Class Polyline
- Direct Known Subclasses:
Polygon
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a new polyline which is a concatenation of this polyline and the specified polyline.protected booleanboundsIntersect(Polyline otherPolyline) booleancontainsPoint(Point point) Checks whether this primitive contains the specified pointbooleancontainsPoint(Point point, boolean includeEndPoint) Checks whether this polyline contains the specified point, i.e.doubledistanceToPoint(Point point) Returns the distance from the specified point to this polyline.booleangetAllIntersectionPoints(Polyline polyline) Returns a list of points where this polyline intersects with the specified other polyline.getAllIntersectionPoints(Polyline polyline, boolean considerEndPoints) Returns a list of points where this polyline intersects with the specified other polyline.getAllIntersectionPoints(Segment segment) Returns an unmodifiable list of points at which this polyline intersects with the specified segment.getAllIntersectionPoints(Segment segment, boolean considerEndPoints) Returns an unmodifiable list of points at which this polyline intersects with the specified segment.getAllIntersections(Polyline polyline) Returns a list ofIntersectionDescriptorinstances representing all points where this polyline intersects with the specified other polyline.getAllIntersections(Polyline polyline, boolean considerEndPoints) Returns a list ofIntersectionDescriptorinstances representing all points where this polyline intersects with the specified other polyline.getAllIntersections(Segment segment) Returns an unmodifiable list ofIntersectionDescriptorinstances representing the points at which this polyline intersects with the specified segment.getAllIntersections(Segment segment, boolean considerEndPoints) Returns an unmodifiable list ofIntersectionDescriptorinstances representing the points at which this polyline intersects with the specified segment.doublegetClosestPointAbsOffset(Point point) Returns the smallest absolute offset of the point on this polyline that is closest to the specified point.getClosestPointTo(Point point) Returns the first point on this polyline that is closest to the specified point.getConnectingSegment(Polyline otherPolyline) Returns the shortest possible segment that connects this polyline to the specified polyline.getCopy()Returns a copy of this polyline.getEquidistantPolyline(double distance) Returns a polyline that is an approximation of equidistant line for this polyline at the specified distance.getFirstIntersection(Polyline polyline) Returns theIntersectionDescriptorinstance representing the first intersection of this polyline and the specified other polyline, ornullif the polylines do not intersect.getFirstIntersection(Polyline polyline, boolean considerEndPoints) Returns theIntersectionDescriptorinstance representing the first intersection of this polyline and the specified other polyline, ornullif the polylines do not intersect.getFirstIntersection(Segment segment) Returns theIntersectionDescriptorobject describing polyline's intersection with the specified segment having minimal absolute offset, or null if this polyline does not intersect with the specified segment.getFirstIntersection(Segment segment, boolean includeEndPoints) Returns theIntersectionDescriptorobject describing polyline's intersection with the specified segment having minimal absolute offset, or null if this polyline does not intersect with the specified segment.getFirstIntersectionPoint(Polyline polyline) Returns the first intersection point of this polyline and the specified other polyline, ornullif the polylines do not intersect.getFirstIntersectionPoint(Polyline polyline, boolean considerEndPoints) Returns the first intersection point of this polyline and the specified other polyline, ornullif the polylines do not intersect.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.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.Returns the first point of this polyline, or null if this polyline is emptyReturns the first segment of this polyline, or null if this polyline has no segmentsgetIntersection(Point point) Returns theIntersectionDescriptorobject describing polyline's intersection with the specified point, or null if the specified point does not lie on this polyline.getIntersection(Point point, boolean includeEndPoint) Returns theIntersectionDescriptorobject describing polyline's intersection with the specified point, or null if the specified point does not lie on this polyline.Returns the last point of this polyline, or null if this polyline is emptyReturns the last segment of this polyline, or null if this polyline has no segmentsdoubleReturns the length of this polyline.Returns the maximum point of this polyline's bounds.Returns the minimum point of this polyline's bounds.getParallelPolyline(double distance) Returns a polyline that is parallel to this polyline and at the specified distance.getParallelPolyline(double distance, boolean correctSelfIntersections) Returns a polyline that is parallel to this polyline and at the specified distance correcting convexity if specified.getPointAndSegmentIndexByAbsoluteOffset(double absoluteOffset) getPointAndSegmentIndexByAbsoluteOffset(double absoluteOffset, EpsilonComparator comparator) getPointByAbsoluteOffset(double absoluteOffset) Returns point on this polyline by its absolute offset on this polyline, i.e.getPointByRelativeOffset(double relativeOffset) Returns point on this polyline by its relative offset on this polyline.Returns unmodifiable list of points of this polyline.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.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.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.Returns a new polyline which is equivalent to this polyline without self intersections.Returns this polyline directed in the reverse direction.getRotated(double angle) Returns a polyline that is a result of rotation of this polyline around the (0, 0) point by the specified angle.Returns unmodifiable list of segments of this polyline.Simplifies this polyline by removing all non-bendpoints, retaining only the key points that define the shape of the polyline.Returns a new polyline that is this polyline smoothed according to the default smoothing parameters.getSmoothed(double maxSmoothingVectorLength, double minAngleToSmooth, int hermitePointsNumber) Returns a new polyline that is this polyline smoothed according to the specified smoothing parameters.getSubPolylineByAbsoluteOffsets(double beginPointAbsoluteOffset, double endPointAbsoluteOffset) Returns subpolyline that is a part of this polyline located between the specified absolute offsets.getSubPolylineByAbsoluteOffsets(double beginPointAbsoluteOffset, double endPointAbsoluteOffset, EpsilonComparator comparator) Returns subpolyline that is a part of this polyline located between the specified absolute offsets.getSubPolylineByRelativeOffsets(double beginPointRelativeOffset, double endPointRelativeOffset) Returns subpolyline that is a part of this polyline located between the specified relative offsets.inthashCode()booleanChecks whether this polyline has self intersections.booleanintersectsWith(Polyline polyline) Checks whether this polyline intersects with the specified other polyline.booleanintersectsWith(Polyline polyline, boolean considerEndPoints) Checks whether this polyline intersects with the specified other polyline.booleanintersectsWith(Segment segment) Checks whether this polyline intersects with the specified segment.booleanintersectsWith(Segment segment, boolean includeEndPoints) Checks whether this polyline intersects with the specified segment.booleanisEmpty()Checks whether this polyline is empty, e.g.Returns the polyline that is point-wise difference of this polyline and the specified point.multiply(double factor) Returns the polyline that is point-wise product of this polyline and the specified factor.Returns the polyline that is point-wise sum of this polyline and the specified point.Returns the string representing Java code that creates this primitive in its current statetoString()
-
Field Details
-
segments
-
points
-
length
protected double length
-
-
Constructor Details
-
Polyline
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
Creates a new instance of polyline with specified pointsNote 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
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:
trueif this polyline is empty,falseotherwise.
-
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
-
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
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
Returns the first point of this polyline, or null if this polyline is empty- Returns:
- first point of this polyline
-
getLastPoint
Returns the last point of this polyline, or null if this polyline is empty- Returns:
- last point of this polyline
-
getFirstSegment
Returns the first segment of this polyline, or null if this polyline has no segments- Returns:
- first segment of this polyline
-
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
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 pointincludeEndPoint- include or exclude end point of this polyline- Returns:
trueif this polyline contains the specified point,falseotherwise.
-
containsPoint
Description copied from class:AbstractGeometricPrimitiveChecks whether this primitive contains the specified point- Specified by:
containsPointin classAbstractGeometricPrimitive- Parameters:
point- the specified point- Returns:
trueif this primitive contains the specified point,falseotherwise
-
getPointByRelativeOffset
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
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
Returns aPaircontaining thePointlocated 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
Pairof the point and the segment index, ornullif the offset is out of bounds or if there are no segments
-
getPointAndSegmentIndexByAbsoluteOffset
public Pair<Point,Integer> getPointAndSegmentIndexByAbsoluteOffset(double absoluteOffset, EpsilonComparator comparator) Returns aPaircontaining thePointlocated 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 lengthscomparator- specified comparator to compare length and distances- Returns:
- a
Pairof the point and the segment index, ornullif 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 pointendPointRelativeOffset- 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 pointendPointRelativeOffset- 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 pointendPointAbsoluteOffset- 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 pointendPointAbsoluteOffset- specified absolute offset of the end pointcomparator- 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 pointendPointAbsoluteOffset- 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 pointendPointAbsoluteOffset- specified absolute offset of the end pointcomparator- 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
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
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 segmentminAngleToSmooth- minimum angle to be smoothed, in positive radians. Typical value is PI/3hermitePointsNumber- number of points that will be used to smooth each angle- Returns:
- smoothed 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
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
Polylineinstance 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
Polylineinstance containing the simplified set of points that define the essential shape of this polyline.
-
intersectsWith
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 segmentincludeEndPoints- include or exclude end points of this polyline and the segment- Returns:
trueif this polyline intersects with the specified segment,falseotherwise
-
intersectsWith
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:
trueif this polyline intersects with the specified segment,falseotherwise
-
getFirstIntersectionPoint
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 segmentincludeEndPoints- include or exclude end points of this polyline and the segment- Returns:
- first point of intersection, or null
-
getFirstIntersectionPoint
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
Returns theIntersectionDescriptorobject 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 segmentincludeEndPoints- include or exclude end points of this polyline and the segment- Returns:
IntersectionDescriptorobject describing first point of intersection, or null
-
getFirstIntersection
Returns theIntersectionDescriptorobject 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:
IntersectionDescriptorobject describing first point of intersection, or null
-
getIntersection
Returns theIntersectionDescriptorobject 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 pointincludeEndPoint- include or exclude end points of this polyline- Returns:
IntersectionDescriptorobject describing first point of intersection, or null
-
getIntersection
Returns theIntersectionDescriptorobject 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:
IntersectionDescriptorobject describing first point of intersection, or null
-
getAllIntersectionPoints
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 segmentconsiderEndPoints- 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
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
Returns an unmodifiable list ofIntersectionDescriptorinstances 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 segmentconsiderEndPoints- include or exclude end points of this polyline and the specified segment when detecting intersections- Returns:
- unmodifiable list of
IntersectionDescriptorinstances representing the points at which this polyline intersects with the specified segment
-
getAllIntersections
Returns an unmodifiable list ofIntersectionDescriptorinstances 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
IntersectionDescriptorinstances representing the points at which this polyline intersects with the specified segment
-
intersectsWith
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 polylineconsiderEndPoints- include or exclude end points of both polylines- Returns:
trueif this polyline intersects with the specified other polyline,falseotherwise
-
intersectsWith
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:
trueif this polyline intersects with the specified other polyline,falseotherwise
-
getFirstIntersectionPoint
Returns the first intersection point of this polyline and the specified other polyline, ornullif 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 polylineconsiderEndPoints- include or exclude end points of both polylines- Returns:
- first intersection point of this polyline and the specified other
polyline, or
null
-
getFirstIntersectionPoint
Returns the first intersection point of this polyline and the specified other polyline, ornullif 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
Returns theIntersectionDescriptorinstance representing the first intersection of this polyline and the specified other polyline, ornullif 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 polylineconsiderEndPoints- include or exclude end points of both polylines- Returns:
IntersectionDescriptorinstance representing the first intersection of this polyline and the specified other polyline, ornull
-
getFirstIntersection
Returns theIntersectionDescriptorinstance representing the first intersection of this polyline and the specified other polyline, ornullif the polylines do not intersect. First intersection is the one with smallest absolute offset on this polyline.- Parameters:
polyline- specified other polyline- Returns:
IntersectionDescriptorinstance representing the first intersection of this polyline and the specified other polyline, ornull
-
getAllIntersectionPoints
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 polylineconsiderEndPoints- include or exclude end points of both polylines- Returns:
- list of points where this polyline intersects with the specified other polyline
-
getAllIntersectionPoints
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 ofIntersectionDescriptorinstances 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
IntersectionDescriptorinstances pointing to begin and end points of these segments.If the two polylines do not intersect, returns an empty list.

