Class representing a segment

Hierarchy (view full)

Constructors

  • Parameters

    • Rest...args:
          | []
          | [Point, Point]
          | [number, number, number, number]
          | [[number, number, number, number]]

      Segment may be constructed by two points, or by array of four numbers, or by four numbers

    Returns Segment

Properties

pe: Point = ...

End Point

ps: Point = ...

Start point

Accessors

  • get box(): Box
  • Bounding box

    Returns Box

    bounding box of a segment

  • get end(): Point
  • End point

    Returns Point

    end point

  • get length(): number
  • Length of a segment

    Returns number

    length of a segment

  • get name(): string
  • Shape name

    Returns string

    name of the shape

  • get slope(): number
  • Slope of the line - angle to axe x in radians from 0 to 2PI

    Returns number

    slope in radians from 0 to 2PI

  • get start(): Point
  • Start point

    Returns Point

    start point

  • get vertices(): [Point, Point]
  • Start and end point of the segment

    Returns [Point, Point]

    array of start and end point

Methods

  • Return new cloned instance of segment

    Returns Segment

  • Check if segment contains point

    Parameters

    Returns boolean

    true if segment contains point

  • Calculate definite integral of the segment over y=ymin.

    Parameters

    • ymin: number = 0.0

    Returns number

    definite integral

  • Calculate distance and shortest segment from segment to shape and return as array [distance, shortest segment]

    Parameters

    • shape: Shape<any> | Polygon

      Shape of the one of supported types Point, Line, Circle, Segment, Arc, Polygon or Planar Set

    Returns [number, Segment]

    distance from segment to shape and shortest segment between segment and shape (started at segment, ended at shape)

  • Check if segment is equal to other segment

    Parameters

    Returns boolean

    true if equals to query segment, false otherwise

  • Returns array of intersection points between segment and other shape

    Parameters

    • shape: Shape<any>

      Shape of the one of supported types

    Returns Point[]

  • Check if the segment's length is zero.

    Returns boolean

    true if segment start is equal to segment end up to DP_TOL

  • Get middle point

    Returns Point

    middle point of the segment

  • Get point at given length

    Parameters

    • length: number

      The length along the segment

    Returns Point

    point at given length

  • Reverse segment

    Returns Segment

    new segment with swapped start and end points

  • Rotate shape by given angle around given center point. If center point is omitted, rotates around zero point (0,0). Positive value of angle defines rotation in counterclockwise direction, negative angle defines rotation in clockwise direction

    Parameters

    • angle: number

      angle in radians

    • center: SimplePoint = ...

      center of rotation

    Returns Segment

    new rotated shape

  • Scale shape with coordinates multiplied by scaling factor

    Parameters

    • sx: number

      x-axis scaling factor

    • sy: number

      y-axis scaling factor

    Returns Segment

    new scaled shape

  • Sort given array of points from segment start to end, assuming all points lay on the segment

    Parameters

    • pts: Point[]

      array of points

    Returns Point[]

    new array sorted

  • When point belongs to segment, return array of two segments split by given point, if point is inside segment. Returns clone of this segment if query point is incident to start or end point of the segment. Returns empty array if point does not belong to segment

    Parameters

    Returns [] | [Segment, Segment] | [Segment]

  • Get normalized vector of tagent line on end point

    Returns Vector

    unit vector in the direction from end to start

  • Get normalized vector of tagent line on start point

    Returns Vector

    unit vector in the direction from start to end

  • Return new segment transformed using affine transformation matrix

    Parameters

    • matrix: Matrix = ...

      affine transformation matrix

    Returns Segment

    transformed segment

  • Translated shape by given vector. Translation vector may be also defined by a pair of numbers.

    Parameters

    • Rest...args: [number, number] | [Vector]

      Translation vector or translation by x and y or tuple of numbers

    Returns Segment

    new translated shape