- I
Remarks
Members
Constructors
Returns a new LineSegment.
Properties
Gets the smallest rectangle that contains the object.
Implements
IPlaneObject.boundsProperty Value
Property Value
Gets the first endpoint of the line segment.
Gets the second endpoint of the line segment.
Property Value
Methods
Determines whether a specified point lies on this line segment, within an optional tolerance.
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
- 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.
Return Value
- boolean
trueif the point lies on the line segment within the specified tolerance; otherwise,false.
Checks whether the line segment intersects a box.
Parameters
- box: Rect
- A rectangle.
Return Value
- boolean
trueif the line segment intersects the box,falseotherwise.
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
- eps?: number
- The allowable difference in y-coordinates to consider the segment horizontal. Defaults to
0. A small tolerance such as1e-8can be used to account for floating-point precision errors.
Return Value
- boolean
trueif the y-coordinates of the endpoints of this segment differ by less thaneps, indicating that the segment is considered horizontal; otherwise,false.
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
- 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.
Return Value
- boolean
trueif the x-coordinate lies within the x-axis projection of the line segment, considering the specified tolerance; otherwise,false.
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
- 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.
Return Value
- boolean
trueif the y-coordinate lies within the y-axis projection of the line segment, considering the specified tolerance; otherwise,false.
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
- eps?: number
- The allowable difference in x-coordinates to consider the segment vertical. Defaults to
0. A small tolerance such as1e-8can be used to account for floating-point precision errors.
Return Value
- boolean
trueif the x-coordinates of the endpoints of this segment differ by less thaneps, indicating that the segment is considered vertical; otherwise,false.
Return Value
- number
- a value > 0.
Static Methods
Checks whether a line segment intersects a box.
Parameters
- 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
Return Value
- boolean
trueif the line segment intersects the box,falseotherwise.
Parameters
- 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
Return Value
- boolean
trueif the line segment intersects the box,falseotherwise.
Determines the intersection point between two line segments, if they intersect.
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
- 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.
Return Value
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
- 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.
Return Value
- boolean
trueif the x-coordinate ofp1andp2differ by less thaneps, indicating that the points define a horizontal line segment; otherwise,false.
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
- 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.
Return Value
- boolean
trueif the x-coordinates ofp1andp2differ by less thaneps, indicating that the points define a vertical line segment; otherwise,false.