- Parameters:
polyline- specified other polylineconsiderEndPoints- include or exclude end points of both polylines- Returns:
- list of
IntersectionDescriptorinstances representing all points where this polyline intersects with the specified one
-
getAllIntersections
Returns a list ofIntersectionDescriptorinstances 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
IntersectionDescriptorinstances 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
IntersectionDescriptorinstances representing all points where this polyline intersects with the specified one
-
getParallelPolyline
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 polylineIn 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
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 polylineIn 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 distancecorrectSelfIntersections- 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
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
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
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
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
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
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
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:
trueif this polyline has self intersections,falseotherwise- See Also:
-
getClosestPointAbsOffset
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
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. Returnsnullif the two polylines intersect.
- Parameters:
otherPolyline- specified polyline- Returns:
- shortest possible segment that connects this polyline to the
specified polyline, or
null
-
getCopy
Returns a copy of this polyline.- Returns:
- copy of this polyline
-
getEquidistantPolyline
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) becausegetParallelPolyline(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 polylineIn 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
-
hashCode
public int hashCode() -
toString
-
toCodeString
Description copied from class:AbstractGeometricPrimitiveReturns the string representing Java code that creates this primitive in its current state- Specified by:
toCodeStringin classAbstractGeometricPrimitive- Returns:
- Java code required to create this primitive in its current state
-