Segment
public abstract class Segment
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 |
final @NonNull MutableBox |
computeBoundingBox(@NonNull MutableBox outBox)Populates |
final @NonNull ImmutableVec |
Returns an ImmutableVec with the displacement from start to end. |
final @NonNull MutableVec |
computeDisplacement(@NonNull MutableVec outVec)Populates |
final @FloatRange(from = 0.0) float |
The length of the |
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 |
final @NonNull ImmutableVec |
Returns an |
final @NonNull MutableVec |
computeMidpoint(@NonNull MutableVec outVec)Populates |
abstract @NonNull Vec |
getEnd() |
abstract @NonNull Vec |
getStart() |
final boolean |
isAlmostEqual(Compares this |
final float |
Returns the multiple of the segment's length at which the infinite extrapolation of this segment is closest to |
Public methods
computeBoundingBox
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
public final @NonNull MutableBox computeBoundingBox(@NonNull MutableBox outBox)
Populates outBox with the minimum bounding box containing the Segment.
computeDisplacement
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
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
public final @FloatRange(from = 0.0) float computeLength()
The length of the Segment.
computeLerpPoint
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
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
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
public final @NonNull MutableVec computeMidpoint(@NonNull MutableVec outVec)
Populates outVec with the point halfway along the segment.
isAlmostEqual
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
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.