A 2D line segment

Hierarchy

  • LineSegment

Constructors

Properties

begin: Vector

The starting point of the line segment

end: Vector

The ending point of the line segment

Accessors

  • get intercept(): number
  • Gets the Y-intercept (b) of the line. Will return (+/-)Infinity if there is no intercept.

    Returns number

  • get slope(): number
  • Gets the raw slope (m) of the line. Will return (+/-)Infinity for vertical lines.

    Returns number

Methods

  • Tests if a given point is below the line, points in the normal direction above the line are considered above.

    Parameters

    Returns boolean

  • 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.

    Returns

    A new point with the other calculated axis value

    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

  • Returns the length of the line segment in pixels

    Returns number

  • 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
    • Optional threshold: number

    Returns boolean

  • 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

    • v: Vector
    • Optional threshold: number

    Returns boolean