net.returnvoid.graphics.shape

## Class CurvedLens

- java.lang.Object
- - net.returnvoid.graphics.shape.CurvedLens

- All Implemented Interfaces:
    RShape

      public class CurvedLens
      extends java.lang.Object
      implements RShape

  A class for building and transforming lenses that a deformed by a curve (Catmull-Rom Curves).
  Author:
    Diana Lange

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected processing.core.PApplet` | `parent` The PApplet object for drawing thinks.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CurvedLens(processing.core.PApplet parent, processing.core.PVector[] coordinates, float height)` Builds a new CurvedLens shape with the given parameters.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `centerSize()` Returns the number of coordinates that defines this shape (points on center curve).
    `float` | `computeHeight(float tplusi)` Computes the thickness of the lens on a certain point in the shape.
    `void` | `computeMinMax()` Forces to calculate the bounds of this shape and store them.
    `CurvedLens` | `copy()` Builds and returns a true copy of this shape.
    `CurvedLens` | `draw()` Draws the shape-
    `CurvedLens` | `drawCenter()` Draws the center curve.
    `CurvedLens` | `drawRaw()` Draws outline with lines not curves.
    `processing.core.PVector` | `get(int i)` Returns the coordinate with index i.
    `float` | `getArea()` Returns the area (approx).
    `Rect` | `getBoundingBox()` Returns the bounding box of this shape (will mark the bounds of the shape).
    `processing.core.PVector` | `getCenter()` Returns the center coordinate of this shape.
    `processing.core.PVector[]` | `getCoordinates()` Returns all coordinates that defines this shape.
    `Curve` | `getCurve()` Returns the center curve.
    `int` | `getDetails()` Returns the number of coordinates for the center curve.
    `float` | `getDetailScale()` Returns the detailsScale factor.
    `processing.core.PVector` | `getEnd()` Returns the end coordinate for this shape.
    `float` | `getHeight()` Returns the thickness of this lens.
    `float` | `getLength()` Returns the length (distance from start to end) of this shape.
    `LineSegments` | `getLineSegments()` Returns the center LineSegments (raw version of the center curve).
    `java.lang.Float` | `getRotation()` Returns the angle of shape.
    `processing.core.PVector` | `getStart()` Returns the start coordinate for this shape.
    `java.lang.Float` | `getX()` Returns the x-position of the start coordinate for this shape.
    `java.lang.Float` | `getY()` Returns the y-position of the start coordinate for this shape.
    `CurvedLens` | `rotate(float angle)` Turns the shape through the given angle.
    `CurvedLens` | `rotate(processing.core.PVector rotationCenter, float angle)` Turns the shape through the given angle.
    `CurvedLens` | `scale(float scale)` Scale the shape by the given scaling factor.
    `CurvedLens` | `scale(processing.core.PVector scaleCenter, float scale)` Scale the shape by the given scaling factor.
    `CurvedLens` | `scale(processing.core.PVector scaleCenter, float scaleX, float scaleY)` Scales the shape by the given scaling factors.
    `CurvedLens` | `setDetails(int details)` Sets the number of coordinates for the center curve.
    `CurvedLens` | `setDetailScale(float detailScale)` Sets the detailsScale factor.
    `CurvedLens` | `setHeight(float height)` Sets the thickness of the lens.
    `CurvedLens` | `setLength(float newLength)` Sets the length of this shape.
    `CurvedLens` | `setLength(processing.core.PVector center, float newLength)` Sets the length of this shape.
    `CurvedLens` | `setLocation(float x, float y)` Translates the shape to the given location.
    `CurvedLens` | `setRotation(float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `CurvedLens` | `setRotation(processing.core.PVector rotationCenter, float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `CurvedLens` | `setX(float x)` Translates the shape to the given x-location.
    `CurvedLens` | `setY(float y)` Translates the shape to the given y-location.
    `int` | `size()` Returns the number of coordinates for this shape.
    `Curve` | `toCurve()` Returns the center curve.
    `LineSegments` | `toLineSegments()` Returns the center LineSegments (raw version of the center curve).
    `Curve` | `toSmoothedCurve()` Returns the a smoothend version of the center curve (smoothness depends on detailScale).
    `CurvedLens` | `translate(float x, float y)` Translates the coordinates by the given parameters x, y ( "moves the shape by x, y").

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### parent

          protected processing.core.PApplet parent

      The PApplet object for drawing thinks.

  - ### Constructor Detail

    - #### CurvedLens

          public CurvedLens(processing.core.PApplet parent,
                            processing.core.PVector[] coordinates,
                            float height)

      Builds a new CurvedLens shape with the given parameters.
      Parameters:
        `parent` - The PApplet object.
        `coordinates` - The coordinates of that describe the center curve for this lens.
        `height` - The thickness of the lens.

  - ### Method Detail

    - #### getDetailScale

          public float getDetailScale()

      Returns the detailsScale factor. The center curve will be a smoothend version of the LineSegments given by getCoordinates(). The center curve defines the shape of the lens. The detailScale factor defines how many coordinates the smoothend curve will have. For detailScale < 1 : the curve will have less coordinates than centerCooridates; for detailScale > 1 : the curve will have more coordinates than centerCooridates.
      Returns:
        The scale of details.

    - #### getDetails

          public int getDetails()

      Returns the number of coordinates for the center curve. The center curve will be a smoothend version of the LineSegments given by getCoordinates(). The center curve defines the shape of the lens. The details are the number of coordinates the smoothend curve will have.
      Returns:
        The number of coordinates for the curve.

    - #### size

          public int size()

      Description copied from interface: `RShape`
      Returns the number of coordinates for this shape. Can be used to iterate over all coordinates for this shape (e.g. for drawing the shape). Example:

           for (int i = 0; i < myShape.size(); i++) {
                  PVector p = myShape.get(i);
           }

      Specified by:
        `size` in interface `RShape`
      Returns:
        The number of coordinates for this shape.

    - #### centerSize

          public int centerSize()

      Returns the number of coordinates that defines this shape (points on center curve).
      Returns:
        The number of coordinates of the center curve.

    - #### get

          public processing.core.PVector get(int i)

      Description copied from interface: `RShape`
      Returns the coordinate with index i. Please make sure i is within bounds, e.g. using the size() method. Example:

           for (int i = 0; i < myShape.size(); i++) {
                  PVector p = myShape.get(i);
           }

      Specified by:
        `get` in interface `RShape`
      Parameters:
        `i` - The index of a coordinates of this shape.
      Returns:
        The coordinate of the shape with the given index.

    - #### getStart

          public processing.core.PVector getStart()

      Description copied from interface: `RShape`
      Returns the start coordinate for this shape. The start is defined differently for each shape. For a Line it is one of the ends, for a Rect it is the top left corner (when no rotation is applied) and so on.
      Specified by:
        `getStart` in interface `RShape`
      Returns:
        The start coordinate for the shape.

    - #### getEnd

          public processing.core.PVector getEnd()

      Returns the end coordinate for this shape.
      Returns:
        The end location.

    - #### getBoundingBox

          public Rect getBoundingBox()

      Description copied from interface: `RShape`
      Returns the bounding box of this shape (will mark the bounds of the shape).
      Specified by:
        `getBoundingBox` in interface `RShape`
      Returns:
        The bounding box.

    - #### getCenter

          public processing.core.PVector getCenter()

      Description copied from interface: `RShape`
      Returns the center coordinate of this shape.
      Specified by:
        `getCenter` in interface `RShape`
      Returns:
        The center coordinate of this shape.

    - #### getX

          public java.lang.Float getX()

      Description copied from interface: `RShape`
      Returns the x-position of the start coordinate for this shape. The start is defined differently for each shape. For a Line it is one of the ends, for a Rect it is the top left corner (when no rotation is applied) and so on.
      Specified by:
        `getX` in interface `RShape`
      Returns:
        The x-position start coordinate for the shape.

    - #### getY

          public java.lang.Float getY()

      Description copied from interface: `RShape`
      Returns the y-position of the start coordinate for this shape. The start is defined differently for each shape. For a Line it is one of the ends, for a Rect it is the top left corner (when no rotation is applied) and so on.
      Specified by:
        `getY` in interface `RShape`
      Returns:
        The y-position start coordinate for the shape.

    - #### getHeight

          public float getHeight()

      Returns the thickness of this lens.
      Returns:
        The thickness.

    - #### getLength

          public float getLength()

      Returns the length (distance from start to end) of this shape.
      Returns:
        The length of the shape.

    - #### getArea

          public float getArea()

      Returns the area (approx).
      Returns:
        The area.

    - #### getCoordinates

          public processing.core.PVector[] getCoordinates()

      Description copied from interface: `RShape`
      Returns all coordinates that defines this shape.
      Specified by:
        `getCoordinates` in interface `RShape`
      Returns:
        The coordinates of this shape.

    - #### getRotation

          public java.lang.Float getRotation()

      Description copied from interface: `RShape`
      Returns the angle of shape.
      Specified by:
        `getRotation` in interface `RShape`
      Returns:
        The angle of the shape.

    - #### copy

          public CurvedLens copy()

      Description copied from interface: `RShape`
      Builds and returns a true copy of this shape.
      Specified by:
        `copy` in interface `RShape`
      Returns:
        The copy of this shape.

    - #### setLength

          public CurvedLens setLength(float newLength)

      Sets the length of this shape. The rectangle will be scaled around getStart().
      Parameters:
        `newLength` - The new length of the line (> 0).
      Returns:
        The current shape.

    - #### setLength

          public CurvedLens setLength(processing.core.PVector center,
                                      float newLength)

      Sets the length of this shape. The lens will be scaled around center.
      Parameters:
        `center` - The control point for the scaling.
        `newLength` - The new length of the line (> 0).
      Returns:
        The current shape.

    - #### setHeight

          public CurvedLens setHeight(float height)

      Sets the thickness of the lens. The outline will be re-build.
      Parameters:
        `height` - The thickness of the lens.
      Returns:
        The current shape.

    - #### setRotation

          public CurvedLens setRotation(float angle)

      Description copied from interface: `RShape`
      Rotates the shape to the given angle (past rotations will be overridden). The rotation center will be the getStart() of this shape.
      Specified by:
        `setRotation` in interface `RShape`
      Parameters:
        `angle` - The target rotation angle.
      Returns:
        The current shape.

    - #### setRotation

          public CurvedLens setRotation(processing.core.PVector rotationCenter,
                                        float angle)

      Description copied from interface: `RShape`
      Rotates the shape to the given angle (past rotations will be overridden). The rotation center will be the given location c.
      Specified by:
        `setRotation` in interface `RShape`
      Parameters:
        `rotationCenter` - The rotation center.
        `angle` - The target rotation angle.
      Returns:
        The current shape.

    - #### setX

          public CurvedLens setX(float x)

      Description copied from interface: `RShape`
      Translates the shape to the given x-location. After the translation getStart().x will be equal to the given x.
      Specified by:
        `setX` in interface `RShape`
      Parameters:
        `x` - The new x-position of this shape.
      Returns:
        The current shape.

    - #### setY

          public CurvedLens setY(float y)

      Description copied from interface: `RShape`
      Translates the shape to the given y-location. After the translation getStart().y will be equal to the given y.
      Specified by:
        `setY` in interface `RShape`
      Parameters:
        `y` - The new y-position of this shape.
      Returns:
        The current shape.

    - #### setLocation

          public CurvedLens setLocation(float x,
                                        float y)

      Description copied from interface: `RShape`
      Translates the shape to the given location. After the translation getStart() will be equal to the given x, y.
      Specified by:
        `setLocation` in interface `RShape`
      Parameters:
        `x` - The new x-position of this shape.
        `y` - The new y-position of this shape.
      Returns:
        The current shape.

    - #### setDetailScale

          public CurvedLens setDetailScale(float detailScale)

      Sets the detailsScale factor. The center curve will be a smoothend version of the LineSegments given by getCoordinates(). The center curve defines the shape of the lens. The detailScale factor defines how many coordinates the smoothend curve will have. For detailScale < 1 : the curve will have less coordinates than centerCooridates; for detailScale > 1 : the curve will have more coordinates than centerCooridates. The outline will be re-build.
      Parameters:
        `detailScale` - The new detailScale (> 0).
      Returns:
        The current shape.

    - #### setDetails

          public CurvedLens setDetails(int details)

      Sets the number of coordinates for the center curve. The center curve will be a smoothend version of the LineSegments given by getCoordinates(). The center curve defines the shape of the lens. The details are the number of coordinates the smoothend curve will have.
      Parameters:
        `details` - The number of coordinates for the curve (>= 2).
      Returns:
        The current shape.

    - #### computeMinMax

          public void computeMinMax()

      Forces to calculate the bounds of this shape and store them. The bounds can be accessed by getBoundingBox().

    - #### computeHeight

          public float computeHeight(float tplusi)

      Computes the thickness of the lens on a certain point in the shape.
      Parameters:
        `tplusi` - A parameter that describes the position in the center curve. i is the index of the coordinate, t is the parameter that describes how near the returned normal is to that coordinate. If t is 0 the normal will be directly at the coordinate, if t is 1 the normal will be directly at the following coordinate. For t=0.5 the normal will be in the middle of the coordinate and the following coordinate. t and i should be summed for this parameter, e.g. for the normal which is in the middle (t=0.5) of coordinate[1] (i=1) and coordinate[2] tplusi should be 1+0.5=0.5. i should be in range of [0, centerSize()).
      Returns:
        The thickness at this point.

    - #### translate

          public CurvedLens translate(float x,
                                      float y)

      Description copied from interface: `RShape`
      Translates the coordinates by the given parameters x, y ( "moves the shape by x, y").
      Specified by:
        `translate` in interface `RShape`
      Parameters:
        `x` - The horizontal translation.
        `y` - The vertical translation.
      Returns:
        The current shape.

    - #### rotate

          public CurvedLens rotate(float angle)

      Description copied from interface: `RShape`
      Turns the shape through the given angle. The rotation center will be the getStart() of this shape.
      Specified by:
        `rotate` in interface `RShape`
      Parameters:
        `angle` - The rotation angle.
      Returns:
        The current shape.

    - #### rotate

          public CurvedLens rotate(processing.core.PVector rotationCenter,
                                   float angle)

      Description copied from interface: `RShape`
      Turns the shape through the given angle. The rotation center will be the given location c.
      Specified by:
        `rotate` in interface `RShape`
      Parameters:
        `rotationCenter` - The rotation center.
        `angle` - The rotation angle.
      Returns:
        The current shape.

    - #### scale

          public CurvedLens scale(float scale)

      Description copied from interface: `RShape`
      Scale the shape by the given scaling factor. For scaling factor s <1 the shape will shrink. For scaling factor s>1 the shape will expand. The scaling center will be the getStart() of this shape.
      Specified by:
        `scale` in interface `RShape`
      Parameters:
        `scale` - The scaling factor (> 0).
      Returns:
        The current shape.

    - #### scale

          public CurvedLens scale(processing.core.PVector scaleCenter,
                                  float scale)

      Description copied from interface: `RShape`
      Scale the shape by the given scaling factor. For scaling factor s <1 the shape will shrink. For scaling factor s>1 the shape will expand. The scaling center will be the given location c.
      Specified by:
        `scale` in interface `RShape`
      Parameters:
        `scaleCenter` - The scaling center.
        `scale` - The scaling factor (> 0).
      Returns:
        The current shape.

    - #### scale

          public CurvedLens scale(processing.core.PVector scaleCenter,
                                  float scaleX,
                                  float scaleY)

      Scales the shape by the given scaling factors. For scaling factor < 1 the shape will shrink. For scaling factors > 1 the shape will expand. The scaling center will be the given location scaleCenter.
      Parameters:
        `scaleCenter` - The scaling center.
        `scaleX` - The horizontal scaling.
        `scaleY` - The vertical scaling.
      Returns:
        The current shape.

    - #### draw

          public CurvedLens draw()

      Description copied from interface: `RShape`
      Draws the shape-
      Specified by:
        `draw` in interface `RShape`
      Returns:
        The current shape.

    - #### drawRaw

          public CurvedLens drawRaw()

      Draws outline with lines not curves.
      Returns:
        The current shape.

    - #### drawCenter

          public CurvedLens drawCenter()

      Draws the center curve.
      Returns:
        The current shape.

    - #### getCurve

          public Curve getCurve()

      Returns the center curve. Does a shallow copy of the coordinates of the center and this shape.
      Returns:
        The curve.

    - #### toCurve

          public Curve toCurve()

      Returns the center curve. Does a real copy of the coordinates of the center curve and this shape.
      Returns:
        The curve.

    - #### getLineSegments

          public LineSegments getLineSegments()

      Returns the center LineSegments (raw version of the center curve). Does a shallow copy of the coordinates of the center and this shape.
      Returns:
        The LineSegments.

    - #### toLineSegments

          public LineSegments toLineSegments()

      Returns the center LineSegments (raw version of the center curve). Does a real copy of the coordinates of the center and this shape.
      Returns:
        The LineSegments.

    - #### toSmoothedCurve

          public Curve toSmoothedCurve()

      Returns the a smoothend version of the center curve (smoothness depends on detailScale).
      Returns:
        The smoothend center curve.