public IGrid <TNewCell, RectPoint> MakeVertexGrid <TNewCell>() { var vertices = this.SelectMany(x => x.GetVertices()); var storage = RectGrid <TNewCell> .CalculateStorage(vertices); var offset = RectGrid <TNewCell> .GridPointFromArrayPoint(storage.offset); return(new RectGrid <TNewCell>(storage.dimensions.X, storage.dimensions.Y, x => IsInsideVertexGrid(x + offset), offset)); }
public RectShapeInfo <TCell> Default(int width, int height) { var rawInfow = MakeShapeStorageInfo <RectPoint>( width, height, x => RectGrid <TCell> .DefaultContains(x, width, height)); return(new RectShapeInfo <TCell>(rawInfow)); }
public static bool __CompilerHint2__Rect__MeshTileCell() { //Ensures abstract super classes for base grids gets created var grid = new RectGrid <MeshTileCell>(1, 1, p => p == RectPoint.Zero, x => x, x => x, new List <RectPoint>()); //Ensures shape infpo classes get created var shapeStorageInfo = new ShapeStorageInfo <RectPoint>(new IntRect(), p => true); var shapeInfo = new RectShapeInfo <MeshTileCell>(shapeStorageInfo); return(grid[grid.First()] == null || shapeInfo.Translate(RectPoint.Zero) != null); }
/// <summary> /// Constructs a new NestedRectGrid. /// </summary> /// <param name="bigDimensions">How wide and high this grid is (how many grids per row and how many grids per column).</param> /// <param name="smallDimensions">How wide and high each small grid is (how many cells in each row and columns).</param> public NestedRectGrid(RectPoint bigDimensions, RectPoint smallDimensions) { this.bigDimensions = bigDimensions; this.smallDimensions = smallDimensions; bigGrid = new RectGrid <RectGrid <TCell> >(bigDimensions.X, bigDimensions.Y); foreach (var bigPoint in bigGrid) { bigGrid[bigPoint] = new RectGrid <TCell>(smallDimensions.X, smallDimensions.Y); } }
protected override void InitGrid() { VectorPoint rectDimensions = Dimensions; switch (shape) { case Shape.Rectangle: base.Grid = RectGrid <MeshCell> .Rectangle(rectDimensions.X, rectDimensions.Y); break; case Shape.Parallelogram: base.Grid = RectGrid <MeshCell> .Parallelogram(rectDimensions.X, rectDimensions.Y); break; case Shape.CheckerBoard: base.Grid = RectGrid <MeshCell> .CheckerBoard(rectDimensions.X, rectDimensions.Y); break; case Shape.Circle: base.Grid = RectGrid <MeshCell> .BeginShape().Circle(size).EndShape(); break; case Shape.Custom: base.Grid = GetCustomGrid(); break; default: throw new ArgumentOutOfRangeException(); } switch (neighborSetup) { case RectNeighborType.Main: ((RectGrid <MeshCell>)base.Grid).SetNeighborsMain(); break; case RectNeighborType.Diagonals: ((RectGrid <MeshCell>)base.Grid).SetNeighborsDiagonals(); break; case RectNeighborType.MainAndDiagonals: ((RectGrid <MeshCell>)base.Grid).SetNeighborsMainAndDiagonals(); break; default: throw new ArgumentOutOfRangeException(); } }
public static bool __CompilerHint__Rect__MeshTileCell() { var grid = new RectGrid <MeshTileCell[]>(1, 1); foreach (var point in grid) { grid[point] = new MeshTileCell[1]; } var shapeStorageInfo = new ShapeStorageInfo <RectPoint>(new IntRect(), p => true); var shapeInfo = new RectShapeInfo <MeshTileCell>(shapeStorageInfo); return(grid[grid.First()][0] == null || shapeInfo.Translate(RectPoint.Zero) != null); }
public static IEnumerable <RectPoint> GetNeighborHood <T>(this RectGrid <T> grid, RectPoint center, int radius) { for (int i = center.X - radius; i <= center.X + radius; i++) { for (int j = center.Y - radius; j <= center.Y + radius; j++) { var neighborhoodPoint = new RectPoint(i, j); if (grid.Contains(neighborhoodPoint)) { yield return(neighborhoodPoint); } } } }
/** * Call this method if you use a RectGrid. * Replace the type __CellType to whatever type you have in your grid. * * You can call the method anywhere in your code. * * if(!__CompilerHint__Rect()) return; * * This methods always returns true. * * @since 1.6 */ public static bool __CompilerHint__Rect() { //Ensures abstract super classes for base grids gets created var grid = new RectGrid <__CellType[]>(1, 1); foreach (var point in grid) { grid[point] = new __CellType[1]; } //Ensures shape infpo classes get created var shapeStorageInfo = new ShapeStorageInfo <RectPoint>(new IntRect(), p => true); var shapeInfo = new RectShapeInfo <__CellType>(shapeStorageInfo); return(grid[grid.First()][0] == null || shapeInfo.Translate(RectPoint.Zero) != null); }
protected override void InitGrid() { int width = Dimensions.X; int height = Dimensions.Y; switch (shape) { case Shape.Rectangle: base.Grid = RectGrid <TileCell> .HorizontallyWrappedParallelogram(width, height); break; default: throw new ArgumentOutOfRangeException(); } }
/** * 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(); }
private static bool IsInNeighbourhood(RectGrid <Vector2?> grid, IMap <RectPoint> map, Vector2 point, float mindist) { var gridPoint = map[point]; //get the neighbourhood if the point in the grid //cellsAroundPoint = squareAroundPoint(grid, gridPoint, 5); foreach (var neighbor in grid.GetNeighborHood(gridPoint, 2)) { var cell = grid[neighbor]; if (cell != null) { var difference = cell.Value - point; if (difference.magnitude < mindist) { return(true); } } } return(false); }
protected override ArrayPoint ArrayPointFromGridPoint(RectPoint point) { return(RectGrid <TCell> .ArrayPointFromGridPoint(point)); }
protected override RectPoint GridPointFromArrayPoint(ArrayPoint point) { return(RectGrid <TCell> .GridPointFromArrayPoint(point)); }
public static List <Vector2> GeneratePoisson(Rect rect, float minDist, int newPointsCount) { //Create the grid float cellSize = minDist / Mathf.Sqrt(2); var gridWidth = Mathf.CeilToInt(rect.width / cellSize); var gridHeight = Mathf.CeilToInt(rect.height / cellSize); var grid = RectGrid <Vector2?> .Rectangle(gridWidth, gridHeight); var map = new RectMap(Vector2.one) .AnchorCellBottomLeft() .WithWindow(rect) .Stretch(grid); var processList = new RandomQueue <Vector2>(); var samplePoints = new List <Vector2>(); //generate the first point randomly //and updates var firstPoint = new Vector2(Random.value * rect.width, Random.value * rect.height) + new Vector2(rect.xMin, rect.yMin); //update containers processList.Push(firstPoint); samplePoints.Add(firstPoint); grid[map[firstPoint]] = firstPoint; //generate other points from points in queue. while (!processList.IsEmpty()) { var point = processList.Pop(); for (int i = 0; i < newPointsCount; i++) { var newPoint = GenerateRandomPointAround(point, minDist); //check that the point is in the image region //and no points exists in the point's neighbourhood if (rect.Contains(newPoint) && !IsInNeighbourhood(grid, map, newPoint, minDist)) { if (grid.Contains(map[newPoint])) //TODO: why is this necessary? { //update containers processList.Push(newPoint); samplePoints.Add(newPoint); grid[map[newPoint]] = newPoint; } /* * else * { * Debug.Log(newPoint); * Debug.Log(map[newPoint]); * Debug.Break(); * } */ } } } return(samplePoints); }
/** * 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 RectShapeInfo<TCell> MyCustomShape(this RectOp<TCell> op) * { * return * BeginGroup() * .Shape1() * .Union() * .Shape2() * .EndGroup(op); * } * * @since 1.1 */ public RectOp <TCell> BeginGroup() { return(RectGrid <TCell> .BeginShape()); }