Class: Segment
Defined in: index.ts:360
Segment represents a line segment between two points.
Remarks
All operations are immutable and return new Segment instances.
Constructors
Constructor
new Segment(
p1
,p2
):Segment
Defined in: index.ts:366
Creates a new Segment instance.
Parameters
p1
The start point
p2
The end point
Returns
Segment
Properties
p1
p1:
Vec2
Defined in: index.ts:367
The start point
p2
p2:
Vec2
Defined in: index.ts:368
The end point
Accessors
length
Get Signature
get length():
number
Defined in: index.ts:384
Gets the length of this segment.
Returns
number
The distance between the endpoints
angle
Get Signature
get angle():
number
Defined in: index.ts:392
Gets the angle of this segment from the positive x-axis.
Returns
number
The angle in radians, in the range [-π, π]
Methods
equals()
equals(
other
):boolean
Defined in: index.ts:376
Checks if this segment equals another segment.
Parameters
other
Segment
The segment to compare with
Returns
boolean
True if both endpoints are equal
transform()
transform(
transform
):Segment
Defined in: index.ts:401
Transforms this segment by a transformation matrix.
Parameters
transform
The transformation to apply
Returns
Segment
A new transformed Segment
mix()
mix(
other
,ratio
):Segment
Defined in: index.ts:414
Linearly interpolates between this segment and another.
Parameters
other
Segment
The target segment
ratio
number
The interpolation ratio (0 = this, 1 = other)
Returns
Segment
A new Segment with interpolated endpoints
toString()
toString():
string
Defined in: index.ts:425
Returns a string representation of this segment.
Returns
string
A string in the format "Segment(p1,p2)"
toSVGLineProps()
toSVGLineProps():
object
Defined in: index.ts:434
Converts this segment to SVG line element properties.
Returns
object
An object with x1, y1, x2, y2 properties
x1
x1:
number
y1
y1:
number
x2
x2:
number
y2
y2:
number