public abstract class Segment

Known direct subclasses
ImmutableSegment

Represents a directed line segment between two points.

MutableSegment

Represents a mutable directed line segment between two points.


Represents a directed line segment between two points.

Summary

Public methods

final @NonNull ImmutableBox

Returns the minimum bounding box containing the Segment.

final @NonNull MutableBox

Populates outBox with the minimum bounding box containing the Segment.

final @NonNull ImmutableVec

Returns an ImmutableVec with the displacement from start to end.

final @NonNull MutableVec

Populates outVec with the displacement from start to end.

final @FloatRange(from = 0.0) float

The length of the Segment.

final @NonNull ImmutableVec
computeLerpPoint(float ratio)

Returns the point on the segment at the given ratio of the segment's length, measured from the start point.

final @NonNull MutableVec
computeLerpPoint(float ratio, @NonNull MutableVec outVec)

Fills outVec with the point on the segment at the given ratio of the segment's length, measured from the start point.

final @NonNull ImmutableVec

Returns an ImmutableVec that lies halfway along the segment.

final @NonNull MutableVec

Populates outVec with the point halfway along the segment.

abstract @NonNull Vec
abstract @NonNull Vec
final boolean
isAlmostEqual(
    @NonNull Segment other,
    @FloatRange(from = 0.0) float tolerance
)

Compares this Segment with other, and returns true if both start points are considered almost equal with the given tolerance, and likewise for both end points.

final float
project(@NonNull Vec pointToProject)

Returns the multiple of the segment's length at which the infinite extrapolation of this segment is closest to pointToProject.

Public methods

computeBoundingBox

Added in 1.0.0-alpha01
public final @NonNull ImmutableBox computeBoundingBox()

Returns the minimum bounding box containing the Segment.

For performance-sensitive code, prefer to use computeBoundingBox with a pre-allocated instance of MutableBox.

computeBoundingBox

Added in 1.0.0-alpha01
public final @NonNull MutableBox computeBoundingBox(@NonNull MutableBox outBox)

Populates outBox with the minimum bounding box containing the Segment.

computeDisplacement

Added in 1.0.0-alpha01
public final @NonNull ImmutableVec computeDisplacement()

Returns an ImmutableVec with the displacement from start to end. This is equivalent to subtract(end, start, output).

For performance-sensitive code, prefer to use computeDisplacement with a pre-allocated instance of MutableVec.

computeDisplacement

Added in 1.0.0-alpha01
public final @NonNull MutableVec computeDisplacement(@NonNull MutableVec outVec)

Populates outVec with the displacement from start to end. This is equivalent to subtract(end, start, output). Returns outVec.

computeLength

Added in 1.0.0-alpha01
public final @FloatRange(from = 0.0) float computeLength()

The length of the Segment.

computeLerpPoint

Added in 1.0.0-alpha01
public final @NonNull ImmutableVec computeLerpPoint(float ratio)

Returns the point on the segment at the given ratio of the segment's length, measured from the start point. You may also think of this as linearly interpolating from the start of the segment to the end. Values outside the interval 0, 1 will be extrapolated along the infinite line passing through this segment. This is the inverse of project.

For performance-sensitive code, prefer to use computeLerpPoint with a pre-allocated instance of MutableVec.

computeLerpPoint

Added in 1.0.0-alpha01
public final @NonNull MutableVec computeLerpPoint(float ratio, @NonNull MutableVec outVec)

Fills outVec with the point on the segment at the given ratio of the segment's length, measured from the start point. You may also think of this as linearly interpolating from the start of the segment to the end. Values outside the interval 0, 1 will be extrapolated along the infinite line passing through this segment. This is the inverse of project.

computeMidpoint

Added in 1.0.0-alpha01
public final @NonNull ImmutableVec computeMidpoint()

Returns an ImmutableVec that lies halfway along the segment.

For performance-sensitive code, prefer to use computeMidpoint with a pre-allocated instance of MutableVec.

computeMidpoint

Added in 1.0.0-alpha01
public final @NonNull MutableVec computeMidpoint(@NonNull MutableVec outVec)

Populates outVec with the point halfway along the segment.

getEnd

Added in 1.0.0-alpha01
public abstract @NonNull Vec getEnd()

getStart

Added in 1.0.0-alpha01
public abstract @NonNull Vec getStart()

isAlmostEqual

Added in 1.0.0-alpha01
public final boolean isAlmostEqual(
    @NonNull Segment other,
    @FloatRange(from = 0.0) float tolerance
)

Compares this Segment with other, and returns true if both start points are considered almost equal with the given tolerance, and likewise for both end points.

project

Added in 1.0.0-alpha01
public final float project(@NonNull Vec pointToProject)

Returns the multiple of the segment's length at which the infinite extrapolation of this segment is closest to pointToProject. This is the inverse of computeLerpPoint. If the computeLength of this segment is zero, then the projection is undefined and this will throw an error. Note that the computeLength may be zero even if start and end are not equal, if they are sufficiently close that floating-point underflow occurs.