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): SegmentCreates 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.
resultoptional- 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): BoxComputes the axis-aligned bounding box of the specified line segment.
segment- The line segment whose bounding box is computed.
resultoptional- Optional box to store the result; if null, a new box is created.
Returns A box representing the bounds of the line segment.
copystatic
directedSegmentstatic
static directedSegment(p: Point | VectorLike, dir: Vector | VectorLike, result?: Segment | null): SegmentCreates 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.
resultoptional- Optional output
LineSegmentinstance.
Returns A line segment beginning at p and oriented along dir.
directionstatic
static direction(segment: Segment | ShapeLike, result?: Vector | null): VectorComputes the primary direction of the specified line segment.
segment- The line segment whose direction is computed.
resultoptional- 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): RealComputes the horizontal length of the specified line segment.
segment- The line segment whose horizontal length is computed.
resultoptional- Optional length to store the result; if null, a new length is created.
Returns The absolute horizontal component of the line segment.
lenstatic
lengthAlongAxisstatic
static lengthAlongAxis(segment: Segment | ShapeLike, horizontal: Bool | BoolLike, result?: Real | null): RealComputes 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. resultoptional- 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): PointComputes the midpoint of the specified line segment.
segment- The line segment whose midpoint is computed.
resultoptional- 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): PointComputes the point located at a given fractional position along a line segment.
segment- The line segment to evaluate.
ratio- A value between
0and1indicating the relative position along the segment, where0corresponds to the start point and1corresponds to the end point. resultoptional- Optional output
Pointinstance 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): SegmentCreates 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.
resultoptional- 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): SegmentCreates a line segment defined by two endpoints.
p1- The starting point of the segment.
p2- The ending point of the segment.
resultoptional- Optional output
LineSegmentinstance.
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): SegmentCreates 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.
resultoptional- 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): RealComputes the vertical length of the specified line segment.
segment- The line segment whose vertical length is computed.
resultoptional- Optional length to store the result; if null, a new length is created.
Returns The absolute vertical component of the line segment.
