reckfellENGINE

Aabb

A 3D box: coordinates, extents, point containment and boundary intersections.

On this page
struct AabbReckfellSharpInherits ValueType

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.

C#
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
# Aabb · 1/4
C#
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.

Parameters
NameTypeDefault
positionVector3—
sizeVector3—
position

Starting corner of the box.

size

Full size on three axes; use nonnegative components for ordinary bounds operations.

# Aabb · 2/4
C#
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.

Parameters
NameTypeDefault
positionVector3—
widthfloat—
heightfloat—
depthfloat—
position

Starting corner of the box.

width

Full X extent, not a half-extent.

height

Full Y extent, not a half-extent.

depth

Full Z extent, not a half-extent.

# Aabb · 3/4
C#
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.

Parameters
NameTypeDefault
xfloat—
yfloat—
zfloat—
sizeVector3—
x

Starting-corner X coordinate.

y

Starting-corner Y coordinate.

z

Starting-corner Z coordinate.

size

Full size on three axes; use nonnegative components for ordinary bounds operations.

# Aabb · 4/4
C#
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.

Parameters
NameTypeDefault
xfloat—
yfloat—
zfloat—
widthfloat—
heightfloat—
depthfloat—
x

Starting-corner X coordinate.

y

Starting-corner Y coordinate.

z

Starting-corner Z coordinate.

width

Full X extent, not a half-extent.

height

Full Y extent, not a half-extent.

depth

Full Z extent, not a half-extent.

Properties4

EndProperty
# End
C#
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
# Position
C#
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
# Size
C#
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
# Volume
C#
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
# Abs
C#
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.

Returns Aabb

The normalized box copy.

Enclosesbool
# Encloses
C#
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.

Parameters
NameTypeDefault
withAabb—
with

Box in the same coordinate system; call Abs() first if its Size is negative.

Returns bool

true when the other box Position and End lie within this box inclusive bounds.

Equals2 overloads
# Equals · 1/2
C#
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.

Parameters
NameTypeDefault
otherAabb—
other

Other Aabb for exact comparison.

Returns bool

true for exact equality of both box fields.

# Equals · 2/2
C#
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.

Parameters
NameTypeDefault
objobject—
obj

Object to compare; null is allowed.

Returns bool

true for exact equality of both box fields.

ExpandAabb
# Expand
C#
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.

Parameters
NameTypeDefault
pointVector3—
point

Point in the box coordinate system.

Returns Aabb

The expanded box.

GetCenterVector3
# GetCenter
C#
public Vector3 GetCenter();

Computes Position + Size * 0.5f. Returns center coordinates in the same coordinate system; does not apply an object Transform3D.

Returns Vector3

The midpoint of Position and End.

GetEndpointVector3
# GetEndpoint
C#
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.

Parameters
NameTypeDefault
idxint—
idx

Corner index from 0 through 7 inclusive.

Returns Vector3

Corner coordinates in the box coordinate system.

GetHashCodeint
# GetHashCode
C#
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.

Returns int

The hash code of the current Position and Size.

GetLongestAxisVector3
# GetLongestAxis
C#
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.

Returns Vector3

The positive unit vector of the selected axis.

GetLongestAxisIndexVector3.Axis
# GetLongestAxisIndex
C#
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.

Returns Vector3.Axis

Vector3.Axis.X, Vector3.Axis.Y or Vector3.Axis.Z.

GetLongestAxisSizefloat
# GetLongestAxisSize
C#
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.

Returns float

Maximum of Size.X, Size.Y and Size.Z.

GetShortestAxisVector3
# GetShortestAxis
C#
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.

Returns Vector3

The positive unit vector of the selected axis.

GetShortestAxisIndexVector3.Axis
# GetShortestAxisIndex
C#
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.

Returns Vector3.Axis

Vector3.Axis.X, Vector3.Axis.Y or Vector3.Axis.Z.

GetShortestAxisSizefloat
# GetShortestAxisSize
C#
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.

Returns float

Minimum of Size.X, Size.Y and Size.Z.

GetSupportVector3
# GetSupport
C#
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.

Parameters
NameTypeDefault
dirVector3—
dir

Direction in box coordinates; magnitude does not affect selection when signs stay the same.

Returns Vector3

The selected corner coordinates.

GrowAabb
# Grow
C#
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.

Parameters
NameTypeDefault
byfloat—
by

Padding on each of the six sides in box-coordinate units; not the total size increase.

Returns Aabb

The new box; the original is unchanged.

HasPointbool
# HasPoint
C#
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.

Parameters
NameTypeDefault
pointVector3—
point

Point in the same coordinate system as Position and Size.

Returns bool

true when the point lies inside or on the boundary.

HasSurfacebool
# HasSurface
C#
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.

Returns bool

Size.X > 0 || Size.Y > 0 || Size.Z > 0.

HasVolumebool
# HasVolume
C#
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.

Returns bool

Size.X > 0 && Size.Y > 0 && Size.Z > 0.

IntersectionAabb
# Intersection
C#
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.

Parameters
NameTypeDefault
withAabb—
with

Other box in the same coordinate system with nonnegative Size.

Returns Aabb

The common region, including degenerate contact, or default(Aabb) for separated boxes.

Intersectsbool
# Intersects
C#
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.

Parameters
NameTypeDefault
withAabb—
with

Other box in the same coordinate system. Normalize negative Size with Abs() before testing.

Returns bool

true when no axis satisfies separation or equality of the opposite boundaries.

IntersectsPlanebool
# IntersectsPlane
C#
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.

Parameters
NameTypeDefault
planePlane—
plane

Plane in box coordinates. The method adds no tolerance to DistanceTo.

Returns bool

true when corners occur in both distance groups described above.

IntersectsSegmentbool
# IntersectsSegment
C#
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.

Parameters
NameTypeDefault
fromVector3—
toVector3—
from

Segment start in box coordinates.

to

Segment endpoint, not a direction vector.

Returns bool

true when at least one point of the finite segment belongs to the box.

IsEqualApproxbool
# IsEqualApprox
C#
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.

Parameters
NameTypeDefault
otherAabb—
other

Box to compare; its components are the second operands in the tolerance checks.

Returns bool

true when all six component comparisons pass.

IsFinitebool
# IsFinite
C#
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.

Returns bool

true when all Position and Size components are finite.

MergeAabb
# Merge
C#
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.

Parameters
NameTypeDefault
withAabb—
with

Box whose bounds must also be included.

Returns Aabb

The new enclosing box.

ToString2 overloads
# ToString · 1/2
C#
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).

Returns string

Text containing Position and Size coordinates.

# ToString · 2/2
C#
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.

Parameters
NameTypeDefault
formatstring—
format

A .NET numeric format such as "F2". null selects the default format.

Returns string

Text containing Position and Size coordinates.

op_Equalitybool
# op_Equality
C#
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.

Parameters
NameTypeDefault
leftAabb—
rightAabb—
left

Left box.

right

Right box.

Returns bool

true for exact equality.

op_Inequalitybool
# op_Inequality
C#
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.

Parameters
NameTypeDefault
leftAabb—
rightAabb—
left

Left box.

right

Right box.

Returns bool

true for inequality.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.