47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using System.Drawing;
|
|
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 * 0.5f;
|
|
|
|
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 Union(Box3d box, Box2d bounds, float depth)
|
|
{
|
|
Vector3 min = Vector3.Min(box.Min, new Vector3(bounds.Left, bounds.Top, depth));
|
|
Vector3 max = Vector3.Max(box.Max, new Vector3(bounds.Right, bounds.Bottom, depth));
|
|
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);
|
|
}
|
|
|
|
public static Box3d Intersect(Box3d box, Box2d bounds, float depth)
|
|
{
|
|
Vector3 min = Vector3.Max(box.Min, new Vector3(bounds.Min, depth));
|
|
Vector3 max = Vector3.Min(box.Max, new Vector3(bounds.Max, depth));
|
|
return new Box3d(min, max);
|
|
}
|
|
}
|
|
}
|