An internal hit shape that composes two IHitShape instances and returns the slot index from the first shape only if both shapes resolve a hit at the given local position and size. It implements intersection logic: a hit is valid when both underlying shapes report a hit.
using Sandbox;
namespace HitShapes;
internal sealed class IntersectHitShape : IHitShape
{
readonly IHitShape _a;
readonly IHitShape _b;
public IntersectHitShape(IHitShape a, IHitShape b)
{
_a = a;
_b = b;
}
public int SlotCount => _a.SlotCount;
public int? Resolve(Vector2 local, Vector2 size)
{
var sa = _a.Resolve(local, size);
if (!sa.HasValue) return null;
if (!_b.Resolve(local, size).HasValue) return null;
return sa.Value;
}
}