Record Class SegmentedLine

java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.SegmentedLine
All Implemented Interfaces:
Shape

public record SegmentedLine(List<Point2D> points) extends Record implements Shape
Line that consists of multiple segments, where each segment is a straight line but the combination still allows for more complex line shapes. The line is defined by a number of points, where each point except the "head" and the "tail" acts as both the end of the previous segment and the start of the next segment. Alternatively, segments can also be described by Line instances using getSegments().
  • Constructor Details

    • SegmentedLine

      public SegmentedLine(List<Point2D> points)
      Creates an instance of a SegmentedLine record class.
      Parameters:
      points - the value for the points record component
  • Method Details

    • getSegments

      public List<Line> getSegments()
    • getHead

      public Point2D getHead()
    • getTail

      public Point2D getTail()
    • contains

      public boolean contains(Point2D p)
      Description copied from interface: Shape
      Returns whether this shape contains the specified point.
      Specified by:
      contains in interface Shape
    • getBoundingBox

      public Rect getBoundingBox()
      Description copied from interface: Shape
      Returns the smallest possible rectangular bounding box that can fit this shape.
      Specified by:
      getBoundingBox in interface Shape
    • reposition

      public SegmentedLine reposition(Point2D offset)
      Description copied from interface: Shape
      Returns a new Shape instance that is repositioned by the specified X and Y offset.
      Specified by:
      reposition in interface Shape
    • toDirectLine

      public Line toDirectLine()
      Returns a direct line that points from this segmented line's head to its tail.
    • extend

      public SegmentedLine extend(Point2D p)
      Returns a new SegmentedLine that consists of the same segments as this one plus one extra segment between this line's tail and the specified point.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • points

      public List<Point2D> points()
      Returns the value of the points record component.
      Returns:
      the value of the points record component