class Geometry · Computations

Segments

Computations on segments: length, direction and midpoint, points on them, and segments made from a point and a direction.

Static methods

alongSegmentstatic

static alongSegment(p1: Point | VectorLike, p2: Point | VectorLike, leftSide: Bool | BoolLike, distance: Real | NumberLike, paddingStart: Real | NumberLike, paddingEnd: Real | NumberLike, result?: Segment | null): Segment

Creates a line segment along a segment defined by two points, positioned on a specified side, with optional start and end paddings.

If the sum of paddingStart and paddingEnd exceeds the length of the base segment, the line segment is positioned according to the weighted ratio of the paddings having length zero.

p1
The first point defining the base segment.
p2
The second point defining the base segment.
leftSide
Determines the side on which the line segment is positioned.
distance
The offset distance from the start of the segment at which the line segment is positioned, after applying paddings.
paddingStart
The padding applied at the start of the segment.
paddingEnd
The padding applied at the end of the segment.
result optional
Optional line segment to store the result; if null, a new line segment is created.

Returns A line segment constructed along the specified segment.

boundingBoxstatic

static boundingBox(segment: Segment | ShapeLike, result?: Box | null): Box

Computes the axis-aligned bounding box of the specified line segment.

segment
The line segment whose bounding box is computed.
result optional
Optional box to store the result; if null, a new box is created.

Returns A box representing the bounds of the line segment.

copystatic

static copy(segment: Segment | ShapeLike, result?: Segment | null): Segment

Creates a copy of the specified line segment.

segment
The line segment to copy.
result optional
Optional line segment to store the result; if null, a new line segment is created.

Returns A copy of the specified line segment.

directedSegmentstatic

static directedSegment(p: Point | VectorLike, dir: Vector | VectorLike, result?: Segment | null): Segment

Creates a directed line segment starting at the specified point and extending in the specified direction.

p
The starting point of the segment.
dir
The direction and length in which the segment extends.
result optional
Optional output LineSegment instance.

Returns A line segment beginning at p and oriented along dir.

directionstatic

static direction(segment: Segment | ShapeLike, result?: Vector | null): Vector

Computes the primary direction of the specified line segment.

segment
The line segment whose direction is computed.
result optional
Optional direction to store the result; if null, a new direction is created.

Returns The direction of the line segment.

horizontalLengthstatic

static horizontalLength(segment: Segment | ShapeLike, result?: Real | null): Real

Computes the horizontal length of the specified line segment.

segment
The line segment whose horizontal length is computed.
result optional
Optional length to store the result; if null, a new length is created.

Returns The absolute horizontal component of the line segment.

lenstatic

static len(segment: Segment | ShapeLike, result?: Real | null): Real

Computes the length of a line segment.

segment
The segment whose length is to be measured.
result optional
Optional length to store the result; if null, a new direction is created.

Returns The geometric length of segment.

lengthAlongAxisstatic

static lengthAlongAxis(segment: Segment | ShapeLike, horizontal: Bool | BoolLike, result?: Real | null): Real

Computes the horizontal or vertical component of a segment’s length.

segment
The segment to measure.
horizontal
If true, returns the horizontal (X-axis) component of the length; otherwise the vertical (Y-axis) component.
result optional
Optional length to store the result; if null, a new direction is created.

Returns The projection of segment onto the specified axis.

midPointstatic

static midPoint(segment: Segment | ShapeLike, result?: Point | null): Point

Computes the midpoint of the specified line segment.

segment
The line segment whose midpoint is computed.
result optional
Optional point to store the result; if null, a new point is created.

Returns The point located at the center of segment, equidistant from both endpoints.

pointAtstatic

static pointAt(segment: Segment | ShapeLike, ratio: Real | NumberLike, result?: Point | null): Point

Computes the point located at a given fractional position along a line segment.

segment
The line segment to evaluate.
ratio
A value between 0 and 1 indicating the relative position along the segment, where 0 corresponds to the start point and 1 corresponds to the end point.
result optional
Optional output Point instance used to store the computed position.

Returns The point on segment located at the specified ratio.

raystatic

static ray(pin: Pin | PinLike, length: Real | NumberLike, result?: Segment | null): Segment

Creates a line segment (ray) starting at the specified pin's position and extending in the pin's direction for the specified length.

pin
The pin defining the starting point and direction of the ray.
length
The length of the ray segment.
result optional
Optional line segment to store the result; if null, a new line segment is created.

Returns A line segment starting at pin's position and extending along pin's direction for the specified length.

segmentstatic

static segment(p1: Point | VectorLike, p2: Point | VectorLike, result?: Segment | null): Segment

Creates a line segment defined by two endpoints.

p1
The starting point of the segment.
p2
The ending point of the segment.
result optional
Optional output LineSegment instance.

Returns A line segment beginning at p1 and terminating at p2.

segmentAtPointstatic

static segmentAtPoint(point: Point | VectorLike, distance: Real | NumberLike, dir: Vector | VectorLike, ratio: Real | NumberLike, leftSide: Bool | BoolLike, result?: Segment | null): Segment

Creates a line segment at a specified point, offset by a given distance from the point, along a specified direction, with proportional placement along the segment and side orientation.

point
The reference point from which the segment is positioned.
distance
The perpendicular distance from the reference point to the line segment.
dir
The direction in which the segment is oriented. If both components are zero, the direction defaults to (1,0) along the positive X axis.
ratio
A value between 0 and 1 specifying the relative placement along the segment, where 0 is at the start and 1 is at the end.
leftSide
Determines which side of the reference point the segment is placed relative to the direction.
result optional
Optional line segment to store the result; if null, a new line segment is created.

Returns A line segment positioned at the specified distance and orientation relative to the point.

verticalLengthstatic

static verticalLength(segment: Segment | ShapeLike, result?: Real | null): Real

Computes the vertical length of the specified line segment.

segment
The line segment whose vertical length is computed.
result optional
Optional length to store the result; if null, a new length is created.

Returns The absolute vertical component of the line segment.