Struct TreeBox
Represents an axis-aligned bounding box with SIMD-friendly memory layout, used for spatial partitioning in acceleration structures such as DynamicTree.
public struct TreeBox : IEquatable<TreeBox>
- Implements
- Inherited Members
Remarks
The struct is explicitly laid out to occupy exactly 8 float fields, enabling efficient SIMD operations and
binary comparisons. It contains both minimum and maximum corners of the box as JVector, along with
unused W components (MinW, MaxW) to match memory alignment.
Constructors
TreeBox(in JBoundingBox)
Creates a new TreeBox from an existing JBoundingBox.
public TreeBox(in JBoundingBox box)
Parameters
boxJBoundingBox
TreeBox(in JVector, in JVector)
Creates a new TreeBox from minimum and maximum corner vectors.
public TreeBox(in JVector min, in JVector max)
Parameters
Fields
Epsilon
Small epsilon value used for ray-box intersection tests.
public const float Epsilon = 1E-12
Field Value
Max
The maximum corner of the bounding box.
public JVector Max
Field Value
MaxW
Padding for SIMD alignment. Not used directly.
public float MaxW
Field Value
Min
The minimum corner of the bounding box.
public JVector Min
Field Value
MinW
Padding for SIMD alignment. Not used directly.
public float MinW
Field Value
Properties
Center
Gets the center point of the bounding box.
public readonly JVector Center { get; }
Property Value
VectorMax
Returns a Vector128<T> view of the Max vector, reinterpreted as a SIMD vector for efficient processing. This enables vectorized operations on the bounding box's maximum corner.
public readonly ref Vector128<float> VectorMax { get; }
Property Value
VectorMin
Returns a Vector128<T> view of the Min vector, reinterpreted as a SIMD vector for efficient processing. This enables vectorized operations on the bounding box's minimum corner.
public readonly ref Vector128<float> VectorMin { get; }
Property Value
Methods
AsJBoundingBox()
Converts this TreeBox to a JBoundingBox.
public readonly JBoundingBox AsJBoundingBox()
Returns
Contains(in TreeBox)
Determines whether this box completely encloses the specified TreeBox.
public readonly bool Contains(in TreeBox box)
Parameters
boxTreeBoxThe box to check for containment.
Returns
- bool
trueif theboxis entirely inside this box.
Contains(in TreeBox, in TreeBox)
Determines whether the outer box completely contains the inner box using SIMD instructions.
public static bool Contains(in TreeBox outer, in TreeBox inner)
Parameters
Returns
- bool
trueifinneris fully insideouter.
Contains(in JBoundingBox)
Determines whether this box completely encloses the specified box.
public readonly bool Contains(in JBoundingBox box)
Parameters
boxJBoundingBoxThe box to check for containment.
Returns
- bool
trueif theboxis entirely inside this box; otherwise,false.
Contains(in JVector)
Determines whether this box contains the specified point.
public readonly bool Contains(in JVector point)
Parameters
pointJVectorThe point to check.
Returns
- bool
trueif the point is within the boundaries of this box; otherwise,false.
CreateMerged(in TreeBox, in TreeBox, out TreeBox)
Creates a new box that encompasses both input boxes.
public static void CreateMerged(in TreeBox first, in TreeBox second, out TreeBox result)
Parameters
Disjoint(in TreeBox)
Determines whether this box is completely separated from the specified TreeBox.
public readonly bool Disjoint(in TreeBox box)
Parameters
boxTreeBoxThe box to check against.
Returns
- bool
trueif the boxes do not overlap;falseif they touch or overlap.
Disjoint(in TreeBox, in TreeBox)
Determines whether two boxes are completely separated (disjoint) using SIMD instructions.
public static bool Disjoint(in TreeBox first, in TreeBox second)
Parameters
Returns
- bool
trueif the boxes do not overlap on any axis;falseif they touch or intersect.
Disjoint(in JBoundingBox)
Determines whether this box is completely separated from (does not overlap) the specified box.
public readonly bool Disjoint(in JBoundingBox box)
Parameters
boxJBoundingBoxThe box to check against.
Returns
- bool
trueif the boxes are separated by a gap on at least one axis; otherwise,false.
Encompasses(in JBoundingBox)
Determines whether this box completely encloses the specified box.
[Obsolete("Use Contains instead.")]
public readonly bool Encompasses(in JBoundingBox box)
Parameters
boxJBoundingBox
Returns
Remarks
This is an alias for Contains(in JBoundingBox).
Equals(TreeBox)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(TreeBox other)
Parameters
otherTreeBoxAn object to compare with this object.
Returns
Equals(in TreeBox, in TreeBox)
Determines whether two boxes are equal using binary comparison.
public static bool Equals(in TreeBox first, in TreeBox second)
Parameters
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetSurfaceArea()
Calculates the surface area of the bounding box.
public readonly double GetSurfaceArea()
Returns
- double
The total surface area (\(2(xy + yz + zx)\)).
MergedSurface(in TreeBox, in TreeBox)
Calculates the surface area of a hypothetical box that would result from merging the two specified boxes.
public static double MergedSurface(in TreeBox first, in TreeBox second)
Parameters
Returns
- double
The surface area of the union box. Used for SAH (Surface Area Heuristic) costs.
NotDisjoint(in TreeBox, in TreeBox)
Determines whether two boxes overlap using SIMD instructions.
[Obsolete("Use !Disjoint instead.")]
public static bool NotDisjoint(in TreeBox first, in TreeBox second)
Parameters
Returns
- bool
trueif the boxes intersect;falseif they are disjoint.
NotDisjoint(in JBoundingBox)
Determines whether this box intersects with or overlaps the specified box.
[Obsolete("Use !Disjoint instead.")]
public readonly bool NotDisjoint(in JBoundingBox box)
Parameters
boxJBoundingBoxThe box to check against.
Returns
- bool
trueif the boxes overlap;falseif they are completely separated.
RayIntersect(in JVector, in JVector)
Checks if an infinite ray intersects this bounding box.
public readonly bool RayIntersect(in JVector origin, in JVector direction)
Parameters
originJVectorThe origin of the ray.
directionJVectorThe direction of the ray (not necessarily normalized).
Returns
- bool
trueif the ray intersects the box; otherwise,false.
RayIntersect(in JVector, in JVector, out float)
Checks if an infinite ray intersects this bounding box and calculates the entry distance.
public readonly bool RayIntersect(in JVector origin, in JVector direction, out float enter)
Parameters
originJVectorThe origin of the ray.
directionJVectorThe direction of the ray (not necessarily normalized).
enterfloatOutputs the scalar distance along the direction vector where the ray enters the box. If inside, this is 0.
Returns
- bool
trueif the ray intersects the box; otherwise,false.
SegmentIntersect(in JVector, in JVector)
Checks if a finite line segment intersects this bounding box.
public readonly bool SegmentIntersect(in JVector origin, in JVector direction)
Parameters
originJVectorThe start point of the segment.
directionJVectorThe vector defining the direction and length of the segment (End Point = Origin + Direction).
Returns
- bool
trueif the segment passes through the box; otherwise,false.
ToString()
Returns the fully qualified type name of this instance.
public override readonly string ToString()
Returns
- string
The fully qualified type name.
Operators
operator ==(TreeBox, TreeBox)
public static bool operator ==(TreeBox left, TreeBox right)
Parameters
Returns
operator !=(TreeBox, TreeBox)
public static bool operator !=(TreeBox left, TreeBox right)