LineSegment
Index
Constructors
constructor
Parameters
Returns LineSegment
Properties
publicreadonlybegin
The starting point of the line segment
publicreadonlyend
The ending point of the line segment
Accessors
publicintercept
Gets the Y-intercept (b) of the line. Will return (+/-)Infinity if there is no intercept.
Returns number
publicmidpoint
Returns the midpoint of the edge
Returns Vector
publicslope
Gets the raw slope (m) of the line. Will return (+/-)Infinity for vertical lines.
Returns number
Methods
publicbelow
Tests if a given point is below the line, points in the normal direction above the line are considered above.
Parameters
point: Vector
Returns boolean
publicclip
Returns the clip point
Parameters
sideVector: Vector
Vector that traces the line
length: number
Length to clip along side
Returns LineSegment
publicdir
Returns Vector
publicdistanceToPoint
Find the perpendicular distance from the line to a point https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
Parameters
point: Vector
signed: boolean = false
Returns number
publicfindPoint
Finds a point on the line given only an X or a Y value. Given an X value, the function returns a new point with the calculated Y value and vice-versa.
Parameters
x: number = null
The known X value of the target point
y: number = null
The known Y value of the target point
Returns Vector
A new point with the other calculated axis value
publicfindVectorToPoint
Find the perpendicular line from the line to a point https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line (a - p) - ((a - p) * n)n a is a point on the line p is the arbitrary point above the line n is a unit vector in direction of the line
Parameters
point: Vector
Returns Vector
publicflip
Flips the direction of the line segment
Returns LineSegment
publicgetEdge
Returns the edge of the line as vector, the length of the vector is the length of the edge
Returns Vector
publicgetLength
Returns the length of the line segment in pixels
Returns number
publicgetPoints
Returns Vector[]
publicgetSlope
Returns the slope of the line in the form of a vector of length 1
Returns Vector
publichasPoint
Whether or not the given point lies on this line. This method is precise by default meaning the point must lie exactly on the line. Adjust threshold to loosen the strictness of the check for floating-point calculations.
Parameters
x: number
y: number
optionalthreshold: number
Returns boolean
publicnormal
Gets the normal of the line
Returns Vector
A 2D line segment