net.returnvoid.graphics.shape

## Class LineSegments

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

- All Implemented Interfaces:
    RShape

      public class LineSegments
      extends java.lang.Object
      implements RShape

  A class for building and transforming line segements. LineSegments is a continuous sequence of lines defined by an input set of coordinates.
  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
    `LineSegments(processing.core.PApplet parent, java.util.ArrayList<processing.core.PVector> coordinates)` Builds a new LineSegments shape with the given parameters.
    `LineSegments(processing.core.PApplet parent, processing.core.PVector[] coordinates)` Builds a new LineSegments shape with the given parameters.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeMinMax()` Forces to calculate the bounds of this shape and store them.
    `LineSegments` | `copy()` Builds and returns a true copy of this shape.
    `LineSegments` | `draw()` Draws the shape-
    `processing.core.PVector` | `get(int i)` Returns the coordinate with index i.
    `float` | `getArcLength()` Returns the arc length (sum of line lengths) of this shape.
    `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()` Converts this shape to a curve.
    `processing.core.PVector` | `getEnd()` Returns the end coordinate for this shape.
    `float` | `getLength()` Returns the length (distance from start to end) of this shape.
    `Line` | `getLine()` Converts this shape to a line which shares the same start and end as this shape.
    `Line` | `getLine(int i)` Returns the line with the given index.
    `Line[]` | `getLines()` Converts this shape to a lines (each segment will be a single line).
    `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.
    `int` | `lineSize()` Returns the number of lines for this LineSegments shape.
    `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.
    `LineSegments` | `rotate(float angle)` Turns the shape through the given angle.
    `LineSegments` | `rotate(processing.core.PVector rotationCenter, float angle)` Turns the shape through the given angle.
    `LineSegments` | `scale(float scale)` Scale the shape by the given scaling factor.
    `LineSegments` | `scale(processing.core.PVector scaleCenter, float scale)` Scale the shape by the given scaling factor.
    `LineSegments` | `scale(processing.core.PVector scaleCenter, float scaleX, float scaleY)` Scales the shape by the given scaling factors.
    `LineSegments` | `set(int i, float x, float y)` Updates the position of the control point with the given index.
    `LineSegments` | `set(int i, processing.core.PVector p)` Updates the position of the control point with the given index.
    `LineSegments` | `setLength(float length)` Sets the length of this shape.
    `LineSegments` | `setLength(processing.core.PVector center, float length)` Sets the length of this shape.
    `LineSegments` | `setLocation(float x, float y)` Translates the shape to the given location.
    `LineSegments` | `setRotation(float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `LineSegments` | `setRotation(processing.core.PVector rotationCenter, float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `LineSegments` | `setX(float x)` Translates the shape to the given x-location.
    `LineSegments` | `setY(float y)` Translates the shape to the given y-location.
    `int` | `size()` Returns the number of coordinates for this shape.
    `Curve` | `toCurve()` Converts this shape to a curve.
    `Line` | `toLine()` Converts this shape to a line which shares the same start and end as this shape.
    `Line[]` | `toLines()` Converts this shape to a lines (each segment will be a single line).
    `LineSegments` | `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

    - #### LineSegments

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

      Builds a new LineSegments shape with the given parameters.
      Parameters:
        `parent` - The PApplet object.
        `coordinates` - The coordinates of this shapes. The first line will have its start at coordinates[0] and its end at coordinates[1]. The second line will have its start at coordinates[1] and its end at coordinates[2] and so on. The number of coordinates should be at least 2.

    - #### LineSegments

          public LineSegments(processing.core.PApplet parent,
                              java.util.ArrayList<processing.core.PVector> coordinates)

      Builds a new LineSegments shape with the given parameters.
      Parameters:
        `parent` - The PApplet object.
        `coordinates` - The coordinates of this shapes. The first line will have its start at coordinates.get(0) and its end at coordinates.get(1). The second line will have its start at coordinates.get(1) and its end at coordinates.get(2) and so on. The number of coordinates should be at least 2.

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

    - #### lineSize

          public int lineSize()

      Returns the number of lines for this LineSegments shape.
      Returns:
        The number of lines.

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

    - #### getLine

          public Line getLine(int i)

      Returns the line with the given index. Make sure the given index is within bounds. Example:

           for (int i = 0; i < myLineSegmentsShape.lineSize(); i++) {
                  myLineSegmentsShape.getLine(i).draw();
           }

      Parameters:
        `i` - The index of the line [0, lineSize()).
      Returns:
        The line object.

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

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

    - #### 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 shape.
      Returns:
        The length of 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.

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

    - #### getArcLength

          public float getArcLength()

      Returns the arc length (sum of line lengths) of this shape.
      Returns:
        The length of the line.

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

    - #### copy

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

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

    - #### setRotation

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

    - #### setLength

          public LineSegments setLength(float length)

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

    - #### setLength

          public LineSegments setLength(processing.core.PVector center,
                                        float length)

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

    - #### set

          public LineSegments set(int i,
                                  processing.core.PVector p)

      Updates the position of the control point with the given index.
      Parameters:
        `i` - The index of the control point which will be updated [0, size()).
        `p` - The new position of the control point.
      Returns:
        The current shape,

    - #### set

          public LineSegments set(int i,
                                  float x,
                                  float y)

      Updates the position of the control point with the given index.
      Parameters:
        `i` - The index of the control point which will be updated [0, size()).
        `x` - The new x-position of the control point.
        `y` - The new y-position of the control point.
      Returns:
        The current shape,

    - #### setX

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

    - #### translate

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

    - #### computeMinMax

          public void computeMinMax()

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

    - #### removeIntersectingLines

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

      Removes all lines from the given set of lines that intersect with this shape.
      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.
      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).

    - #### draw

          public LineSegments draw()

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

    - #### toCurve

          public Curve toCurve()

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

    - #### getCurve

          public Curve getCurve()

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

    - #### toLine

          public Line toLine()

      Converts this shape to a line which shares the same start and end as this shape. Does a real copy of the coordinates of this shape.
      Returns:
        The Line shape.

    - #### getLine

          public Line getLine()

      Converts this shape to a line which shares the same start and end as this shape. Does a shallow copy of the coordinates of this shape.
      Returns:
        The Line shape.

    - #### toLines

          public Line[] toLines()

      Converts this shape to a lines (each segment will be a single line). Does a real copy of the coordinates of this shape.
      Returns:
        The lines.

    - #### getLines

          public Line[] getLines()

      Converts this shape to a lines (each segment will be a single line). Does a shallow copy of the coordinates of this shape.
      Returns:
        The lines.