Table of Contents

Struct TreeBox

Namespace
Jitter2.Collision
Assembly
Jitter2.dll

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

box JBoundingBox

TreeBox(in JVector, in JVector)

Creates a new TreeBox from minimum and maximum corner vectors.

public TreeBox(in JVector min, in JVector max)

Parameters

min JVector
max JVector

Fields

Epsilon

Small epsilon value used for ray-box intersection tests.

public const float Epsilon = 1E-12

Field Value

float

Max

The maximum corner of the bounding box.

public JVector Max

Field Value

JVector

MaxW

Padding for SIMD alignment. Not used directly.

public float MaxW

Field Value

float

Min

The minimum corner of the bounding box.

public JVector Min

Field Value

JVector

MinW

Padding for SIMD alignment. Not used directly.

public float MinW

Field Value

float

Properties

Center

Gets the center point of the bounding box.

public readonly JVector Center { get; }

Property Value

JVector

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

Vector128<float>

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

Vector128<float>

Methods

AsJBoundingBox()

Converts this TreeBox to a JBoundingBox.

public readonly JBoundingBox AsJBoundingBox()

Returns

JBoundingBox

Contains(in TreeBox)

Determines whether this box completely encloses the specified TreeBox.

public readonly bool Contains(in TreeBox box)

Parameters

box TreeBox

The box to check for containment.

Returns

bool

true if the box is 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

outer TreeBox

The potential container box.

inner TreeBox

The box to check for inclusion.

Returns

bool

true if inner is fully inside outer.

Contains(in JBoundingBox)

Determines whether this box completely encloses the specified box.

public readonly bool Contains(in JBoundingBox box)

Parameters

box JBoundingBox

The box to check for containment.

Returns

bool

true if the box is 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

point JVector

The point to check.

Returns

bool

true if 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

first TreeBox

The first box.

second TreeBox

The second box.

result TreeBox

The resulting union box.

Disjoint(in TreeBox)

Determines whether this box is completely separated from the specified TreeBox.

public readonly bool Disjoint(in TreeBox box)

Parameters

box TreeBox

The box to check against.

Returns

bool

true if the boxes do not overlap; false if 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

first TreeBox

The first box.

second TreeBox

The second box.

Returns

bool

true if the boxes do not overlap on any axis; false if 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

box JBoundingBox

The box to check against.

Returns

bool

true if 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

box JBoundingBox

Returns

bool

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

other TreeBox

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

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

first TreeBox
second TreeBox

Returns

bool

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

first TreeBox

The first box.

second TreeBox

The second box.

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

first TreeBox

The first box.

second TreeBox

The second box.

Returns

bool

true if the boxes intersect; false if 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

box JBoundingBox

The box to check against.

Returns

bool

true if the boxes overlap; false if 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

origin JVector

The origin of the ray.

direction JVector

The direction of the ray (not necessarily normalized).

Returns

bool

true if 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

origin JVector

The origin of the ray.

direction JVector

The direction of the ray (not necessarily normalized).

enter float

Outputs the scalar distance along the direction vector where the ray enters the box. If inside, this is 0.

Returns

bool

true if 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

origin JVector

The start point of the segment.

direction JVector

The vector defining the direction and length of the segment (End Point = Origin + Direction).

Returns

bool

true if 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

left TreeBox
right TreeBox

Returns

bool

operator !=(TreeBox, TreeBox)

public static bool operator !=(TreeBox left, TreeBox right)

Parameters

left TreeBox
right TreeBox

Returns

bool

See Also