32 lines
923 B
C#
32 lines
923 B
C#
using System.Numerics;
|
|
|
|
namespace Dashboard
|
|
{
|
|
public readonly record struct Box3d(Vector3 Min, Vector3 Max)
|
|
{
|
|
public float Left => Min.X;
|
|
public float Right => Max.X;
|
|
public float Top => Min.Y;
|
|
public float Bottom => Max.Y;
|
|
public float Far => Min.Z;
|
|
public float Near => Max.Z;
|
|
|
|
public Vector3 Size => Max - Min;
|
|
public Vector3 Center => Min + Size / 2f;
|
|
|
|
public static Box3d Union(Box3d left, Box3d right)
|
|
{
|
|
Vector3 min = Vector3.Min(left.Min, right.Min);
|
|
Vector3 max = Vector3.Max(left.Max, right.Max);
|
|
return new Box3d(min, max);
|
|
}
|
|
|
|
public static Box3d Intersect(Box3d left, Box3d right)
|
|
{
|
|
Vector3 min = Vector3.Max(left.Min, right.Min);
|
|
Vector3 max = Vector3.Min(left.Max, right.Max);
|
|
return new Box3d(min, max);
|
|
}
|
|
}
|
|
}
|