Aabb
A 3D box: coordinates, extents, point containment and boundary intersections.
A bounding box with faces parallel to the coordinate axes. Position is the starting corner, Size is the full size, and End = Position + Size. This is a C# struct: assignment copies the value; Abs(), Grow(), Expand() and Merge() return a new box.
Keep the box and tested points in the same coordinate system. Transform3D * Aabb produces a new enclosing Aabb; the type itself does not store rotation. Call Abs() first for negative Size. Use HasVolume() for positive extents and IsFinite() for numeric finiteness.
Boundary rules depend on the method: HasPoint() includes End, Intersects() excludes contact alone for ordinary boxes, and Intersection() retains contact regions even with zero thickness. IntersectsPlane() contact depends on the normal direction; see its method description. Aabb has no C# conversion to bool; choose the explicit test your task requires.
using Reckfell;
public static class BoundaryExamples
{
public static bool Validate()
{
var box = new Aabb(Vector3.Zero, new Vector3(2, 2, 2));
var neighbor = new Aabb(new Vector3(2, 0, 0), new Vector3(2, 2, 2));
bool includesEnd = box.HasPoint(box.End); // true
bool overlapsNeighbor = box.Intersects(neighbor); // false
Aabb contact = box.Intersection(neighbor); // position (2,0,0), size (0,2,2)
bool contactHasVolume = contact.HasVolume(); // false
Aabb padded = box.Grow(1); // position (-1,-1,-1), size (4,4,4)
return includesEnd && !overlapsNeighbor && !contactHasVolume
&& contact.Position == new Vector3(2, 0, 0)
&& contact.Size == new Vector3(0, 2, 2)
&& padded.Size == new Vector3(4, 4, 4)
&& box.Size == new Vector3(2, 2, 2); // original unchanged
}
}Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors4
Aabb4 overloads
public Aabb(Vector3 position, Vector3 size);Constructs an Aabb from the starting corner and full size. Coordinates and extents are stored directly; negative components are not corrected. Use default(Aabb) for a zero-size box at the origin.
| Name | Type | Default |
|---|---|---|
position | Vector3 | — |
size | Vector3 | — |
positionStarting corner of the box.
sizeFull size on three axes; use nonnegative components for ordinary bounds operations.
public Aabb(Vector3 position, float width, float height, float depth);Constructs an Aabb from the starting corner and full size. Coordinates and extents are stored directly; negative components are not corrected. Use default(Aabb) for a zero-size box at the origin.
| Name | Type | Default |
|---|---|---|
position | Vector3 | — |
width | float | — |
height | float | — |
depth | float | — |
positionStarting corner of the box.
widthFull X extent, not a half-extent.
heightFull Y extent, not a half-extent.
depthFull Z extent, not a half-extent.
public Aabb(float x, float y, float z, Vector3 size);Constructs an Aabb from the starting corner and full size. Coordinates and extents are stored directly; negative components are not corrected. Use default(Aabb) for a zero-size box at the origin.
| Name | Type | Default |
|---|---|---|
x | float | — |
y | float | — |
z | float | — |
size | Vector3 | — |
xStarting-corner X coordinate.
yStarting-corner Y coordinate.
zStarting-corner Z coordinate.
sizeFull size on three axes; use nonnegative components for ordinary bounds operations.
public Aabb(float x, float y, float z, float width, float height, float depth);Constructs an Aabb from the starting corner and full size. Coordinates and extents are stored directly; negative components are not corrected. Use default(Aabb) for a zero-size box at the origin.
| Name | Type | Default |
|---|---|---|
x | float | — |
y | float | — |
z | float | — |
width | float | — |
height | float | — |
depth | float | — |
xStarting-corner X coordinate.
yStarting-corner Y coordinate.
zStarting-corner Z coordinate.
widthFull X extent, not a half-extent.
heightFull Y extent, not a half-extent.
depthFull Z extent, not a half-extent.
Properties4
EndProperty
public Vector3 End { get; set; }The ending corner: Position + Size. Assignment changes only Size to value - Position, leaving Position unchanged. A value below Position can create negative extents.
PositionProperty
public Vector3 Position { get; set; }The starting corner. Assigning it preserves Size and shifts End by the same amount. Coordinates belong to the chosen reference frame; this is not automatically an object world position.
SizeProperty
public Vector3 Size { get; set; }Full extents along the axes, not half-extents: End = Position + Size. Assignment preserves Position and does not normalize negative components. Use Abs() before bounds tests with negative Size.
VolumeProperty
public float Volume { get; }Computes Size.X * Size.Y * Size.Z without normalization or sign checks. The result can be negative; two negative components produce a positive product. Use HasVolume() to check that all extents are positive.
Methods30
AbsAabb
public Aabb Abs();Returns an equivalent box with nonnegative Size: Position becomes the componentwise minimum of the original Position and End. Zero extents stay zero. Does not modify the original value.
AabbThe normalized box copy.
Enclosesbool
public bool Encloses(Aabb with);Tests complete containment of with on all three axes. Boundaries are included: a box encloses itself and a smaller box touching its faces. Both boxes are expected to have nonnegative Size.
| Name | Type | Default |
|---|---|---|
with | Aabb | — |
withBox in the same coordinate system; call Abs() first if its Size is negative.
booltrue when the other box Position and End lie within this box inclusive bounds.
Equals2 overloads
public bool Equals(Aabb other);Compares every Position and Size component exactly, without tolerance or normalization. Boxes with equivalent geometric bounds but different Position/Size representations are not equal. +0 and -0 compare equal; a NaN component makes comparison with a copy false.
| Name | Type | Default |
|---|---|---|
other | Aabb | — |
otherOther Aabb for exact comparison.
booltrue for exact equality of both box fields.
public override bool Equals(object? obj);For a boxed Aabb, compares every Position and Size component exactly, without tolerance or normalization. Boxes with equivalent geometric bounds but different Position/Size representations are not equal. +0 and -0 compare equal; a NaN component makes comparison with a copy false. Returns false for null or another type.
| Name | Type | Default |
|---|---|---|
obj | object | — |
objObject to compare; null is allowed.
booltrue for exact equality of both box fields.
ExpandAabb
public Aabb Expand(Vector3 point);Returns the smallest copy containing the existing bounds and point. A point inside or on the boundary leaves the result unchanged. Assign the returned value to keep the expansion; the original Aabb is unchanged.
| Name | Type | Default |
|---|---|---|
point | Vector3 | — |
pointPoint in the box coordinate system.
AabbThe expanded box.
GetCenterVector3
public Vector3 GetCenter();Computes Position + Size * 0.5f. Returns center coordinates in the same coordinate system; does not apply an object Transform3D.
Vector3The midpoint of Position and End.
GetEndpointVector3
public Vector3 GetEndpoint(int idx);Returns one of eight corners. Index bit 0 selects End.Z, bit 1 selects End.Y, and bit 2 selects End.X; an unset bit uses that axis Position component. Index 0 returns Position and index 7 returns End. In C#, an index outside 0..7 throws ArgumentOutOfRangeException.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxCorner index from 0 through 7 inclusive.
Vector3Corner coordinates in the box coordinate system.
GetHashCodeint
public override int GetHashCode();Returns HashCode.Combine(Position, Size) for C# hash collections. Exactly equal boxes have equal hashes, but a matching hash does not prove equality. Dictionary<Aabb, T> uses exact Equals(), not IsEqualApprox(). Do not persist this hash as a resource identifier or stable checksum across runs.
intThe hash code of the current Position and Size.
GetLongestAxisVector3
public Vector3 GetLongestAxis();Returns the positive unit vector for the axis with the largest Size component: (1, 0, 0), (0, 1, 0) or (0, 0, 1). Ties prefer X, then Y, then Z. Selection uses raw signed values, not magnitudes; call Abs() first for negative extents. This is a box-coordinate axis, not an object-rotated direction.
Vector3The positive unit vector of the selected axis.
GetLongestAxisIndexVector3.Axis
public Vector3.Axis GetLongestAxisIndex();Selects the largest Size component and returns its Vector3.Axis. Ties prefer X, then Y, then Z. Compares raw signed values, not magnitudes; normalize negative extents with Abs() first.
Vector3.AxisVector3.Axis.X, Vector3.Axis.Y or Vector3.Axis.Z.
GetLongestAxisSizefloat
public float GetLongestAxisSize();Returns the largest Size component without changing its sign. This is the full extent on that axis, not a half-extent or diagonal length. Does not apply an object Transform3D.
floatMaximum of Size.X, Size.Y and Size.Z.
GetShortestAxisVector3
public Vector3 GetShortestAxis();Returns the positive unit vector for the axis with the smallest Size component: (1, 0, 0), (0, 1, 0) or (0, 0, 1). Ties prefer X, then Y, then Z. Selection uses raw signed values, not magnitudes; call Abs() first for negative extents. This is a box-coordinate axis, not an object-rotated direction.
Vector3The positive unit vector of the selected axis.
GetShortestAxisIndexVector3.Axis
public Vector3.Axis GetShortestAxisIndex();Selects the smallest Size component and returns its Vector3.Axis. Ties prefer X, then Y, then Z. Compares raw signed values, not magnitudes; normalize negative extents with Abs() first.
Vector3.AxisVector3.Axis.X, Vector3.Axis.Y or Vector3.Axis.Z.
GetShortestAxisSizefloat
public float GetShortestAxisSize();Returns the smallest Size component without changing its sign. This is the full extent on that axis, not a half-extent or diagonal length. Does not apply an object Transform3D.
floatMinimum of Size.X, Size.Y and Size.Z.
GetSupportVector3
public Vector3 GetSupport(Vector3 dir);Selects a farthest corner along dir for a box with nonnegative Size. A positive direction component selects the corresponding End component; otherwise it selects Position. The direction need not be normalized. Zero components admit tied corners; dir == Vector3.Zero returns Position.
| Name | Type | Default |
|---|---|---|
dir | Vector3 | — |
dirDirection in box coordinates; magnitude does not affect selection when signs stay the same.
Vector3The selected corner coordinates.
GrowAabb
public Aabb Grow(float by);Returns a copy with Position - Vector3.One * by and Size + Vector3.One * (2 * by). Negative by shrinks the box. Shrinking is not clamped: excessive shrinking produces negative Size rather than stopping at zero.
| Name | Type | Default |
|---|---|---|
by | float | — |
byPadding on each of the six sides in box-coordinate units; not the total size increase.
AabbThe new box; the original is unchanged.
HasPointbool
public bool HasPoint(Vector3 point);For finite coordinates: Tests Position <= point <= End on each axis. All six faces, edges and corners are included, including End. Use Abs() first for negative Size. This tests the box coordinates, not the mesh geometry. NaN is not automatically rejected and can make this method return true for the point. Check IsFinite() on the bounds and the input point separately.
| Name | Type | Default |
|---|---|---|
point | Vector3 | — |
pointPoint in the same coordinate system as Position and Size.
booltrue when the point lies inside or on the boundary.
HasSurfacebool
public bool HasSurface();Returns true if at least one Size component is positive. Despite the name, a line with Size = (2, 0, 0) also returns true. Does not compute surface area or validate the other components.
boolSize.X > 0 || Size.Y > 0 || Size.Z > 0.
HasVolumebool
public bool HasVolume();Returns true only when all three Size components are positive. Flat boxes, lines and points return false. Prefer this test to Volume > 0: two negative extents can also produce a positive product.
boolSize.X > 0 && Size.Y > 0 && Size.Z > 0.
IntersectionAabb
public Aabb Intersection(Aabb with);Computes the common box of two boxes with nonnegative Size. Contact is retained: a shared face gives one zero Size component, an edge gives two, and a corner gives three. Disjoint boxes return default(Aabb), the zero box at the origin. A default result alone therefore cannot distinguish separation from contact at the origin.
| Name | Type | Default |
|---|---|---|
with | Aabb | — |
withOther box in the same coordinate system with nonnegative Size.
AabbThe common region, including degenerate contact, or default(Aabb) for separated boxes.
Intersectsbool
public bool Intersects(Aabb with);Compares the intervals on all three axes using strict inequalities. For ordinary positive-size boxes, face-, edge- or corner-only contact returns false. Does not check HasVolume(): a degenerate box strictly inside another can return true. Check HasVolume() separately when both inputs must have nonzero volume.
| Name | Type | Default |
|---|---|---|
with | Aabb | — |
withOther box in the same coordinate system. Normalize negative Size with Abs() before testing.
booltrue when no axis satisfies separation or equality of the opposite boundaries.
IntersectsPlanebool
public bool IntersectsPlane(Plane plane);Tests the distances of all eight corners to plane. Returns true when at least one corner has DistanceTo > 0 and another has DistanceTo <= 0. This is an ordinary plane-box test for strict crossings. For contact alone, reversing the normal can change the result: zero distance belongs only to the nonpositive side. Do not use it as a symmetric tolerance-based contact test.
| Name | Type | Default |
|---|---|---|
plane | Plane | — |
planePlane in box coordinates. The method adds no tolerance to DistanceTo.
booltrue when corners occur in both distance groups described above.
IntersectsSegmentbool
public bool IntersectsSegment(Vector3 from, Vector3 to);Tests the finite segment from from to to, including both endpoints and the box boundary. Face contact counts as intersection. If from == to, the result is point containment. Expects nonnegative Size. Returns only bool, without a hit position, normal or distance.
| Name | Type | Default |
|---|---|---|
from | Vector3 | — |
to | Vector3 | — |
fromSegment start in box coordinates.
toSegment endpoint, not a direction vector.
booltrue when at least one point of the finite segment belongs to the box.
IsEqualApproxbool
public bool IsEqualApprox(Aabb other);Compares Position and Size componentwise using Mathf.IsEqualApprox(). In the current float SDK, exact equality succeeds immediately; otherwise abs(a - b) < max(0.000001, 0.000001 * abs(a)) is required, where a is this box component. Tolerance is not an argument and grows with the first value. Operand order can change the result at the tolerance boundary; the test is also not transitive. Do not use it as Dictionary key equality or a finiteness test: equal infinities pass exact equality, but NaN does not.
| Name | Type | Default |
|---|---|---|
other | Aabb | — |
otherBox to compare; its components are the second operands in the tolerance checks.
booltrue when all six component comparisons pass.
IsFinitebool
public bool IsFinite();Checks all six Position and Size components for NaN and infinity. Negative or zero Size alone still returns true: this validates numeric finiteness, not suitability for a particular algorithm.
booltrue when all Position and Size components are finite.
MergeAabb
public Aabb Merge(Aabb with);Returns the smallest Aabb containing both input boxes. This is an enclosing rectangular volume: any empty space between separated boxes is also included. Both inputs must use the same coordinate system and nonnegative Size. Neither input is changed.
| Name | Type | Default |
|---|---|---|
with | Aabb | — |
withBox whose bounds must also be included.
AabbThe new enclosing box.
ToString2 overloads
public override string ToString();Builds Position.ToString(format) + ", " + Size.ToString(format): for example, (1.25, -2.5, 3), (1, 1, 1). Coordinates use InvariantCulture: the decimal point is independent of the system language. This is diagnostic text, not JSON or a save-game format. Equivalent to ToString(null).
stringText containing Position and Size coordinates.
public string ToString(string? format);Builds Position.ToString(format) + ", " + Size.ToString(format): for example, (1.25, -2.5, 3), (1, 1, 1). Coordinates use InvariantCulture: the decimal point is independent of the system language. This is diagnostic text, not JSON or a save-game format. The format applies to all six numbers; F2 rounds display to two decimal places without changing the box. An unsupported numeric format can throw FormatException.
| Name | Type | Default |
|---|---|---|
format | string | — |
formatA .NET numeric format such as "F2". null selects the default format.
stringText containing Position and Size coordinates.
op_Equalitybool
public static bool operator ==(Aabb left, Aabb right);Uses the exact Equals(right) comparison. Compares Position and Size components without tolerance, Abs() or an overlap test. +0 and -0 are equal. With a NaN component, equality with a copy is false and inequality is true.
| Name | Type | Default |
|---|---|---|
left | Aabb | — |
right | Aabb | — |
leftLeft box.
rightRight box.
booltrue for exact equality.
op_Inequalitybool
public static bool operator !=(Aabb left, Aabb right);Negates the exact Equals(right) comparison. Compares Position and Size components without tolerance, Abs() or an overlap test. +0 and -0 are equal. With a NaN component, equality with a copy is false and inequality is true.
| Name | Type | Default |
|---|---|---|
left | Aabb | — |
right | Aabb | — |
leftLeft box.
rightRight box.
booltrue for inequality.