npm install line2
or include it in a script tag in the browser
var Line = ;var l = 0 0 10 10;console; // 1 0 0
Line2(x1, y1, x2, y2) or Line2(slope, yIntercept)
returns a new
add an observer that will be notified of any change.
Removes a listener, if no
fn is passed remove them all.
Call all of the listeners, manually.
return the computed y-intercept or
null if verical
y is passed it will set the y-intercept of this line and the x-intercept if appropriate (not horizontal)
return the computed x-intercept or
null if horizontal
x is passed it will set the x-intercept of this line and the y-intercept if appropriate (not vertical)
return the computed slope.
slope is passed it will set the slope of this line
note: this will be
Infinity if the line is vertical
intersectSegment(x1, y1, x2, y2)
truewhen the segment is colinear with this line
falsewhen the segment does not intersect with this line
Vec2representing where the point of interesection
returns a new line instance that is perpendicular to this line and goes through the provided point
returns an array of
Vec2s which represent the intersections.
a length of:
0means no intersections
1means the line is tangent to the provided circle
2means the line fully intersects
x coordinate using the provided
y coordinate using the provided
intersect(line2) or intersect(x1, y1, x2, y2)
Vec2 representing the point of intersection if there was one.
If the lines are colinear, it returns
If there is no intersection, it returns
returns the a
Vec2 representing the closest point on this line to the provided vec2
returns true if the provided vec2 is on this line
MIT (see: license.txt)