Class Polyline

Direct Known Subclasses:
Polygon

public class Polyline extends AbstractGeometricPrimitive
Class representing a directed polyline in 2D space. The polyline consists of ordered list of points and ordered list of segments connecting the consecutive pairs of points. A polyline with N points has N-1 segments.

Empty polylines and polylines of 1 point are allowed although most of the methods will not work correctly with such polylines.

Author:
Andrey Malykhanov
  • Field Details

  • Constructor Details

    • Polyline

      public Polyline(List<Point> points)
      Creates a new instance of polyline with points specified in the list.

      Note that this constructor allows to create a potentially invalid polyline with 0 or 1 points. Also, this constructor does not check for presence of consecutive equal points

      Parameters:
      points - specified list of points
    • Polyline

      public Polyline(Point... points)
      Creates a new instance of polyline with specified points

      Note that this constructor allows to create a potentially invalid polyline with 0 or 1 points. Also, this constructor does not check for presence of consecutive equal points

      Parameters:
      points - specified variable argument array of points
  • Method Details

    • getMinRectPoint

      public Point getMinRectPoint()
      Returns the minimum point of this polyline's bounds. In screen coordinates, this will be the top left point

      Returns:
      minimum point of this polyline's bounds
    • isEmpty

      public boolean isEmpty()
      Checks whether this polyline is empty, e.g. has no points.
      Returns:
      true if this polyline is empty, false otherwise.
    • getMaxRectPoint

      public Point getMaxRectPoint()
      Returns the maximum point of this polyline's bounds. In screen coordinates, this will be the bottom right point

      Returns:
      maximum point of this polyline's bounds
    • boundsIntersect

      protected boolean boundsIntersect(Polyline otherPolyline)
    • getSegments

      public List<Segment> getSegments()
      Returns unmodifiable list of segments of this polyline. All segments are directed from begin point of the polyline to its end point. List can be empty if polyline consists of less than 2 points
      Returns:
      unmodifiable list of segments of this polyline
      See Also:
    • getPoints

      public List<Point> getPoints()
      Returns unmodifiable list of points of this polyline. List can be empty if the polyline consists of 0 points (i.e. the polyline itself is empty)
      Returns:
      unmodifiable list of points of this polyline
      See Also:
    • getFirstPoint

      public Point getFirstPoint()
      Returns the first point of this polyline, or null if this polyline is empty
      Returns:
      first point of this polyline
    • getLastPoint

      public Point getLastPoint()
      Returns the last point of this polyline, or null if this polyline is empty
      Returns:
      last point of this polyline
    • getFirstSegment

      public Segment getFirstSegment()
      Returns the first segment of this polyline, or null if this polyline has no segments
      Returns:
      first segment of this polyline
    • getLastSegment

      public Segment getLastSegment()
      Returns the last segment of this polyline, or null if this polyline has no segments
      Returns:
      last segment of this polyline
    • getLength

      public double getLength()
      Returns the length of this polyline. Length can be zero but is always non-negative
      Returns:
      length of this polyline
    • containsPoint

      public boolean containsPoint(Point point, boolean includeEndPoint)
      Checks whether this polyline contains the specified point, i.e. the specified point lies on this polyline. Allows to include or exclude the end point of polyline
      Parameters:
      point - specified point
      includeEndPoint - include or exclude end point of this polyline
      Returns:
      true if this polyline contains the specified point, false otherwise.
    • containsPoint

      public boolean containsPoint(Point point)
      Description copied from class: AbstractGeometricPrimitive
      Checks whether this primitive contains the specified point
      Specified by:
      containsPoint in class AbstractGeometricPrimitive
      Parameters:
      point - the specified point
      Returns:
      true if this primitive contains the specified point, false otherwise
    • getPointByRelativeOffset

      public Point getPointByRelativeOffset(double relativeOffset)
      Returns point on this polyline by its relative offset on this polyline.

      Returns null if the specified relative offset is outside interval of [0, number of points - 1]. All comparisons for calculating the result of this method are make using the default comparator (Compare).

      Parameters:
      relativeOffset - specified relative offset of point.
      Returns:
      point point on this polyline, or null
    • getPointByAbsoluteOffset

      public Point getPointByAbsoluteOffset(double absoluteOffset)
      Returns point on this polyline by its absolute offset on this polyline, i.e. by the distance from polyline's begin point measured along this polyline.

      Returns null if the specified absolute offset is outside interval of [0, length of this polyline].All comparisons for calculating the result of this method are make using the default comparator (Compare).

      Parameters:
      absoluteOffset - specified absolute offset of point
      Returns:
      point point on this polyline, or null
      See Also:
    • getPointAndSegmentIndexByAbsoluteOffset

      public Pair<Point,Integer> getPointAndSegmentIndexByAbsoluteOffset(double absoluteOffset)
      Returns a Pair containing the Point located at the specified absolute offset along the polyline and the index of the segment where that point lies.

      All comparisons for calculating the result of this method are made using the default comparator (Compare).

      Parameters:
      absoluteOffset - the distance from the start of the polyline, in the same units as segment lengths
      Returns:
      a Pair of the point and the segment index, or null if the offset is out of bounds or if there are no segments
    • getPointAndSegmentIndexByAbsoluteOffset

      public Pair<Point,Integer> getPointAndSegmentIndexByAbsoluteOffset(double absoluteOffset, EpsilonComparator comparator)
      Returns a Pair containing the Point located at the specified absolute offset along the polyline and the index of the segment where that point lies.

      Parameters:
      absoluteOffset - the distance from the start of the polyline, in the same units as segment lengths
      comparator - specified comparator to compare length and distances
      Returns:
      a Pair of the point and the segment index, or null if the offset is out of bounds or if there are no segments
    • getSubPolylineByRelativeOffsets

      public Polyline getSubPolylineByRelativeOffsets(double beginPointRelativeOffset, double endPointRelativeOffset)
      Returns subpolyline that is a part of this polyline located between the specified relative offsets.

    • If endPointRelativeOffset > beginPointRelativeOffset, the direction of the resulting polyline is the same as direction of this polyline
    • If beginPointRelativeOffset > endPointRelativeOffset, the direction of the resulting polyline is reversed compared to this polyline
    • If beginPointRelativeOffset = endPointRelativeOffset, the resulting polyline contains only one point and located at the specified relative offset
    • If either of the specified offsets is outside the range of [0, number of points - 1], returns null

      All comparisons above are made using the default comparator (Compare).

    • Parameters:
      beginPointRelativeOffset - specified relative offset of the begin point
      endPointRelativeOffset - specified relative offset of the end point
      Returns:
      polyline that is a subpolyline of this polyline between the specified relative offsets, or null
    • getPointsOfSubPolylineByRelativeOffsets

      public List<Point> getPointsOfSubPolylineByRelativeOffsets(double beginPointRelativeOffset, double endPointRelativeOffset)
      Returns a list of points that constitutes a subpolyline that is a part of this polyline located between the specified relative offsets.

    • If endPointRelativeOffset > beginPointRelativeOffset, the direction of the resulting list of points is the same as direction of this polyline
    • If beginPointRelativeOffset > endPointRelativeOffset, the direction of the resulting list of points is reversed compared to this polyline
    • If beginPointRelativeOffset = endPointRelativeOffset, the result is the list with only one point and located at the specified relative offset
    • If either of the specified offsets is outside the range of [0, number of points - 1], returns null

      All comparisons above are made using the default comparator (Compare).

    • Parameters:
      beginPointRelativeOffset - specified relative offset of the begin point
      endPointRelativeOffset - specified relative offset of the end point
      Returns:
      list of points that constitutes a subpolyline of this polyline between the specified relative offsets, or null
      See Also:
    • getSubPolylineByAbsoluteOffsets

      public Polyline getSubPolylineByAbsoluteOffsets(double beginPointAbsoluteOffset, double endPointAbsoluteOffset)
      Returns subpolyline that is a part of this polyline located between the specified absolute offsets.

    • If endPointAbsoluteOffset > beginPointAbsoluteOffset, the direction of the resulting polyline is the same as direction of this polyline
    • If beginPointAbsoluteOffset > endPointAbsoluteOffset, the direction of the resulting polyline is reversed compared to this polyline
    • If beginPointAbsoluteOffset = endPointAbsoluteOffset, the resulting polyline contains only one point and located at the specified absolute offset
    • If either of the specified offsets is outside the range of [0, number of points - 1], returns null

      All comparisons above are made using the default comparator (Compare).

    • Parameters:
      beginPointAbsoluteOffset - specified absolute offset of the begin point
      endPointAbsoluteOffset - specified absolute offset of the end point
      Returns:
      polyline that is a subpolyline of this polyline between the specified absolute offsets, or null
    • getSubPolylineByAbsoluteOffsets

      public Polyline getSubPolylineByAbsoluteOffsets(double beginPointAbsoluteOffset, double endPointAbsoluteOffset, EpsilonComparator comparator)
      Returns subpolyline that is a part of this polyline located between the specified absolute offsets.

    • If endPointAbsoluteOffset > beginPointAbsoluteOffset, the direction of the resulting polyline is the same as direction of this polyline
    • If beginPointAbsoluteOffset > endPointAbsoluteOffset, the direction of the resulting polyline is reversed compared to this polyline
    • If beginPointAbsoluteOffset = endPointAbsoluteOffset, the resulting polyline contains only one point and located at the specified absolute offset
    • If either of the specified offsets is outside the range of [0, number of points - 1], returns null

    • Parameters:
      beginPointAbsoluteOffset - specified absolute offset of the begin point
      endPointAbsoluteOffset - specified absolute offset of the end point
      comparator - specified comparator to compare length and distances
      Returns:
      polyline that is a subpolyline of this polyline between the specified absolute offsets, or null
    • getPointsOfSubPolylineByAbsoluteOffsets

      public List<Point> getPointsOfSubPolylineByAbsoluteOffsets(double beginPointAbsoluteOffset, double endPointAbsoluteOffset)
      Returns list of points that constitutes a subpolyline that is a part of this polyline located between the specified absolute offsets.

    • If endPointAbsoluteOffset > beginPointAbsoluteOffset, the direction of the resulting list of points is the same as direction of this polyline
    • If beginPointAbsoluteOffset > endPointAbsoluteOffset, the direction of the resulting list of points is reversed compared to this polyline
    • If beginPointAbsoluteOffset = endPointAbsoluteOffset, the resulting list of points contains only one point and located at the specified absolute offset
    • If either of the specified offsets is outside the range of [0, number of points - 1], returns null

      All comparisons above are made using the default comparator (Compare).

    • Parameters:
      beginPointAbsoluteOffset - specified absolute offset of the begin point
      endPointAbsoluteOffset - specified absolute offset of the end point
      Returns:
      list of points that constitutes a polyline that is a subpolyline of this polyline between the specified absolute offsets, or null
    • getPointsOfSubPolylineByAbsoluteOffsets

      public List<Point> getPointsOfSubPolylineByAbsoluteOffsets(double beginPointAbsoluteOffset, double endPointAbsoluteOffset, EpsilonComparator comparator)
      Returns list of points that constitutes a subpolyline that is a part of this polyline located between the specified absolute offsets.

    • If endPointAbsoluteOffset > beginPointAbsoluteOffset, the direction of the resulting list of points is the same as direction of this polyline
    • If beginPointAbsoluteOffset > endPointAbsoluteOffset, the direction of the resulting list of points is reversed compared to this polyline
    • If beginPointAbsoluteOffset = endPointAbsoluteOffset, the resulting list of points contains only one point and located at the specified absolute offset
    • If either of the specified offsets is outside the range of [0, number of points - 1], returns null

    • Parameters:
      beginPointAbsoluteOffset - specified absolute offset of the begin point
      endPointAbsoluteOffset - specified absolute offset of the end point
      comparator - specified comparator to compare length and distances
      Returns:
      list of points that constitutes a polyline that is a subpolyline of this polyline between the specified absolute offsets, or null
    • getReversed

      public Polyline getReversed()
      Returns this polyline directed in the reverse direction. The resulting polyline will have reversed list of points and reversed list of reversed segments of this polyline.
      Returns:
      polyline directed in the reverse direction to this one
    • add

      public Polyline add(Polyline polyline)
      Returns a new polyline which is a concatenation of this polyline and the specified polyline.
    • If the last point of this polyline equals the first point of the specified polyline, the resulting polyline will not contain this duplication
    • If the last point of this polyline does not equal the first point of the specified polyline, the resulting polyline will not contain segment connection these points
    • Parameters:
      polyline - specified polyline
      Returns:
      new polyline which is a concatenation of this polyline and the specified polyline
    • getSmoothed

      public Polyline getSmoothed(double maxSmoothingVectorLength, double minAngleToSmooth, int hermitePointsNumber)
      Returns a new polyline that is this polyline smoothed according to the specified smoothing parameters. Begin and end points of this polyline are preserved
      Parameters:
      maxSmoothingVectorLength - maximum length of the smoothing vector. Must be within the range of length of minimum non-zero length segment
      minAngleToSmooth - minimum angle to be smoothed, in positive radians. Typical value is PI/3
      hermitePointsNumber - number of points that will be used to smooth each angle
      Returns:
      smoothed polyline
    • getSmoothed

      public Polyline getSmoothed()
      Returns a new polyline that is this polyline smoothed according to the default smoothing parameters. Begin and end points of this polyline are preserved
      Returns:
      smoothed polyline
    • getSimplified

      public Polyline getSimplified()
      Simplifies this polyline by removing all non-bendpoints, retaining only the key points that define the shape of the polyline. The first and last points of the polyline are always preserved, ensuring the simplified polyline accurately represents the original shape.

      A bendpoint is defined as a point where the direction (heading) of the polyline changes. Consecutive points along a straight segment are removed, except for the endpoints of the segment. If this polyline has several consecutive equal points, the simplifed polyline will contain at most one of such points.

      This original polyline is not modified by this method. A new Polyline instance is created and returned, containing the simplified set of points.

      If this polyline has no points, an empty polyline is returned. Otherwise, the first and last points are included in the result even if they are not bendpoints.

      Returns:
      a new Polyline instance containing the simplified set of points that define the essential shape of this polyline.
    • intersectsWith

      public boolean intersectsWith(Segment segment, boolean includeEndPoints)
      Checks whether this polyline intersects with the specified segment. Allows to include or exclude end points of this polyline and the segment.
      Parameters:
      segment - specified segment
      includeEndPoints - include or exclude end points of this polyline and the segment
      Returns:
      true if this polyline intersects with the specified segment, false otherwise
    • intersectsWith

      public boolean intersectsWith(Segment segment)
      Checks whether this polyline intersects with the specified segment. Includes end points of both this polyline and the specified segment.
      Parameters:
      segment - specified segment
      Returns:
      true if this polyline intersects with the specified segment, false otherwise
    • getFirstIntersectionPoint

      public Point getFirstIntersectionPoint(Segment segment, boolean includeEndPoints)
      Returns the point of this polyline's intersection with the specified segment having minimal absolute offset, or null if this polyline does not intersect with the specified segment. Allows to include or exclude end points of this polyline and the segment.
      Parameters:
      segment - specified segment
      includeEndPoints - include or exclude end points of this polyline and the segment
      Returns:
      first point of intersection, or null
    • getFirstIntersectionPoint

      public Point getFirstIntersectionPoint(Segment segment)
      Returns the point of this polyline's intersection with the specified segment having minimal absolute offset, or null if this polyline does not intersect with the specified segment. Includes end points of both this polyline and the specified segment.
      Parameters:
      segment - specified segment
      Returns:
      first point of intersection, or null
    • getFirstIntersection

      public IntersectionDescriptor getFirstIntersection(Segment segment, boolean includeEndPoints)
      Returns the IntersectionDescriptor object describing polyline's intersection with the specified segment having minimal absolute offset, or null if this polyline does not intersect with the specified segment. Allows to include or exclude end points of this polyline and the segment.
      Parameters:
      segment - specified segment
      includeEndPoints - include or exclude end points of this polyline and the segment
      Returns:
      IntersectionDescriptor object describing first point of intersection, or null
    • getFirstIntersection

      public IntersectionDescriptor getFirstIntersection(Segment segment)
      Returns the IntersectionDescriptor object describing polyline's intersection with the specified segment having minimal absolute offset, or null if this polyline does not intersect with the specified segment. Includes end points of both this polyline and the specified segment.
      Parameters:
      segment - specified segment
      Returns:
      IntersectionDescriptor object describing first point of intersection, or null
    • getIntersection

      public IntersectionDescriptor getIntersection(Point point, boolean includeEndPoint)
      Returns the IntersectionDescriptor object describing polyline's intersection with the specified point, or null if the specified point does not lie on this polyline. Allows to include or exclude end points of this polyline and the segment.
      Parameters:
      point - specified point
      includeEndPoint - include or exclude end points of this polyline
      Returns:
      IntersectionDescriptor object describing first point of intersection, or null
    • getIntersection

      public IntersectionDescriptor getIntersection(Point point)
      Returns the IntersectionDescriptor object describing polyline's intersection with the specified point, or null if the specified point does not lie on this polyline. Includes the end point of this polyline.
      Parameters:
      point - specified point
      Returns:
      IntersectionDescriptor object describing first point of intersection, or null
    • getAllIntersectionPoints

      public List<Point> getAllIntersectionPoints(Segment segment, boolean considerEndPoints)
      Returns an unmodifiable list of points at which this polyline intersects with the specified segment. Allows to include or exclude end points of this polyline and the segment. The points are ordered by their absolute offsets on this polyline, in ascending order.

      If the specified segment fully or partially overlaps with this polyline, begin and end points of overlapping subsegments are included into the resulting list.

      If the specified segment does not intersect with this polyline, returns an empty list.

      Parameters:
      segment - specified segment
      considerEndPoints - include or exclude end points of this polyline and the specified segment when detecting intersections
      Returns:
      unmodifiable list of points at which this polyline intersects with the specified segment
    • getAllIntersectionPoints

      public List<Point> getAllIntersectionPoints(Segment segment)
      Returns an unmodifiable list of points at which this polyline intersects with the specified segment. The points are ordered by their absolute offsets on this polyline, in ascending order.

      If the specified segment fully or partially overlaps with this polyline, begin and end points of overlapping subsegments are included into the resulting list.

      If the specified segment does not intersect with this polyline, returns an empty list.

      Parameters:
      segment - specified segment
      Returns:
      unmodifiable list of points at which this polyline intersects with the specified segment
    • getAllIntersections

      public List<IntersectionDescriptor> getAllIntersections(Segment segment, boolean considerEndPoints)
      Returns an unmodifiable list of IntersectionDescriptor instances representing the points at which this polyline intersects with the specified segment. Allows to include or exclude end points of this polyline and the segment. The elements of the list are ordered by their absolute offsets on this polyline, in ascending order.

      If the specified segment fully or partially overlaps with this polyline, descriptors of begin and end points of overlapping subsegments are included into the resulting list.

      If the specified segment does not intersect with this polyline, returns an empty list.

      Parameters:
      segment - specified segment
      considerEndPoints - include or exclude end points of this polyline and the specified segment when detecting intersections
      Returns:
      unmodifiable list of IntersectionDescriptor instances representing the points at which this polyline intersects with the specified segment
    • getAllIntersections

      public List<IntersectionDescriptor> getAllIntersections(Segment segment)
      Returns an unmodifiable list of IntersectionDescriptor instances representing the points at which this polyline intersects with the specified segment. The elements of the list are ordered by their absolute offsets on this polyline, in ascending order.

      If the specified segment fully or partially overlaps with this polyline, descriptors of begin and end points of overlapping subsegments are included into the resulting list.

      If the specified segment does not intersect with this polyline, returns an empty list.

      Parameters:
      segment - specified segment
      Returns:
      unmodifiable list of IntersectionDescriptor instances representing the points at which this polyline intersects with the specified segment
    • intersectsWith

      public boolean intersectsWith(Polyline polyline, boolean considerEndPoints)
      Checks whether this polyline intersects with the specified other polyline. Allows to include or exclude end points of both polylines.

      It might make sense to use this method instead of getFirstIntersection(Polyline) when it is only needed to check whether an intersection exists because this method is faster.

      Parameters:
      polyline - specified other polyline
      considerEndPoints - include or exclude end points of both polylines
      Returns:
      true if this polyline intersects with the specified other polyline, false otherwise
    • intersectsWith

      public boolean intersectsWith(Polyline polyline)
      Checks whether this polyline intersects with the specified other polyline. Includes end points of both polylines when checking for intersection.

      It might make sense to use this method instead of getFirstIntersection(Polyline) when it is only needed to check whether an intersection exists because this method is faster.

      Parameters:
      polyline - specified other polyline
      Returns:
      true if this polyline intersects with the specified other polyline, false otherwise
    • getFirstIntersectionPoint

      public Point getFirstIntersectionPoint(Polyline polyline, boolean considerEndPoints)
      Returns the first intersection point of this polyline and the specified other polyline, or null if the polylines do not intersect. First intersection point is the one with smallest absolute offset on this polyline. Allows to include or exclude end points of both polylines when detecting intersection.
      Parameters:
      polyline - specified other polyline
      considerEndPoints - include or exclude end points of both polylines
      Returns:
      first intersection point of this polyline and the specified other polyline, or null
    • getFirstIntersectionPoint

      public Point getFirstIntersectionPoint(Polyline polyline)
      Returns the first intersection point of this polyline and the specified other polyline, or null if the polylines do not intersect. First intersection point is the one with smallest absolute offset on this polyline.
      Parameters:
      polyline - specified other polyline
      Returns:
      first intersection point of this polyline and the specified other polyline, or null
    • getFirstIntersection

      public IntersectionDescriptor getFirstIntersection(Polyline polyline, boolean considerEndPoints)
      Returns the IntersectionDescriptor instance representing the first intersection of this polyline and the specified other polyline, or null if the polylines do not intersect. First intersection is the one with smallest absolute offset on this polyline. Allows to include or exclude end points of both polylines when detecting intersection.
      Parameters:
      polyline - specified other polyline
      considerEndPoints - include or exclude end points of both polylines
      Returns:
      IntersectionDescriptor instance representing the first intersection of this polyline and the specified other polyline, or null
    • getFirstIntersection

      public IntersectionDescriptor getFirstIntersection(Polyline polyline)
      Returns the IntersectionDescriptor instance representing the first intersection of this polyline and the specified other polyline, or null if the polylines do not intersect. First intersection is the one with smallest absolute offset on this polyline.
      Parameters:
      polyline - specified other polyline
      Returns:
      IntersectionDescriptor instance representing the first intersection of this polyline and the specified other polyline, or null
    • getAllIntersectionPoints

      public List<Point> getAllIntersectionPoints(Polyline polyline, boolean considerEndPoints)
      Returns a list of points where this polyline intersects with the specified other polyline. List elements are ordered by absolute offset of the points on this polyline in ascending order. Allows to include or exclude end points of both polylines.

      If intersection of the two polylines contains segments (for example, like on the figure below), then for each such segment the resulting list contains two points - the begin and the end point of the segment.

      If the two polylines do not intersect, returns an empty list.

      Parameters:
      polyline - specified other polyline
      considerEndPoints - include or exclude end points of both polylines
      Returns:
      list of points where this polyline intersects with the specified other polyline
    • getAllIntersectionPoints

      public List<Point> getAllIntersectionPoints(Polyline polyline)
      Returns a list of points where this polyline intersects with the specified other polyline. List elements are ordered by absolute offset of the points on this polyline in ascending order.

      If intersection of the two polylines contains segments (for example, like on the figure below), then for each such segment the resulting list contains two points - the begin and the end point of the segment.

      If the two polylines do not intersect, returns an empty list.

      Parameters:
      polyline - specified other polyline
      Returns:
      list of points where this polyline intersects with the specified other polyline
    • getAllIntersections

      public List<IntersectionDescriptor> getAllIntersections(Polyline polyline, boolean considerEndPoints)
      Returns a list of IntersectionDescriptor instances representing all points where this polyline intersects with the specified other polyline. List elements are ordered by absolute offset on this polyline in ascending order. Allows to include or exclude end points of both polylines.

      If intersection of the two polylines contains segments, then for each such segment the resulting list contains IntersectionDescriptor instances pointing to begin and end points of these segments.

      If the two polylines do not intersect, returns an empty list.

      Parameters:
      polyline - specified other polyline
      considerEndPoints - include or exclude end points of both polylines
      Returns:
      list of IntersectionDescriptor instances representing all points where this polyline intersects with the specified one
    • getAllIntersections

      public List<IntersectionDescriptor> getAllIntersections(Polyline polyline)
      Returns a list of IntersectionDescriptor instances representing all points where this polyline intersects with the specified other polyline. List elements are ordered by absolute offset on this polyline in ascending order.

      If intersection of the two polylines contains segments, then for each such segment the resulting list contains IntersectionDescriptor instances pointing to begin and end points of these segments.

      If the two polylines do not intersect, returns an empty list.

      Parameters:
      polyline - specified other polyline
      Returns:
      list of IntersectionDescriptor instances representing all points where this polyline intersects with the specified one
    • getParallelPolyline

      public Polyline getParallelPolyline(double distance)
      Returns a polyline that is parallel to this polyline and at the specified distance. The resulting polyline might contain self-intersections if the specified distance is comparable with or greater than length of some segments of this polyline. The resulting polyline always contains the same amount of points and segments, although the length of the resulting polyline might differ from the length of this polyline.

      If this polyline contains less than 2 points, throws IllegalStateException. If the specified distance is zero, the resulting polyline is equal to this polyline.

      In screen coordinates, if the specified distance is > 0, the resulting polyline will be located above and to the right of this polyline

      In screen coordinates, if the specified distance is < 0, the resulting polyline will be located below and to the left of this polyline

      Parameters:
      distance - specified distance
      Returns:
      polyline that is parallel to this polyline and at the specified distance
    • getParallelPolyline

      public Polyline getParallelPolyline(double distance, boolean correctSelfIntersections)
      Returns a polyline that is parallel to this polyline and at the specified distance correcting convexity if specified.

      If correctSelfIntersections = false, the resulting polyline is equal to result of getParallelPolyline(double) function.

      If correctSelfIntersections = true, the resulting polyline will not contain self-intersections even if the distance is greater than or comparable with length of this polyline's segments. In this case, the resulting polyline can contain less points and segments than this one.

      If this polyline contains less than 2 points, throws RuntimeException. If the specified distance is zero, the resulting polyline is equal to this polyline.

      In screen coordinates, if the specified distance is > 0, the resulting polyline will be located above and to the right of this polyline

      In screen coordinates, if the specified distance is < 0, the resulting polyline will be located below and to the left of this polyline

      Parameters:
      distance - specified distance
      correctSelfIntersections - whether or not correct self intersections that might appear in the resulting polyline
      Returns:
      polyline that is parallel to this polyline and at the specified distance
      See Also:
    • getPolylineWithoutSelfIntersections

      public Polyline getPolylineWithoutSelfIntersections()
      Returns a new polyline which is equivalent to this polyline without self intersections. If this polyline contains no self intersections, the resulting polyline is equal to this one.
      Returns:
      this polyline without self intersections
      See Also:
    • distanceToPoint

      public double distanceToPoint(Point point)
      Returns the distance from the specified point to this polyline. The distance is defined as length of the shortest possible segment connecting the specified point and this polyline.
      Parameters:
      point - specified point
      Returns:
      distance from the specified point to this polyline
    • getClosestPointTo

      public Point getClosestPointTo(Point point)
      Returns the first point on this polyline that is closest to the specified point. If there are several such points, returns the one with the smallest absolute offset. If the specified point lies on this polyline, returns the specified point.
      Parameters:
      point - specified point
      Returns:
      point on polyline that is closest to the specified point
    • plus

      public Polyline plus(Point point)
      Returns the polyline that is point-wise sum of this polyline and the specified point. The resulting polyline has the same number of points as this one, and every point of the resulting polyline is a sum of the corresponding point of this polyline and the specified point.
      Parameters:
      point - specified point
      Returns:
      polyline that is point-wise sum of this polyline and the specified point
      See Also:
    • minus

      public Polyline minus(Point point)
      Returns the polyline that is point-wise difference of this polyline and the specified point. The resulting polyline has the same number of points as this one, and every point of the resulting polyline is a difference of the corresponding point of this polyline and the specified point.
      Parameters:
      point - specified point
      Returns:
      polyline that is point-wise difference of this polyline and the specified point
      See Also:
    • multiply

      public Polyline multiply(double factor)
      Returns the polyline that is point-wise product of this polyline and the specified factor. The resulting polyline has the same number of points as this one, and every point of the resulting polyline is a product of the corresponding point of this polyline and the specified factor.
      Parameters:
      factor - multiplication factor
      Returns:
      polyline that is point-wise difference of this polyline and the specified point
      See Also:
    • getRotated

      public Polyline getRotated(double angle)
      Returns a polyline that is a result of rotation of this polyline around the (0, 0) point by the specified angle.

      In screen coordinate system, if the angle is positive, the rotation is directed counter-clockwise. If the angle is negative, the rotation is directed clockwise

      Parameters:
      angle - rotation angle, in radians
      Returns:
      rotated polyline
    • hasSelfIntersections

      public boolean hasSelfIntersections()
      Checks whether this polyline has self intersections.
      Returns:
      true if this polyline has self intersections, false otherwise
      See Also:
    • getClosestPointAbsOffset

      public double getClosestPointAbsOffset(Point point)
      Returns the smallest absolute offset of the point on this polyline that is closest to the specified point. If the specified point lies on this polyline, returns the specified absolute offset of this point.
      Parameters:
      point - specified point
      Returns:
      smallest absolute offset of the point on this polyline that is closest to the specified point
    • getConnectingSegment

      public Segment getConnectingSegment(Polyline otherPolyline)
      Returns the shortest possible segment that connects this polyline to the specified polyline. If there are several such segments, returns the one connecting the points with smallest absolute offsets of respective polylines. The segment is directed from this polyline to the specified polyline. Returns null if the two polylines intersect.

      Parameters:
      otherPolyline - specified polyline
      Returns:
      shortest possible segment that connects this polyline to the specified polyline, or null
    • getCopy

      public Polyline getCopy()
      Returns a copy of this polyline.
      Returns:
      copy of this polyline
    • getEquidistantPolyline

      public Polyline getEquidistantPolyline(double distance)
      Returns a polyline that is an approximation of equidistant line for this polyline at the specified distance. The resulting polyline never contains self-intersections. The length of the resulting polyline might differ from the length of this polyline.

      In simple cases, the result of this method is the same as result of getParallelPolyline(double). It can make sense to use this method if this polyline contains sharp corners and spikes (see the picture below) because getParallelPolyline(double) method might provide an unexpected result in such cases.

      If this polyline contains less than 2 points, throws IllegalStateException. If the specified distance is zero, the resulting polyline is equal to this polyline.

      In screen coordinates, if the specified distance is > 0, the resulting polyline will be located above and to the right of this polyline

      In screen coordinates, if the specified distance is < 0, the resulting polyline will be located below and to the left of this polyline

      Parameters:
      distance - specified distance
      Returns:
      polyline that is parallel to this polyline and at the specified distance
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

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

      public String toCodeString()
      Description copied from class: AbstractGeometricPrimitive
      Returns the string representing Java code that creates this primitive in its current state
      Specified by:
      toCodeString in class AbstractGeometricPrimitive
      Returns:
      Java code required to create this primitive in its current state