Line

Class representing a line.

Constructor

new Line(a, b)

Create a line between two Vectors.

Parameters:
NameTypeAttributesDefaultDescription
aVector

The startpoint.

bVector

The endpoint.

options.strokestring<optional>
"black"
options.strokeWidthnumber<optional>
0.1

Classes

Line

Methods

intersects(target) → {boolean|Array}

Check if this line intersects another shape. Currently only Line is supported.

Parameters:
NameTypeDescription
targetobject

The target.

Returns:
  • False if lines don't intersect, otherwise returns the intersection point [x,y]
Type: 
boolean | Array

isContainedBy(line) → {boolean}

Check if this line lies directly on top of a longer line.

Parameters:
NameTypeDescription
lineLine

The target line to check against.

Returns:
  • True if this line's startpoint and endpoint are both on the line being checked against, otherwise False.
Type: 
boolean

isDuplicate(line) → {boolean}

Check if this line is the same as another line.

Parameters:
NameTypeDescription
lineLine

The target line to compare to.

Returns:

True if startpoints and endpoints are identical or in reverse.

Type: 
boolean

length() → {number}

Get the length.

Returns:

The distance from the startpoint to the endpoint. Uses the Vector#distance method.

Type: 
number

toSVGElement() → {SVGElement}

Returns:
Type: 
SVGElement

(static) fromArray(array) → {Line}

Create a Line from an array of numbers.

Parameters:
NameTypeDescription
arrayArray.<number>

[x1, y1, x2, y2].

Returns:
Type: 
Line

(static) lineIntersection(line1, line2) → {boolean|Array}

Check if two lines intersect.

Parameters:
NameTypeDescription
line1Line
line2Line
Returns:
  • False if lines don't intersect, otherwise returns the intersection point [x,y]
Type: 
boolean | Array