Class: Segment

Segment

A segment, represented by its two points.

Constructor

new Segment(a:, b:)

Constructs a segment from point a to point b.
Parameters:
Name Type Description
a: Point
b: Point != a
Source:

Members

a

Returns the first point.
Source:

b

Returns the second point.
Source:

Methods

compare(other) → {number}

Compare two segments before with min points and maybe after with max points.
Parameters:
Name Type Description
other Segment
Source:
Returns:
-1, 0 or 1
Type
number

isCommonEndPoint()

Returns true iff have at leat one common endpoint.
Source:

isEquals(other) → {boolean}

Returns true iff the segment is equals to the segment other, namely iff they are same points (regardless of the order).
Parameters:
Name Type Description
other Segment
Source:
Returns:
Type
boolean

isExtremityPoint(point) → {boolean}

Returns true iff point is an extremity point of the segment.
Parameters:
Name Type Description
point Point
Source:
Returns:
Type
boolean

isHorizontal() → {boolean}

Returns true iff is a horizontal segment
Source:
Returns:
Type
boolean

isIn(p) → {boolean}

Returns true iff p is in the segment (inclusive its extremities).
Parameters:
Name Type Description
p Point
Source:
Returns:
Type
boolean

isInSameLine(p) → {boolean}

Returns true iff p is in the same line that the segment.
Parameters:
Name Type Description
p Point
Source:
Returns:
Type
boolean

isIntersect(other) → {boolean}

Returns true iff two segments intersect.
Parameters:
Name Type Description
other Segment
Source:
Returns:
Type
boolean

isProperIn(p) → {boolean}

Returns true iff p is in the segment (exclusive its extremities).
Parameters:
Name Type Description
p Point
Source:
Returns:
Type
boolean

isProperIntersect(other) → {boolean}

Returns true iff two segments intersect without their endpoints.
Parameters:
Name Type Description
other Segment
Source:
Returns:
Type
boolean

isProperIntersectWithHorizontalLine()

Returns true iff the horizontal line of vertical coordonate y (strictically) intersect the segment.
Source:

isVertical() → {boolean}

Returns true iff is a vertical segment
Source:
Returns:
Type
boolean

ordonned() → {Segment}

If segment.a <= segment.b then return this, else return a new segment with points swapped.
Source:
Returns:
Type
Segment

slope() → {number|null}

Returns the slope of the segment. If the segment is vertical, then return null.
Source:
Returns:
Type
number | null

toString() → {String}

Returns a string representation of the segment. Each number is represented with at most precision figures after the decimal point.
Source:
Returns:
Type
String

yOnLine(x) → {number|null}

Returns the y coordinate for the given x coordinate. If the segment is vertical, then return null.
Parameters:
Name Type Description
x number
Source:
Returns:
Type
number | null