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
Fields
Epsilon
public const float Epsilon = 1E-12
Field Value
LargeBox
A bounding box covering the entire valid range of coordinates.
public static readonly JBoundingBox LargeBox
Field Value
Max
The maximum corner of the bounding box (largest X, Y, Z coordinates).
public JVector Max
Field Value
Min
The minimum corner of the bounding box (smallest X, Y, Z coordinates).
public JVector Min
Field Value
SmallBox
An inverted bounding box initialized with Min > Max, useful for growing a box from scratch.
public static readonly JBoundingBox SmallBox
Field Value
Properties
Center
Gets the center point of the bounding box.
public readonly JVector Center { get; }
Property Value
Methods
AddPoint(in JVector)
[Obsolete("Use static AddPointInPlace instead.")]
public void AddPoint(in JVector point)
Parameters
pointJVector
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
boxJBoundingBoxThe bounding box to expand.
pointJVectorThe point to include.
Contains(in JBoundingBox)
Determines the relationship between this box and another box.
public readonly JBoundingBox.ContainmentType Contains(in JBoundingBox box)
Parameters
boxJBoundingBoxThe other bounding box to test.
Returns
- JBoundingBox.ContainmentType
Disjoint if they do not touch.
Contains ifboxis 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
outerJBoundingBoxThe outer bounding box.
innerJBoundingBoxThe inner bounding box to test.
Returns
Contains(in JVector)
Determines whether the bounding box contains the specified point.
public readonly bool Contains(in JVector point)
Parameters
pointJVector
Returns
CreateFromPoints(IEnumerable<JVector>)
Creates a bounding box that exactly encompasses a collection of points.
public static JBoundingBox CreateFromPoints(IEnumerable<JVector> points)
Parameters
pointsIEnumerable<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
originalJBoundingBoxThe first bounding box.
additionalJBoundingBoxThe 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
originalJBoundingBoxThe first bounding box.
additionalJBoundingBoxThe second bounding box.
resultJBoundingBoxOutput: 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
boxJBoundingBoxThe original bounding box.
orientationJMatrixThe 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
leftJBoundingBoxThe first bounding box.
rightJBoundingBoxThe second bounding box.
Returns
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
outerJBoundingBoxinnerJBoundingBox
Returns
Remarks
This is an alias for Contains(in JBoundingBox, in JBoundingBox).
Equals(JBoundingBox)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(JBoundingBox other)
Parameters
otherJBoundingBoxAn object to compare with this object.
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.
GetCorners(Span<JVector>)
Retrieves the 8 corners of the bounding box.
public readonly void GetCorners(Span<JVector> destination)
Parameters
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
GetVolume()
Calculates the volume of the bounding box.
public readonly float GetVolume()
Returns
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
leftJBoundingBoxrightJBoundingBox
Returns
- bool
trueif the boxes overlap;falseif 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
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 distance along the direction vector where the ray enters the box. Returns 0 if the origin is inside.
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 from start to end (End = Origin + Direction).
Returns
- bool
trueif the segment passes through the box; otherwise,false.
ToString()
Returns a string representation of the JBoundingBox.
public override readonly string ToString()
Returns
Transform(in JMatrix)
[Obsolete("Use static CreateTransformed instead.")]
public void Transform(in JMatrix orientation)
Parameters
orientationJMatrix
Operators
operator ==(JBoundingBox, JBoundingBox)
public static bool operator ==(JBoundingBox left, JBoundingBox right)
Parameters
leftJBoundingBoxrightJBoundingBox
Returns
operator !=(JBoundingBox, JBoundingBox)
public static bool operator !=(JBoundingBox left, JBoundingBox right)
Parameters
leftJBoundingBoxrightJBoundingBox