MoonWorks/src/Collision/Fixed/Collider.cs

34 lines
625 B
C#

using System;
namespace MoonWorks.Collision.Fixed
{
public class Collider<T> : IHasAABB2D where T : struct, IShape2D
{
private readonly T[] Shapes;
public ReadOnlySpan<T>.Enumerator GetEnumerator() => new ReadOnlySpan<T>(Shapes).GetEnumerator();
public AABB2D AABB { get; }
public Collider(T shape)
{
Shapes = new T[1] { shape };
AABB = shape.AABB;
}
public Collider(T[] shapes)
{
Shapes = new T[shapes.Length];
Array.Copy(shapes, Shapes, shapes.Length);
var aabb = new AABB2D();
foreach (var shape in Shapes)
{
aabb = aabb.Compose(shape.AABB);
}
AABB = aabb;
}
}
}