Skip to main content

LineSegment

A 2D line segment

Index

Constructors

constructor

  • Parameters

    • begin: Vector

      The starting point of the line segment

    • end: Vector

      The ending point of the line segment

    Returns LineSegment

Properties

publicbegin

begin: Vector

The starting point of the line segment

publicend

end: Vector

The ending point of the line segment

Accessors

publicintercept

  • get intercept(): number
  • 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

  • get slope(): number
  • 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

    Returns boolean

publicclip

  • Returns the clip point


    Parameters

    • sideVector: Vector

      Vector that traces the line

    • length: number

      Length to clip along side

    • normalize: boolean = true

    Returns LineSegment

clone

publicdir

publicdistanceToPoint

  • distanceToPoint(point: Vector, signed?: boolean): number

publicfindPoint

  • findPoint(x?: number, y?: number): Vector
  • 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

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

  • getLength(): number
  • Returns the length of the line segment in pixels


    Returns number

publicgetPoints

publicgetSlope

  • Returns the slope of the line in the form of a vector of length 1


    Returns Vector

publichasPoint

  • hasPoint(x: number, y: number, threshold?: number): boolean
  • hasPoint(v: Vector, threshold?: number): 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

    • x: number
    • y: number
    • optionalthreshold: number

    Returns boolean

publicnormal

  • Gets the normal of the line


    Returns Vector

transform