All Implemented Interfaces:
Embedding<Vector2D,Vector1D>, HyperplaneConvexSubset<Vector2D>, HyperplaneSubset<Vector2D>, Splittable<Vector2D,HyperplaneSubset<Vector2D>>, RegionEmbedding<Vector2D,Vector1D>, Sized

public final class Segment extends LineConvexSubset
Class representing a line segment in 2D Euclidean space. A line segment is a portion of a line with finite start and end points.

Instances of this class are guaranteed to be immutable.

See Also:
  • Field Details

    • startPoint

      private final Vector2D startPoint
      Start point for the segment.
    • endPoint

      private final Vector2D endPoint
      End point for the segment.
  • Constructor Details

    • Segment

      Segment(Line line, Vector2D startPoint, Vector2D endPoint)
      Construct a new instance from a line and two points on the line. Callers are responsible for ensuring that the given points lie on the line and are in order of increasing abscissa. No validation is performed.
      Parameters:
      line - line for the segment
      startPoint - segment start point
      endPoint - segment end point
  • Method Details

    • isFull

      public boolean isFull()
      Return true if this instance contains all points in the hyperplane.

      This method always returns false.

      Returns:
      true if this instance contains all points in the hyperplane
    • isInfinite

      public boolean isInfinite()
      Return true if the size of the instance is infinite.

      This method always returns false.

      Returns:
      true if the size of the instance is infinite
    • isFinite

      public boolean isFinite()
      Return true if the size of the instance is finite.

      This method always returns true.

      Returns:
      true if the size of the instance is finite
    • getSize

      public double getSize()
      Get the size of the instance.
      Returns:
      the size of the instance
    • getCentroid

      public Vector2D getCentroid()
      Get the centroid, or geometric center, of the hyperplane subset or null if no centroid exists or one exists but is not unique. A centroid will not exist for empty or infinite subsets.

      The centroid of a geometric object is defined as the mean position of all points in the object, including interior points, vertices, and other points lying on the boundary. If a physical object has a uniform density, then its center of mass is the same as its geometric centroid.

      Returns:
      the centroid of the hyperplane subset or null if no unique centroid exists
      See Also:
    • getStartPoint

      public Vector2D getStartPoint()
      Get the start point for the subset.
      Specified by:
      getStartPoint in class LineConvexSubset
      Returns:
      the start point for the subset, or null if no start point exists
    • getSubspaceStart

      public double getSubspaceStart()
      Get the 1D start location of the subset or Double.NEGATIVE_INFINITY if no start location exists.
      Specified by:
      getSubspaceStart in class LineConvexSubset
      Returns:
      the 1D start location of the subset or Double.NEGATIVE_INFINITY if no start location exists.
    • getEndPoint

      public Vector2D getEndPoint()
      Get the end point for the subset.
      Specified by:
      getEndPoint in class LineConvexSubset
      Returns:
      the end point for the subset, or null if no end point exists.
    • getSubspaceEnd

      public double getSubspaceEnd()
      Get the 1D end location of the subset or Double.POSITIVE_INFINITY if no end location exists.
      Specified by:
      getSubspaceEnd in class LineConvexSubset
      Returns:
      the 1D end location of the subset or Double.POSITIVE_INFINITY if no end location exists
    • getBounds

      public Bounds2D getBounds()
      Get a Bounds2D object defining an axis-aligned bounding box containing all vertices for this subset. Null is returned if the subset is infinite or does not contain any vertices.
      Specified by:
      getBounds in class LineSubset
      Returns:
      the bounding box for this instance or null if no valid bounds could be determined
    • transform

      public Segment transform(Transform<Vector2D> transform)
      Return a new hyperplane subset resulting from the application of the given transform. The current instance is not modified.

      Hyperplane convex subsets subjected to affine transformations remain convex.

      Specified by:
      transform in interface HyperplaneConvexSubset<Vector2D>
      Specified by:
      transform in interface HyperplaneSubset<Vector2D>
      Specified by:
      transform in class LineConvexSubset
      Parameters:
      transform - the transform instance to apply
      Returns:
      new transformed hyperplane subset
    • reverse

      public Segment reverse()
      Reverse the orientation of the hyperplane for this instance, returning the result as a new instance. The returned subset contains the same points but has a reversed orientation.
      Specified by:
      reverse in interface HyperplaneConvexSubset<Vector2D>
      Specified by:
      reverse in class LineConvexSubset
      Returns:
      a hyperplane convex subset representing the same region but with the opposite orientation.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • classifyAbscissa

      RegionLocation classifyAbscissa(double abscissa)
      Classify the given line abscissa value with respect to the subspace region.
      Specified by:
      classifyAbscissa in class LineSubset
      Parameters:
      abscissa - the abscissa value to classify
      Returns:
      the region location of the line abscissa value
    • closestAbscissa

      double closestAbscissa(double abscissa)
      Get the closest value in the subspace region to the given abscissa.
      Specified by:
      closestAbscissa in class LineConvexSubset
      Parameters:
      abscissa - input abscissa
      Returns:
      the closest value in the subspace region to the given abscissa
    • splitOnIntersection

      Split<LineConvexSubset> splitOnIntersection(Line splitter, Vector2D intersection)
      Split this instance using the given splitter line and intersection point.
      Specified by:
      splitOnIntersection in class LineConvexSubset
      Parameters:
      splitter - splitter line
      intersection - intersection point between the splitter line and the line for this instance
      Returns:
      the result of splitting this instance with the given splitter line and intersection point