Represents a line segment. A LineSegment2 is immutable.

Hierarchy (view full)

Constructors

Properties

bbox: Rect2

The bounding box of this line segment.

direction: Vec3

The unit direction vector of this line segment, from point1 to point2.

In other words, direction is point2.minus(point1).normalized() (perhaps except when point1 is equal to point2).

length: number

The distance between point1 and point2.

Accessors

Methods

  • Returns true if and only if the given point is contained within this shape.

    epsilon is a small number used to counteract floating point error. Thus, if point is within epsilon of the inside of this shape, containsPoint may also return true.

    The default implementation relies on signedDistance. Subclasses may override this method to provide a more efficient implementation.

    Parameters

    • point: Vec3
    • epsilon: number = Abstract2DShape.smallValue

    Returns boolean

  • Returns true iff this is equivalent to other.

    Options:

    • tolerance: The maximum difference between endpoints. (Default: 0)
    • ignoreDirection: Allow matching a version of this with opposite direction. (Default: true)

    Parameters

    • other: LineSegment2
    • Optional options: {
          ignoreDirection?: boolean;
          tolerance?: number;
      }
      • Optional ignoreDirection?: boolean
      • Optional tolerance?: number

    Returns boolean

  • Returns the distance from this line segment to target.

    Because a line segment has no interior, this signed distance is equivalent to the full distance between target and this line segment.

    Parameters

    Returns number

  • Returns the smallest line segment that contains all points in points, or null if no such line segment exists.

    Parameters

    • points: readonly Vec3[]

    Returns null | LineSegment2

    Example

    import {LineSegment2, Vec2} from '@js-draw/math';
    console.log(LineSegment2.ofSmallestContainingPoints([Vec2.of(1, 0), Vec2.of(0, 1)]));
    

Generated using TypeDoc

OpenSource licenses