A readonly record struct representing a 3D axis-aligned bounding box (AABB). It stores Min and Max corners, exposes Size and Center computed properties, provides a factory FromPoints to build an AABB from a span of Vector3, and an Intersects method with an expansion margin.
using System.Numerics;
namespace AutoRig.Mesh;
// s&box compat: the engine defines Vector2/Vector3 in the GLOBAL namespace, which
// shadows using-directive imports - alias explicitly to System.Numerics.
using Vector2 = System.Numerics.Vector2;
using Vector3 = System.Numerics.Vector3;
/// <summary>Axis-aligned bounding box.</summary>
public readonly record struct Aabb3( Vector3 Min, Vector3 Max )
{
public Vector3 Size => Max - Min;
public Vector3 Center => (Min + Max) * 0.5f;
public static Aabb3 FromPoints( ReadOnlySpan<Vector3> points )
{
if ( points.IsEmpty ) return new( Vector3.Zero, Vector3.Zero );
var min = points[0]; var max = points[0];
foreach ( var p in points ) { min = Vector3.Min( min, p ); max = Vector3.Max( max, p ); }
return new( min, max );
}
public bool Intersects( Aabb3 other, float expand )
=> Min.X - expand <= other.Max.X && Max.X + expand >= other.Min.X
&& Min.Y - expand <= other.Max.Y && Max.Y + expand >= other.Min.Y
&& Min.Z - expand <= other.Max.Z && Max.Z + expand >= other.Min.Z;
}