Example #1
0
        public PointyHexShapeInfo <TCell> Default(int width, int height)
        {
            var rawInfow = MakeShapeStorageInfo <PointyHexPoint>(
                width,
                height,
                x => PointyHexGrid <TCell> .DefaultContains(x, width, height));

            return(new PointyHexShapeInfo <TCell>(rawInfow));
        }
Example #2
0
        /**
         *      This method is provided for generic testing purposes.
         *      It should generally not be used in production code: it may
         *      be slow and not type-safe.
         */
        public static TGrid MakeGrid <TPoint, TGrid, TCell>(int width, int height, TPoint offset)
            where TPoint : IGridPoint <TPoint>
            where TGrid : IGrid <TCell, TPoint>
        {
            if (typeof(TPoint) == typeof(PointyHexPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(PointyHexGrid <TCell>));

                return((TGrid)(object)new PointyHexGrid <TCell>(
                           width,
                           height,
                           x => PointyHexGrid <TCell> .DefaultContains(x, width, height),
                           (PointyHexPoint)(object)offset));
            }
            if (typeof(TPoint) == typeof(FlatHexPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(FlatHexGrid <TCell>));

                return((TGrid)(object)new FlatHexGrid <TCell>(
                           width,
                           height,
                           x => FlatHexGrid <TCell> .DefaultContains(x, width, height),
                           (FlatHexPoint)(object)offset));
            }
            if (typeof(TPoint) == typeof(RectPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(RectGrid <TCell>));

                return((TGrid)(object)new RectGrid <TCell>(
                           width,
                           height,
                           x => RectGrid <TCell> .DefaultContains(x, width, height),
                           (RectPoint)(object)offset));
            }
            if (typeof(TPoint) == typeof(DiamondPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(DiamondGrid <TCell>));

                return((TGrid)(object)new DiamondGrid <TCell>(
                           width,
                           height,
                           x => DiamondGrid <TCell> .DefaultContains(x, width, height),
                           (DiamondPoint)(object)offset));
            }

            throw new NotSupportedException();
        }