net.returnvoid.graphics.shape

## Class Line

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

- All Implemented Interfaces:
    RShape

      public class Line
      extends java.lang.Object
      implements RShape

  A class for building and transforming lines.
  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
    `Line(processing.core.PApplet parent, float startX, float startY, float endX, float endY)` Builds a new line with the given parameters.
    `Line(processing.core.PApplet parent, processing.core.PVector start, float angle, float length)` Builds a new line with the given parameters.
    `Line(processing.core.PApplet parent, processing.core.PVector start, processing.core.PVector end)` Builds a new line with the given parameters.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeMinMax()` Forces to calculate the bounds of this shape and store them.
    `Line` | `copy()` Builds and returns a true copy of this shape.
    `Line` | `draw()` Draws the shape-
    `processing.core.PVector` | `get(int i)` Returns the coordinate with index i.
    `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 line.
    `processing.core.PVector` | `getNormal()` Returns a normal vector for this line.
    `static processing.core.PVector` | `getNormal(processing.core.PVector p, processing.core.PVector o)` Returns a normal vector for that is described by the given vectors.
    `Line` | `getNormalLine(float lineLength)` Builds a line, that represents the normal of this 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.
    `boolean` | `hasIntersection(Line other)` Tests if two lines have an intersection.
    `boolean` | `hasIntersection(Line other, boolean ignoreStartEnd)` Tests if two lines have an intersection.
    `static boolean` | `hasIntersection(Line base, Line other)` Tests if two lines have an intersection.
    `static boolean` | `hasIntersection(Line base, Line other, boolean ignoreStartEnd)` Tests if two lines have an intersection.
    `processing.core.PVector` | `intersection(Line other)` Returns the location of an intersection of two lines if they have an intersection.
    `processing.core.PVector` | `intersection(Line other, boolean ignoreStartEnd)` Returns the location of an intersection of two lines if they have an intersection.
    `static processing.core.PVector` | `intersection(Line base, Line other)` Returns the location of an intersection of two lines if they have an intersection.
    `static processing.core.PVector` | `intersection(Line base, Line other, boolean ignoreStartEnd)` Returns the location of an intersection of two lines if they have an intersection.
    `static void` | `removeIntersectingLines(java.util.ArrayList<Line> lines)` Removes lines from the given set of lines if they intersect with other lines of the list.
    `static void` | `removeIntersectingLines(java.util.ArrayList<Line> lines, boolean ignoreStartEnd)` Removes lines from the given set of lines if they intersect with other lines of the list.
    `static void` | `removeIntersectingLinesHierarchical(java.util.ArrayList<Line> lines)` Removes lines from the given set of lines if they intersect with other lines of the list.
    `static void` | `removeIntersectingLinesHierarchical(java.util.ArrayList<Line> lines, boolean ignoreStartEnd)` Removes lines from the given set of lines if they intersect with other lines of the list.
    `Line` | `rotate(float angle)` Turns the shape through the given angle.
    `Line` | `rotate(processing.core.PVector rotationCenter, float angle)` Turns the shape through the given angle.
    `Line` | `scale(float scale)` Scale the shape by the given scaling factor.
    `Line` | `scale(processing.core.PVector scaleCenter, float scale)` Scale the shape by the given scaling factor.
    `Line` | `setLength(float length)` Sets the length of this line.
    `Line` | `setLength(processing.core.PVector center, float length)` Sets the length of this line.
    `Line` | `setLocation(float x, float y)` Translates the shape to the given location.
    `Line` | `setRotation(float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `Line` | `setRotation(processing.core.PVector rotationCenter, float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `Line` | `setX(float x)` Translates the shape to the given x-location.
    `Line` | `setY(float y)` Translates the shape to the given y-location.
    `int` | `size()` Returns the number of coordinates for this shape.
    `static Line[]` | `toLines(processing.core.PApplet parent, processing.core.PVector[] points)` Creates lines from the given point set.
    `processing.core.PVector` | `toRotationVector()` Creates a vector that points in the same direction like this line.
    `Line` | `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

    - #### Line

          public Line(processing.core.PApplet parent,
                      processing.core.PVector start,
                      processing.core.PVector end)

      Builds a new line with the given parameters.
      Parameters:
        `parent` - The PApplet object.
        `start` - The start-location of the line.
        `end` - The end-location of the line.

    - #### Line

          public Line(processing.core.PApplet parent,
                      float startX,
                      float startY,
                      float endX,
                      float endY)

      Builds a new line with the given parameters.
      Parameters:
        `parent` - The PApplet object.
        `startX` - The start-x-location of the line.
        `startY` - The start-y-location of the rectangle (top-left corner).
        `endX` - The end-x-location of the line.
        `endY` - The end-y-location of the line.

    - #### Line

          public Line(processing.core.PApplet parent,
                      processing.core.PVector start,
                      float angle,
                      float length)

      Builds a new line with the given parameters.
      Parameters:
        `parent` - The PApplet object.
        `start` - The start-location of the line.
        `angle` - The rotation of the line (in radians).
        `length` - The length of the line.

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

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

    - #### getLength

          public float getLength()

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

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

    - #### getNormal

          public processing.core.PVector getNormal()

      Returns a normal vector for this line.
      Returns:
        The normal vector.

    - #### getNormalLine

          public Line getNormalLine(float lineLength)

      Builds a line, that represents the normal of this line. The normal line will have its start in the middle of the current line object.
      Parameters:
        `lineLength` - The length of the normal line.
      Returns:
        The normal line.

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

    - #### setRotation

          public Line 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 Line 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 Line setLength(float length)

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

    - #### setLength

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

      Sets the length of this line. The line 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.

    - #### setX

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

    - #### intersection

          public processing.core.PVector intersection(Line other)

      Returns the location of an intersection of two lines if they have an intersection. Returns null otherwise.
      Parameters:
        `other` - One line.
      Returns:
        The location of intersection or null.

    - #### intersection

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

      Returns the location of an intersection of two lines if they have an intersection. Returns null otherwise.
      Parameters:
        `other` - One line.
        `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 still null will be returned). Otherwise all found intersections will be returned.
      Returns:
        The location of intersection or null.

    - #### hasIntersection

          public boolean hasIntersection(Line other)

      Tests if two lines have an intersection.
      Parameters:
        `other` - One line.
      Returns:
        True, when the two lines intersect.

    - #### hasIntersection

          public boolean hasIntersection(Line other,
                                         boolean ignoreStartEnd)

      Tests if two lines have an intersection.
      Parameters:
        `other` - One line.
        `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 still false will be returned).
      Returns:
        True, when the two lines intersect.

    - #### translate

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

    - #### computeMinMax

          public void computeMinMax()

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

    - #### getNormal

          public static processing.core.PVector getNormal(processing.core.PVector p,
                                                          processing.core.PVector o)

      Returns a normal vector for that is described by the given vectors.
      Parameters:
        `p` - One location (p != o).
        `o` - Another location (p != o).
      Returns:
        The normal vector.

    - #### toLines

          public static Line[] toLines(processing.core.PApplet parent,
                                       processing.core.PVector[] points)

      Creates lines from the given point set. The first line will have its start at points[0] and its end at points[1]. The second line will have its start at points[1] and its end at points[2] and so on.
      Parameters:
        `parent` - The PApplet object.
        `points` - Some coordinates (points.length >= 2).
      Returns:
        A set of lines.

    - #### intersection

          public static processing.core.PVector intersection(Line base,
                                                             Line other)

      Returns the location of an intersection of two lines if they have an intersection. Returns null otherwise.
      Parameters:
        `base` - One line.
        `other` - Another line.
      Returns:
        The location of intersection or null.

    - #### intersection

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

      Returns the location of an intersection of two lines if they have an intersection. Returns null otherwise.
      Parameters:
        `base` - One line.
        `other` - Another line.
        `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 still null will be returned). Otherwise all found intersections will be returned.
      Returns:
        The location of intersection or null.

    - #### hasIntersection

          public static boolean hasIntersection(Line base,
                                                Line other)

      Tests if two lines have an intersection.
      Parameters:
        `base` - One line.
        `other` - Another line.
      Returns:
        True, when the two lines intersect.

    - #### hasIntersection

          public static boolean hasIntersection(Line base,
                                                Line other,
                                                boolean ignoreStartEnd)

      Tests if two lines have an intersection.
      Parameters:
        `base` - One line.
        `other` - Another line.
        `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 still false will be returned).
      Returns:
        True, when the two lines intersect.

    - #### removeIntersectingLines

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

      Removes lines from the given set of lines if they intersect with other lines of the list. For each intersection the line which was added later to the list of lines (i.e. has a higher index) will be removed.
      Parameters:
        `lines` - A set of lines.

    - #### removeIntersectingLines

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

      Removes lines from the given set of lines if they intersect with other lines of the list. For each intersection the line which was added later to the list of lines (i.e. has a higher index) will be removed.
      Parameters:
        `lines` - 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 lines will not be removed).

    - #### removeIntersectingLinesHierarchical

          public static void removeIntersectingLinesHierarchical(java.util.ArrayList<Line> lines)

      Removes lines from the given set of lines if they intersect with other lines of the list. The removal of the lines is done hierarchical: In each iteration the line with the most intersections is found and that line is removed. This means in each iteration just one intersection is removed. This makes the algorithm quite slow (but precise). Use removeIntersectingLines() for faster (but less precise) removal.
      Parameters:
        `lines` - A set of lines.

    - #### removeIntersectingLinesHierarchical

          public static void removeIntersectingLinesHierarchical(java.util.ArrayList<Line> lines,
                                                                 boolean ignoreStartEnd)

      Removes lines from the given set of lines if they intersect with other lines of the list. The removal of the lines is done hierarchical: In each iteration the line with the most intersections is found and that line is removed. This means in each iteration just one intersection is removed. This makes the algorithm quite slow (but precise). Use removeIntersectingLines() for faster (but less precise) removal.
      Parameters:
        `lines` - 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 lines will not be removed).

    - #### draw

          public Line draw()

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

    - #### toRotationVector

          public processing.core.PVector toRotationVector()

      Creates a vector that points in the same direction like this line.
      Returns:
        The vector with the same angle like this line.