Code/Internal/ShapeCache.cs
using System.Collections.Concurrent;

namespace HitShapes;

internal static class ShapeCache
{
    static readonly ConcurrentDictionary<(int slots, float innerRatio, float outerRatio), IHitShape> _radial = new();
    static readonly ConcurrentDictionary<(int cols, int rows), IHitShape> _rectGrid = new();

    public static IHitShape GetOrCreateRadial(int slots, float innerRatio, float outerRatio)
        => _radial.GetOrAdd((slots, innerRatio, outerRatio),
            k => new RadialHitShape(k.slots, k.innerRatio, k.outerRatio));

    public static IHitShape GetOrCreateRectGrid(int cols, int rows)
        => _rectGrid.GetOrAdd((cols, rows),
            k => new RectGridHitShape(k.cols, k.rows));
}