This class represents a line segment in the plane.
Remarks
Type Details
- yFiles module
- algorithms
Constructors
Returns a new LineSegment.
Properties
Gets the smallest rectangle that contains the object.
Implements
Gets the first endpoint of the line segment.
Gets the second endpoint of the line segment.
Methods
Determines whether a specified point lies on this line segment, within an optional tolerance.
Remarks
This method checks whether the specified point
lies within the bounds of this line segment, taking into account an optional tolerance eps
.
This method is particularly useful for determining point containment on line segments in the presence of floating-point inaccuracies or when a precise match is not feasible.
Parameters
A map of options to pass to the method.
- point - Point
- The point to check.
- eps - number
- The non-negative tolerance to apply when checking if the point lies on the line segment. Defaults to
0
. A small tolerance, such as1e-8
, can be used to account for floating-point precision errors.
Returns
- ↪boolean
true
if the point lies on the line segment within the specified tolerance; otherwise,false
.
Determines whether this segment is considered horizontal, meaning that the y-coordinate of its endpoints differ by at most the specified tolerance.
Remarks
A segment is considered horizontal if the absolute difference between the y-coordinates of its endpoints is less than the specified tolerance eps
. If eps
is not provided, the method checks for an exact match (eps
= 0).
This method is particularly useful when working with geometric segments where small inaccuracies in floating-point arithmetic might otherwise cause a segment to be incorrectly classified as non-horizontal.
Parameters
A map of options to pass to the method.
- eps - number
- The allowable difference in y-coordinates to consider the segment horizontal. Defaults to
0
. A small tolerance such as1e-8
can be used to account for floating-point precision errors.
Returns
- ↪boolean
true
if the y-coordinates of the endpoints of this segment differ by less thaneps
, indicating that the segment is considered horizontal; otherwise,false
.
Determines whether a specified x-coordinate lies within the projection of the line segment on the x-axis, considering an optional tolerance.
Remarks
The method checks if the given x-coordinate x
falls within the x-axis interval defined by the endpoints of the line segment, optionally reducing the interval by the tolerance eps
at both ends of the interval.
This method is useful in scenarios where you need to verify that a point falls within the horizontal range of a line segment, particularly when accounting for minor inaccuracies in floating-point calculations.
Parameters
A map of options to pass to the method.
- x - number
- The x-coordinate to check.
- eps - number
- The tolerance to apply when checking if the x-coordinate is within the interval. Defaults to
0
. A small tolerance, such as1e-8
, can be used to account for floating-point precision errors.
Returns
- ↪boolean
true
if the x-coordinate lies within the x-axis projection of the line segment, considering the specified tolerance; otherwise,false
.
Determines whether a specified y-coordinate lies within the projection of the line segment on the y-axis, considering an optional tolerance.
Remarks
The method checks if the given y-coordinate y
falls within the y-axis interval defined by the endpoints of the line segment, optionally reducing the interval by the tolerance eps
at both ends of the interval.
This method is useful in scenarios where you need to verify that a point falls within the vertical range of a line segment, particularly when accounting for minor inaccuracies in floating-point calculations.
Parameters
A map of options to pass to the method.
- y - number
- The y-coordinate to check.
- eps - number
- The tolerance to apply when checking if the y-coordinate is within the interval. Defaults to
0
. A small tolerance, such as1e-8
, can be used to account for floating-point precision errors.
Returns
- ↪boolean
true
if the y-coordinate lies within the y-axis projection of the line segment, considering the specified tolerance; otherwise,false
.
Determines whether this segment is considered vertical, meaning that the x-coordinate of its endpoints differ by at most the specified tolerance.
Remarks
A segment is considered vertical if the absolute difference between the x-coordinates of its endpoints is less than the specified tolerance eps
. If eps
is not provided, the method checks for an exact match (eps
= 0).
This method is particularly useful when working with geometric segments where small inaccuracies in floating-point arithmetic might otherwise cause a segment to be incorrectly classified as non-vertical.
Parameters
A map of options to pass to the method.
- eps - number
- The allowable difference in x-coordinates to consider the segment vertical. Defaults to
0
. A small tolerance such as1e-8
can be used to account for floating-point precision errors.
Returns
- ↪boolean
true
if the x-coordinates of the endpoints of this segment differ by less thaneps
, indicating that the segment is considered vertical; otherwise,false
.
Static Methods
Checks whether a line segment intersects a box.
Checks whether a line segment intersects a box.
Remarks
Parameters
A map of options to pass to the method.
- box - Rect
- A rectangle
- x1 - number
- x-coordinate of the first end point of the line segment
- y1 - number
- y-coordinate of the first end point of the line segment
- x2 - number
- x-coordinate of the second end point of the line segment
- y2 - number
- y-coordinate of the second end point of the line segment
Returns
- ↪boolean
true
if the line segment intersects the box,false
otherwise.
boxIntersectsSegment
(boxX1: number, boxY1: number, boxX2: number, boxY2: number, sX1: number, sY1: number, sX2: number, sY2: number) : booleanChecks whether a line segment intersects a paraxial box.
Remarks
Parameters
A map of options to pass to the method.
- boxX1 - number
- x-coordinate of the upper left corner of the box
- boxY1 - number
- y-coordinate of the upper left corner of the box
- boxX2 - number
- x-coordinate of the lower right corner of the box
- boxY2 - number
- y-coordinate of the lower right corner of the box
- sX1 - number
- x-coordinate of the first end point of the line segment
- sY1 - number
- y-coordinate of the first end point of the line segment
- sX2 - number
- x-coordinate of the second end point of the line segment
- sY2 - number
- y-coordinate of the second end point of the line segment
Returns
- ↪boolean
true
if the line segment intersects the box,false
otherwise.
Determines the intersection point between two line segments, if they intersect.
Remarks
This method computes the intersection point of the line segments s1
and s2
. If the line segments intersect within the given tolerance eps
, the method returns the intersection point as a Point. If there is no intersection or if the two line segments overlap, i.e., there is no unique intersection point, the method returns null
.
The method takes into account a small tolerance to handle potential floating-point inaccuracies. The line segments are treated as if they were shortened by the tolerance on both ends. This is useful to prevent intersections from being returned due to precision errors in cases where two line segments are close, but do not intersect. Moreover, a small tolerance can be used to model intersections of open line segments, i.e., if only the endpoint of a line segment lies on the other line segment, this shall not be treated as an intersection.
Parameters
A map of options to pass to the method.
- s1 - LineSegment
- The first line segment.
- s2 - LineSegment
- The second line segment.
- eps - number
- The non-negative tolerance to apply when checking for intersection. Defaults to
0
. A small tolerance, such as1e-8
, can be used to account for floating-point precision errors.
Returns
Determines whether the specified points define a horizontal line segment within a given tolerance.
Remarks
A horizontal line segment is characterized by having the same y-coordinate for both points. This method checks if the absolute difference between the y-coordinates of p1
and p2
is less than the specified tolerance eps
. If eps
is not provided, the method defaults to checking for an exact match (eps
= 0).
This method is useful in geometric computations where exact precision is challenging due to floating-point arithmetic limitations. By allowing a small tolerance, it accommodates minor computational inaccuracies.
Parameters
A map of options to pass to the method.
- p1 - Point
- The first point.
- p2 - Point
- The second point.
- eps - number
- The allowable difference in y-coordinates to consider the points as forming a horizontal line segment. Defaults to
0
. A typical value for a small tolerance is1e-8
.
Returns
- ↪boolean
true
if the x-coordinate ofp1
andp2
differ by less thaneps
, indicating that the points define a horizontal line segment; otherwise,false
.
Determines whether the specified points define a vertical line segment within a given tolerance.
Remarks
A vertical line segment is characterized by having the same x-coordinate for both points. This method checks if the absolute difference between the x-coordinates of p1
and p2
is less than the specified tolerance eps
. If eps
is not provided, the method defaults to checking for an exact match (eps
= 0).
This method is useful in geometric computations where exact precision is challenging due to floating-point arithmetic limitations. By allowing a small tolerance, it accommodates minor computational inaccuracies.
Parameters
A map of options to pass to the method.
- p1 - Point
- The first point.
- p2 - Point
- The second point.
- eps - number
- The allowable difference in x-coordinates to consider the points as forming a vertical line segment. Defaults to
0
. A typical value for a small tolerance is1e-8
.
Returns
- ↪boolean
true
if the x-coordinates ofp1
andp2
differ by less thaneps
, indicating that the points define a vertical line segment; otherwise,false
.