Table of Contents

Struct JBoundingBox

Namespace
Jitter2.LinearMath
Assembly
Jitter2.dll

Represents an axis-aligned bounding box (AABB), a rectangular bounding box whose edges are parallel to the coordinate axes.

public struct JBoundingBox : IEquatable<JBoundingBox>
Implements
Inherited Members

Constructors

JBoundingBox(JVector, JVector)

Represents an axis-aligned bounding box (AABB), a rectangular bounding box whose edges are parallel to the coordinate axes.

public JBoundingBox(JVector min, JVector max)

Parameters

min JVector
max JVector

Fields

Epsilon

public const float Epsilon = 1E-12

Field Value

float

LargeBox

A bounding box covering the entire valid range of coordinates.

public static readonly JBoundingBox LargeBox

Field Value

JBoundingBox

Max

The maximum corner of the bounding box (largest X, Y, Z coordinates).

public JVector Max

Field Value

JVector

Min

The minimum corner of the bounding box (smallest X, Y, Z coordinates).

public JVector Min

Field Value

JVector

SmallBox

An inverted bounding box initialized with Min > Max, useful for growing a box from scratch.

public static readonly JBoundingBox SmallBox

Field Value

JBoundingBox

Properties

Center

Gets the center point of the bounding box.

public readonly JVector Center { get; }

Property Value

JVector

Methods

AddPoint(in JVector)

[Obsolete("Use static AddPointInPlace instead.")]
public void AddPoint(in JVector point)

Parameters

point JVector

AddPointInPlace(ref JBoundingBox, in JVector)

Expands the bounding box to include the specified point.

public static void AddPointInPlace(ref JBoundingBox box, in JVector point)

Parameters

box JBoundingBox

The bounding box to expand.

point JVector

The point to include.

Contains(in JBoundingBox)

Determines the relationship between this box and another box.

public readonly JBoundingBox.ContainmentType Contains(in JBoundingBox box)

Parameters

box JBoundingBox

The other bounding box to test.

Returns

JBoundingBox.ContainmentType

Disjoint if they do not touch.
Contains if box is strictly inside this box.
Intersects if they overlap but one does not strictly contain the other.

Contains(in JBoundingBox, in JBoundingBox)

Determines whether the outer box completely contains the inner box.

public static bool Contains(in JBoundingBox outer, in JBoundingBox inner)

Parameters

outer JBoundingBox

The outer bounding box.

inner JBoundingBox

The inner bounding box to test.

Returns

bool

true if inner is entirely within the boundaries of outer; otherwise, false.

Contains(in JVector)

Determines whether the bounding box contains the specified point.

public readonly bool Contains(in JVector point)

Parameters

point JVector

Returns

bool

CreateFromPoints(IEnumerable<JVector>)

Creates a bounding box that exactly encompasses a collection of points.

public static JBoundingBox CreateFromPoints(IEnumerable<JVector> points)

Parameters

points IEnumerable<JVector>

The collection of points to encompass.

Returns

JBoundingBox

A bounding box containing all the points.

CreateMerged(in JBoundingBox, in JBoundingBox)

Creates a new bounding box that is the union of two other bounding boxes.

public static JBoundingBox CreateMerged(in JBoundingBox original, in JBoundingBox additional)

Parameters

original JBoundingBox

The first bounding box.

additional JBoundingBox

The second bounding box.

Returns

JBoundingBox

A bounding box encompassing both inputs.

CreateMerged(in JBoundingBox, in JBoundingBox, out JBoundingBox)

Creates a new bounding box that is the union of two other bounding boxes.

public static void CreateMerged(in JBoundingBox original, in JBoundingBox additional, out JBoundingBox result)

Parameters

original JBoundingBox

The first bounding box.

additional JBoundingBox

The second bounding box.

result JBoundingBox

Output: A bounding box encompassing both inputs.

CreateTransformed(in JBoundingBox, in JMatrix)

Creates a new AABB that encloses the original box after it has been rotated by the given orientation matrix.

public static JBoundingBox CreateTransformed(in JBoundingBox box, in JMatrix orientation)

Parameters

box JBoundingBox

The original bounding box.

orientation JMatrix

The rotation matrix to apply.

Returns

JBoundingBox

A new AABB enclosing the rotated box.

Remarks

Rotating an AABB usually results in a larger AABB to fit the rotated geometry.

Disjoint(in JBoundingBox, in JBoundingBox)

Determines whether the two boxes are completely separated (disjoint).

public static bool Disjoint(in JBoundingBox left, in JBoundingBox right)

Parameters

left JBoundingBox

The first bounding box.

right JBoundingBox

The second bounding box.

Returns

bool

true if there is a gap between the boxes on at least one axis; otherwise, false.

Encompasses(in JBoundingBox, in JBoundingBox)

Determines whether the outer box completely contains the inner box.

[Obsolete("Use Contains instead.")]
public static bool Encompasses(in JBoundingBox outer, in JBoundingBox inner)

Parameters

outer JBoundingBox
inner JBoundingBox

Returns

bool

Remarks

Equals(JBoundingBox)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(JBoundingBox other)

Parameters

other JBoundingBox

An object to compare with this object.

Returns

bool

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

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.

GetCorners(Span<JVector>)

Retrieves the 8 corners of the bounding box.

public readonly void GetCorners(Span<JVector> destination)

Parameters

destination Span<JVector>

A span of at least 8 JVectors to hold the corners.

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 float GetSurfaceArea()

Returns

float

GetVolume()

Calculates the volume of the bounding box.

public readonly float GetVolume()

Returns

float

NotDisjoint(in JBoundingBox, in JBoundingBox)

Determines whether the two boxes intersect or overlap.

[Obsolete("Use !Disjoint instead.")]
public static bool NotDisjoint(in JBoundingBox left, in JBoundingBox right)

Parameters

left JBoundingBox
right JBoundingBox

Returns

bool

true if the boxes overlap; false if they are disjoint.

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 distance along the direction vector where the ray enters the box. Returns 0 if the origin is inside.

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 from start to end (End = Origin + Direction).

Returns

bool

true if the segment passes through the box; otherwise, false.

ToString()

Returns a string representation of the JBoundingBox.

public override readonly string ToString()

Returns

string

Transform(in JMatrix)

[Obsolete("Use static CreateTransformed instead.")]
public void Transform(in JMatrix orientation)

Parameters

orientation JMatrix

Operators

operator ==(JBoundingBox, JBoundingBox)

public static bool operator ==(JBoundingBox left, JBoundingBox right)

Parameters

left JBoundingBox
right JBoundingBox

Returns

bool

operator !=(JBoundingBox, JBoundingBox)

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

Parameters

left JBoundingBox
right JBoundingBox

Returns

bool