Box
public abstract class Box
ImmutableBox |
An immutable axis-aligned rectangle. |
MutableBox |
A mutable axis-aligned rectangle. |
Represents an axis-aligned rectangle. See ImmutableBox and MutableBox for concrete classes implementing Box.
The Box interface is the read-only view of the underlying data which may or may not be mutable.
Summary
Public methods |
|
|---|---|
final @NonNull ImmutableVec |
Returns the center of the |
final @NonNull MutableVec |
computeCenter(@NonNull MutableVec outVec)Populates |
final @NonNull List<@NonNull ImmutableVec> |
Returns a list containing the 4 corners of the |
final void |
computeCorners(Populates the 4 output points with the corners of the |
final boolean |
Returns whether the other Box is contained within this Box. |
final boolean |
Returns whether the given point is contained within the Box. |
final @FloatRange(from = 0.0) float |
The height of the rectangle. |
final @FloatRange(from = 0.0) float |
getWidth()The width of the rectangle. |
abstract float |
getXMax()The upper bound in the |
abstract float |
getXMin()The lower bound in the |
abstract float |
getYMax()The upper bound in the |
abstract float |
getYMin()The lower bound in the |
final boolean |
isAlmostEqual(@NonNull Box other, @FloatRange(from = 0.0) float tolerance)Compares this |
Extension functions |
|
|---|---|
final @NonNull RectF |
AndroidGraphicsConverter.populateRectF( |
final @NonNull RectF |
AndroidGraphicsConverter.toRectF(@NonNull Box receiver)Constructs a Rect with the same coordinates as the |
Public methods
computeCenter
public final @NonNull ImmutableVec computeCenter()
Returns the center of the Box.
Performance-sensitive code should use the computeCenter overload that takes a pre-allocated MutableVec, so that instance can be reused across multiple calls.
computeCenter
public final @NonNull MutableVec computeCenter(@NonNull MutableVec outVec)
Populates outVec with the center of the Box, and returns outVec.
computeCorners
public final @NonNull List<@NonNull ImmutableVec> computeCorners()
Returns a list containing the 4 corners of the Box. The order of the corners is: (x_min, y_min), (x_max, y_min), (x_max, y_max), (x_min, y_max).
computeCorners
public final void computeCorners(
@NonNull MutableVec outVecXMinYMin,
@NonNull MutableVec outVecXMaxYMin,
@NonNull MutableVec outVecXMaxYMax,
@NonNull MutableVec outVecXMinYMax
)
Populates the 4 output points with the corners of the Box. The order of the corners is: (x_min, y_min), (x_max, y_min), (x_max, y_max), (x_min, y_max)
contains
public final boolean contains(@NonNull Box otherBox)
Returns whether the other Box is contained within this Box. Edges of the other Box that overlap with this one's boundary are considered to be contained.
contains
public final boolean contains(@NonNull Vec point)
Returns whether the given point is contained within the Box. Points that lie exactly on the Box's boundary are considered to be contained.
getHeight
public final @FloatRange(from = 0.0) float getHeight()
The height of the rectangle. This can never be negative.
getWidth
public final @FloatRange(from = 0.0) float getWidth()
The width of the rectangle. This can never be negative.
isAlmostEqual
public final boolean isAlmostEqual(@NonNull Box other, @FloatRange(from = 0.0) float tolerance)
Compares this Box with other, and returns true if the difference between xMin and other.xMin is less than tolerance, and likewise for xMax, yMin, and yMax.
Extension functions
AndroidGraphicsConverter.populateRectF
public final @NonNull RectF AndroidGraphicsConverter.populateRectF(
@NonNull Box receiver,
@NonNull RectF out
)
Writes the values from this Box to out.
Returns the modified RectF instance to allow chaining calls.
AndroidGraphicsConverter.toRectF
public final @NonNull RectF AndroidGraphicsConverter.toRectF(@NonNull Box receiver)
Constructs a Rect with the same coordinates as the Box