Exemplo n.º 1
0
        public static bool TryGetComponentAt(
            this IReadOnlyBorder border,
            Coord coord,
            out BorderComponentType component,
            out IReadOnlyRegion componentRegion)
        {
            if (!border.OuterRegion.Overlaps(coord))
            {
                goto fail;
            }

            for (int y = 2; 0 < y; y--)
            {
                for (int x = 2; 0 < x; x--)
                {
                    BorderComponentType type   = ComponentTypes[y, x];
                    IReadOnlyRegion     region = border.GetComponent(type);
                    if (region.Overlaps(coord))
                    {
                        component       = type;
                        componentRegion = region;
                        return(true);
                    }
                }
            }

fail:
            component       = default;
            componentRegion = default !;
Exemplo n.º 2
0
        public static bool Overlaps(this IReadOnlyRegion region1, IReadOnlyRegion region2)
        {
            if (region1 is null)
            {
                throw new ArgumentNullException(nameof(region1));
            }

            if (region2 is null)
            {
                throw new ArgumentNullException(nameof(region2));
            }

            return(region1.Overlaps(region2.ToRectangle()));
        }