net.returnvoid.graphics.shape

## Class Curve

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

- All Implemented Interfaces:
    RShape

      public class Curve
      extends java.lang.Object
      implements RShape

  A class for building and transforming curves (Catmull-Rom Curves). This class uses Processing's implementation for curves and uses always Processing's default values for curveTightness=0 and curveDetail=20.
  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
    `Curve(processing.core.PApplet parent)` Builds an empty shape.
    `Curve(processing.core.PApplet parent, processing.core.PVector[] coordinates)` Builds an curve that follows the given coordinates.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `float` | `arcLengthToTPlusI(float arclength)` Maps a given arc length factor [0, getArcLength()] to a tplusi. tplusi is a parameter that describes the position on the curve and the curve segment. i is the index of the coordinate, t is the parameter that describes how near the returned normal is to that coordinate.
    `void` | `computeMinMax()` Forces to calculate the bounds of this shape and store them.
    `Curve` | `copy()` Builds and returns a true copy of this shape.
    `processing.core.PVector` | `curvePoint(float tplusi)` Calculates a point on the curve.
    `float` | `curveTangent(float tplusi)` Calculates the tangent in a point of the curve.
    `Curve` | `draw()` Draws the shape-
    `processing.core.PVector` | `get(int i)` Returns the coordinate with index i.
    `java.lang.Float` | `getArcLength()` Returns the true length of this curve.
    `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.
    `processing.core.PVector` | `getEnd()` Returns the end coordinate for this shape.
    `float` | `getLength()` Returns the length (distance from start to end) of this curve.
    `LineSegments` | `getLineSegments()` Converts this shape to a LineSegments.
    `float[]` | `getNormal(float tplusi)` Returns the normal information for a given location on the 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.
    `boolean` | `hasIntersection(Line curveSeg, Line other)` Tests if a curve segment has a intersection with the given line.
    `boolean` | `hasIntersection(Line curveSeg, Line other, boolean ignoreStartEnd)` Tests if a curve segment has a intersection with the given line.
    `processing.core.PVector` | `intersection(Line curveSeg, Line other)` Returns the location of an intersection a curve segment with a line if they have an intersection.
    `processing.core.PVector` | `intersection(Line curveSeg, Line other, boolean ignoreStartEnd)` Returns the location of an intersection a curve segment with a line if they have an intersection.
    `void` | `removeIntersectingLines(java.util.ArrayList<Line> toRemove)` Removes all lines from the given set of lines that intersect with this shape.
    `void` | `removeIntersectingLines(java.util.ArrayList<Line> toRemove, boolean ignoreStartEnd)` Removes all lines from the given set of lines that intersect with this shape.
    `Curve` | `rotate(float angle)` Turns the shape through the given angle.
    `Curve` | `rotate(processing.core.PVector rotationCenter, float angle)` Turns the shape through the given angle.
    `Curve` | `scale(float scale)` Scale the shape by the given scaling factor.
    `Curve` | `scale(processing.core.PVector scaleCenter, float scale)` Scale the shape by the given scaling factor.
    `Curve` | `scale(processing.core.PVector scaleCenter, float scaleX, float scaleY)` Scales the shape by the given scaling factors.
    `Curve` | `setControlPoint(int which, processing.core.PVector p)` Sets one of the control points, which is not seen, but used to describe the start or end of the curve.
    `Curve` | `setLength(float newLength)` Sets the length (not arclength) of this curve.
    `Curve` | `setLength(processing.core.PVector center, float newLength)` Sets the length (not arclength) of this curve.
    `Curve` | `setLocation(float x, float y)` Translates the shape to the given location.
    `Curve` | `setRotation(float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `Curve` | `setRotation(processing.core.PVector rotationCenter, float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `Curve` | `setX(float x)` Translates the shape to the given x-location.
    `Curve` | `setY(float y)` Translates the shape to the given y-location.
    `int` | `size()` Returns the number of coordinates for this shape.
    `LineSegments` | `toLineSegments()` Converts this shape to a LineSegments.
    `LineSegments` | `toLineSegments(float detailScale)` Converts this shape to a LineSegments and optimizes the coordinates.
    `LineSegments` | `toLineSegments(int details)` Converts this shape to a LineSegments and optimizes the coordinates.
    `Curve` | `toSmoothedCurve()` Smoothens the curve: All coordinates of the returned curve will have a equal distance to each other.
    `Curve` | `toSmoothedCurve(float detailScale)` Smoothens the curve: All coordinates of the returned curve will have a equal distance to each other.
    `Curve` | `toSmoothedCurve(int details)` Smoothens the curve: All coordinates of the returned curve will have a equal distance to each other.
    `Curve` | `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

    - #### Curve

          public Curve(processing.core.PApplet parent)

      Builds an empty shape. The coordinates have to be set manually.
      Parameters:
        `parent` - The PApplet object.

    - #### Curve

          public Curve(processing.core.PApplet parent,
                       processing.core.PVector[] coordinates)

      Builds an curve that follows the given coordinates.
      Parameters:
        `parent` - The PApplet object.
        `coordinates` - The coordinates of this curve.

  - ### Method Detail

    - #### 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.

    - #### 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.

    - #### getLength

          public float getLength()

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

    - #### 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.

    - #### 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 Curve 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.

    - #### getArcLength

          public java.lang.Float getArcLength()

      Returns the true length of this curve.
      Returns:
        The length of the curve.

    - #### setControlPoint

          public Curve setControlPoint(int which,
                                       processing.core.PVector p)

      Sets one of the control points, which is not seen, but used to describe the start or end of the curve.
      Parameters:
        `which` - -1 for first control point (Control point which is needed to draw a curve between coordinates[0] and coordinates[1]) or 1 for last control point (Control point which is needed to draw a curve between coordinates[last-1] and coordinates[last]).
        `p` - The control point.
      Returns:
        The current curve.

    - #### setRotation

          public Curve 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 Curve 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 Curve 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 Curve 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 Curve 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.

    - #### setLength

          public Curve setLength(float newLength)

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

    - #### setLength

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

      Sets the length (not arclength) of this curve. The curve 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.

    - #### intersection

          public processing.core.PVector intersection(Line curveSeg,
                                                      Line other)

      Returns the location of an intersection a curve segment with a line if they have an intersection. Returns null otherwise. Uses just a cheap approximation (line segment instead of curve segment).
      Parameters:
        `curveSeg` - A line that represents a curve segment (line between two points of the curve).
        `other` - One line.
      Returns:
        The location of intersection or null.

    - #### intersection

          public processing.core.PVector intersection(Line curveSeg,
                                                      Line other,
                                                      boolean ignoreStartEnd)

      Returns the location of an intersection a curve segment with a line if they have an intersection. Returns null otherwise. Uses just a cheap approximation (line segment instead of curve segment).
      Parameters:
        `curveSeg` - A line that represents a curve segment (line between two points of the curve).
        `other` - One line.
        `ignoreStartEnd` - If true, intersections that happen directly at the start or the end of the given line will be ignored (i.e. if the intersection happens at start / end then still null will be returned). Otherwise all found intersections will be returned.
      Returns:
        The location of intersection or null.

    - #### hasIntersection

          public boolean hasIntersection(Line curveSeg,
                                         Line other)

      Tests if a curve segment has a intersection with the given line. Uses just a cheap approximation (line segment instead of curve segment).
      Parameters:
        `curveSeg` - A line that represents a curve segment (line between two points of the curve).
        `other` - One line.
      Returns:
        True, when the two lines intersect.

    - #### hasIntersection

          public boolean hasIntersection(Line curveSeg,
                                         Line other,
                                         boolean ignoreStartEnd)

      Tests if a curve segment has a intersection with the given line. Uses just a cheap approximation (line segment instead of curve segment).
      Parameters:
        `curveSeg` - A line that represents a curve segment (line between two points of the curve).
        `other` - One line.
        `ignoreStartEnd` - If true, intersections that happen directly at the start or the end of the given line will be ignored (i.e. if the intersection happens at start / end then still null will be returned). Otherwise all found intersections will be returned.
      Returns:
        True, when the two lines intersect.

    - #### removeIntersectingLines

          public void removeIntersectingLines(java.util.ArrayList<Line> toRemove)

      Removes all lines from the given set of lines that intersect with this shape. Uses just a cheap approximation (line segment instead of curve segment).
      Parameters:
        `toRemove` - A set of lines.

    - #### removeIntersectingLines

          public void removeIntersectingLines(java.util.ArrayList<Line> toRemove,
                                              boolean ignoreStartEnd)

      Removes all lines from the given set of lines that intersect with this shape. Uses just a cheap approximation (line segment instead of curve segment).
      Parameters:
        `toRemove` - A set of lines.
        `ignoreStartEnd` - If true, intersections that happen directly at the start or the end of any line will be ignored (i.e. if the intersection happens at start / end then the line will not be removed).

    - #### getNormal

          public float[] getNormal(float tplusi)

      Returns the normal information for a given location on the curve.
      Parameters:
        `tplusi` - A parameter that describes the position on the 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
      Returns:
        The information for the normal in form of: [normalX, normalY, normalAngle].

    - #### curveTangent

          public float curveTangent(float tplusi)

      Calculates the tangent in a point of the curve.
      Parameters:
        `tplusi` - A parameter that describes the position on the curve and the curve segment. 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.
      Returns:
        The angle of the tangent in the position.

    - #### curvePoint

          public processing.core.PVector curvePoint(float tplusi)

      Calculates a point on the curve.
      Parameters:
        `tplusi` - A parameter that describes the position on the curve and the curve segment. 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
      Returns:
        The point on the curve.

    - #### arcLengthToTPlusI

          public float arcLengthToTPlusI(float arclength)

      Maps a given arc length factor [0, getArcLength()] to a tplusi. tplusi is a parameter that describes the position on the curve and the curve segment. 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.
      Parameters:
        `arclength` - The arclength [0, getArcLength()].
      Returns:
        The tplusi factor.

    - #### computeMinMax

          public void computeMinMax()

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

    - #### translate

          public Curve 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 Curve 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 Curve 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 Curve 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 Curve 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 Curve 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 Curve draw()

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

    - #### toSmoothedCurve

          public Curve toSmoothedCurve()

      Smoothens the curve: All coordinates of the returned curve will have a equal distance to each other. The returned curve will consists of a equal amount of coordinates as the input curve.
      Returns:
        The new smoothend curve.

    - #### toSmoothedCurve

          public Curve toSmoothedCurve(int details)

      Smoothens the curve: All coordinates of the returned curve will have a equal distance to each other. The returned curve will consists of details coordinates (>= 3).
      Parameters:
        `details` - The number of coordinates for the returned curve.
      Returns:
        The new smoothend curve.

    - #### toSmoothedCurve

          public Curve toSmoothedCurve(float detailScale)

      Smoothens the curve: All coordinates of the returned curve will have a equal distance to each other. The returned curve will consists of less or more coordinates than the input curve depending on the factor detailScale.
      Parameters:
        `detailScale` - A factor that describes the number of coordinates for the returned smoothend curve. For detailScale < 1 the new curve will have less coordinates than the input, for detailScale > 1 the curve will have more coordinates. detailScale should be greater than zero.
      Returns:
        The new smoothend curve.

    - #### getLineSegments

          public LineSegments getLineSegments()

      Converts this shape to a LineSegments. Does a shallow copy of the coordinates of this shape.
      Returns:
        The LineSegments shape.

    - #### toLineSegments

          public LineSegments toLineSegments()

      Converts this shape to a LineSegments. Does a real copy of the coordinates of this shape.
      Returns:
        The LineSegments shape.

    - #### toLineSegments

          public LineSegments toLineSegments(float detailScale)

      Converts this shape to a LineSegments and optimizes the coordinates. All coordinates of the returned LineSegments will have a equal distance to each other. The returned LineSegments will consists of less or more coordinates than the input curve depending on the factor detailScale.
      Parameters:
        `detailScale` - A factor that describes the number of coordinates for the returned LineSegments. For detailScale < 1 the new LineSegments will have less coordinates than the input curve, for detailScale > 1 the LineSegments will have more coordinates. detailScale should be greater than zero.
      Returns:
        The LineSegments shape.

    - #### toLineSegments

          public LineSegments toLineSegments(int details)

      Converts this shape to a LineSegments and optimizes the coordinates. All coordinates of the returned LineSegments will have a equal distance to each other. The returned LineSegments will consists of details coordinates.
      Parameters:
        `details` - The number of coordinates for the returned LineSegments (>= 2).
      Returns:
        The LineSegments shape.