/** * Makes an edge grid for this grid. */ public IGrid <TNewCell, DiamondPoint> MakeEdgeGrid <TNewCell>() { var edges = this.SelectMany(x => x.GetEdges()); var storage = DiamondGrid <TNewCell> .CalculateStorage(edges); var offset = DiamondGrid <TNewCell> .GridPointFromArrayPoint(storage.offset); return(new DiamondGrid <TNewCell>(storage.dimensions.X, storage.dimensions.Y, x => IsInsideEdgeGrid(x + offset), offset)); }
public DiamondShapeInfo <TCell> Default(int width, int height) { var rawInfow = MakeShapeStorageInfo <DiamondPoint>( width, height, x => DiamondGrid <TCell> .DefaultContains(x, width, height)); return(new DiamondShapeInfo <TCell>(rawInfow)); }
public static bool __CompilerHint2__Diamond__MeshTileCell() { //Ensures abstract super classes for base grids gets created var grid = new DiamondGrid <MeshTileCell>(1, 1, p => p == DiamondPoint.Zero, x => x, x => x, new List <DiamondPoint>()); //Ensures shape infpo classes get created var shapeStorageInfo = new ShapeStorageInfo <DiamondPoint>(new IntRect(), p => true); var shapeInfo = new DiamondShapeInfo <MeshTileCell>(shapeStorageInfo); return(grid[grid.First()] == null || shapeInfo.Translate(DiamondPoint.Zero) != null); }
public static bool __CompilerHint__Diamond__MeshTileCell() { var grid = new DiamondGrid <MeshTileCell[]>(1, 1); foreach (var point in grid) { grid[point] = new MeshTileCell[1]; } var shapeStorageInfo = new ShapeStorageInfo <DiamondPoint>(new IntRect(), p => true); var shapeInfo = new DiamondShapeInfo <MeshTileCell>(shapeStorageInfo); return(grid[grid.First()][0] == null || shapeInfo.Translate(DiamondPoint.Zero) != null); }
/** * Call this method if you use a DiamondGrid. * Replace the type __CellType to whatever type you have in your grid. * * You can call the method anywhere in your code. * * if(!__CompilerHint__Diamond()) return; * * This methods always returns true. * * @since 1.6 */ public static bool __CompilerHint__Diamond() { //Ensures abstract super classes for base grids gets created var grid = new DiamondGrid <__CellType[]>(1, 1); foreach (var point in grid) { grid[point] = new __CellType[1]; } //Ensures shape infpo classes get created var shapeStorageInfo = new ShapeStorageInfo <DiamondPoint>(new IntRect(), p => true); var shapeInfo = new DiamondShapeInfo <__CellType>(shapeStorageInfo); return(grid[grid.First()][0] == null || shapeInfo.Translate(DiamondPoint.Zero) != null); }
/** * 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(); }
protected override void InitGrid() { VectorPoint rectDimensions = Dimensions; switch (shape) { case Shape.Rectangle: base.Grid = DiamondGrid <TileCell> .Rectangle(rectDimensions.X, rectDimensions.Y); break; case Shape.Parallelogram: base.Grid = DiamondGrid <TileCell> .Parallelogram(rectDimensions.X, rectDimensions.Y); break; case Shape.FatRectangle: base.Grid = DiamondGrid <TileCell> .FatRectangle(rectDimensions.X, rectDimensions.Y); break; case Shape.ThinRectangle: base.Grid = DiamondGrid <TileCell> .ThinRectangle(rectDimensions.X, rectDimensions.Y); break; case Shape.Diamond: base.Grid = DiamondGrid <TileCell> .Diamond(Size); break; case Shape.Single: base.Grid = DiamondGrid <TileCell> .Single(); break; case Shape.Custom: var shapeBuilder = GetComponent <CustomGridBuilder>(); base.Grid = shapeBuilder.MakeGrid <TileCell, DiamondPoint>(); break; default: throw new ArgumentOutOfRangeException(); } switch (neighborSetup) { case RectNeighborType.Main: ((DiamondGrid <TileCell>)base.Grid).SetNeighborsMain(); break; case RectNeighborType.Diagonals: ((DiamondGrid <TileCell>)base.Grid).SetNeighborsDiagonals(); break; case RectNeighborType.MainAndDiagonals: ((DiamondGrid <TileCell>)base.Grid).SetNeighborsMainAndDiagonals(); break; default: throw new ArgumentOutOfRangeException(); } }
protected override ArrayPoint ArrayPointFromGridPoint(DiamondPoint point) { return(DiamondGrid <TCell> .ArrayPointFromGridPoint(point)); }
protected override DiamondPoint GridPointFromArrayPoint(ArrayPoint point) { return(DiamondGrid <TCell> .GridPointFromArrayPoint(point)); }
/** * Starts a compound shape operation. * * Any shape that is defined in terms of other shape operations must use this method, and use Endgroup() to end the definition. * * public static DiamondShapeInfo<TCell> MyCustomShape(this DiamondOp<TCell> op) * { * return * BeginGroup() * .Shape1() * .Union() * .Shape2() * .EndGroup(op); * } * * @since 1.1 */ public DiamondOp <TCell> BeginGroup() { return(DiamondGrid <TCell> .BeginShape()); }