/// <summary> /// Expands the maze size by a factor and then connects all new rooms that appeared from the expansion. /// </summary> private IGrid <GridPoint2, RectFEV.MazeType> ExpandMaze(IGrid <GridPoint2, RectFEV.MazeType> maze, int factor) { int r1 = (maze.Bounds.Size.X + 1) / 2 * factor; var one = -GridPoint2.One; var newShape = ImplicitShape.Func <GridPoint2>(p => maze.Contains((p - one).FloorDiv(factor * GridPoint2.One)) && maze[(p - one).FloorDiv(factor * GridPoint2.One)] == RectFEV.MazeType.Open).ToExplicit( new GridRect(new GridPoint2(1 - r1, 1 - r1), new GridPoint2(2 * r1 - 1, 2 * r1 - 1))); var maze2 = RectFEV.GenerateMaze(newShape, symmetry); var maze3 = maze2.Bounds.ToGrid <RectFEV.MazeType>(); foreach (var point in maze3.Points) { maze3[point] = maze2.Contains(point) && maze2[point] == RectFEV.MazeType.Open ? RectFEV.MazeType.Open : RectFEV.MazeType.Close; } RectFEV.ContinueMaze(maze3, symmetry); return(maze3); }
public override IExplicitShape <GridPoint3> Aggregate(IEnumerable <IExplicitShape <GridPoint3> > input) { var shape = ImplicitShape.Intersection(input.Cast <IImplicitShape <GridPoint3> >()); var storageRect = input.Select(s => s.Bounds).Aggregate(GridBounds.Intersection); return(shape.ToExplicit(storageRect)); }
public override IExplicitShape <int> Aggregate(IEnumerable <IExplicitShape <int> > input) { var shape = ImplicitShape.Union(input.Cast <IImplicitShape <int> >()); var storageRect = input.Select(s => s.Bounds).Aggregate(GridInterval.UnionBoundingBox); return(shape.ToExplicit(storageRect)); }
/// <summary> /// A Product maze creates small mazes and disposition them on the points of the repeat grid. /// </summary> private IGrid <GridPoint2, RectFEV.MazeType> ProductGrid() { var repeatShape = ImplicitShape.Square(GridPoint2.Zero, repeatGridRadius).ToExplicit(new GridRect(new GridPoint2(1 - repeatGridRadius, 1 - repeatGridRadius), new GridPoint2(2 * repeatGridRadius - 1, 2 * repeatGridRadius - 1))); var smallGridShape = ImplicitShape.Square(GridPoint2.Zero, smallGridRadius).ToExplicit(new GridRect(new GridPoint2(1 - smallGridRadius, 1 - smallGridRadius), new GridPoint2(2 * smallGridRadius - 1, 2 * smallGridRadius - 1))); var bigMaze = Grid.CloneStructure <GridPoint2, RectFEV.MazeType>(p => RectFEV.MazeType.Close); foreach (var iter in repeatShape.Points) { var maze = RectFEV.GenerateMaze(smallGridShape, iter.GetColor(2, 1, 1) == 0 ? RectFEV.Symmetry.Reflection : RectFEV.Symmetry.Rotation); foreach (var point in maze.Points) { var newPoint = iter * new GridPoint2(2 * smallGridRadius - 2, 2 * smallGridRadius - 2) + point; if (maze.Contains(point) && bigMaze.Contains(newPoint)) { bigMaze[newPoint] = maze[point] == RectFEV.MazeType.Open ? RectFEV.MazeType.Open : RectFEV.MazeType.Close; } } } RectFEV.ContinueMaze(bigMaze, symmetry); return(bigMaze); }
protected override IExplicitShape <GridPoint2> Generate() { return(ImplicitShape .RectDiamond(radius) .ToExplicit(new GridRect( new GridPoint2(1 - radius, 1 - radius), new GridPoint2(2 * radius - 1, 2 * radius - 1)))); }
protected override IExplicitShape <GridPoint2> Generate() { var rotated = ImplicitShape .Func <GridPoint2>(p => Contains(p.ToVector2())) .ToExplicit(new GridRect(-2 * GridPoint2.One * radius, 5 * GridPoint2.One * radius)); return(rotated); }
protected override IExplicitShape <GridPoint2> Generate() { return(ImplicitShape .Star(radius) .ToExplicit(new GridRect( new GridPoint2(-2 * radius, -2 * radius), new GridPoint2(4 * radius + 1, 4 * radius + 1)))); }
private static IExplicitShape <GridPoint2> GetThinRectangle(GridPoint2 size) { int storageWidth = size.X + GLMathf.FloorDiv(size.Y - 1, 2); int storageHeight = size.Y; var storagePoint = new GridPoint2(-GLMathf.FloorDiv(size.Y - 1, 2), 0); return(ImplicitShape.HexThinRectangle(size).ToExplicit(new GridRect(storagePoint, new GridPoint2(storageWidth, storageHeight)))); }
private Grid1 <SpriteCell> CreateGrid() { var shape = ImplicitShape.Segment(0, gridSize); var storage = shape.ToExplicit(new GridInterval(0, gridSize)); var grid = new Grid1 <SpriteCell>(storage); return(grid); }
protected override IExplicitShape <GridPoint2> Generate() { var points = vertices.Select(p => p.GetGridPoint()); var implicitShape = ImplicitShape.ConvexPolygon(points); var bounds = GridRect.Erode(ExplicitShape.GetBounds(points)); return(implicitShape.ToExplicit(bounds)); }
protected override IExplicitShape <GridPoint2> Generate() { var dimensions1 = dimensions.GetGridPoint(); return(ImplicitShape .Parallelogram(dimensions1) .ToExplicit(new GridRect(GridPoint2.Zero, dimensions1))); }
private Grid3 <MeshTileCell> CreateGrid() { var dimensions = gridDimensions.GetGridPoint(); var shape = ImplicitShape.Parallelepiped(dimensions); var storage = shape.ToExplicit(new GridBounds(GridPoint3.Zero, dimensions)); var grid = new Grid3 <MeshTileCell>(storage); return(grid); }
private Grid2 <SpriteCell> CreateGrid() { var dimensions = gridDimensions.GetGridPoint(); var shape = ImplicitShape.Parallelogram(dimensions); var storage = shape.ToExplicit(new GridRect(GridPoint2.Zero, dimensions)); var grid = new Grid2 <SpriteCell>(storage); return(grid); }
protected override IExplicitShape <GridPoint3> Generate() { var shapes = baseShape.Select(g => g.GetShape()); var boundingPlane = shapes.Select(s => (GridRect)s.Bounds).Aggregate(GridRect.UnionBoundingBox); var shape = ImplicitShape.Layer(shapes.Select(p => (IImplicitShape <GridPoint2>)p)); var boundingShape = new GridBounds(boundingPlane.Point.To3DXY(0), boundingPlane.Size.To3DXY(baseShape.Count)); return(shape.ToExplicit(boundingShape)); }
protected override IExplicitShape <GridPoint2> Generate() { int iRadius = Mathf.CeilToInt(radius); return(ImplicitShape .DownTriangle(radius).ToExplicit(new GridRect( new GridPoint2(2 - 2 * iRadius, 2 - 2 * iRadius), new GridPoint2(3 * iRadius - 2, 3 * iRadius - 2)))); }
protected override IExplicitShape <GridPoint3> Generate() { var dimensionsGridPoint = dimensions.GetGridPoint(); return(ImplicitShape .Parallelepiped(dimensionsGridPoint) .ToExplicit(new GridBounds( GridPoint3.Zero, dimensionsGridPoint))); }
private IExplicitShape <GridPoint2> GetFlatRectangle(GridPoint2 size) { var storageWidth = size.X; var storageHeight = size.Y + GLMathf.FloorDiv(size.X - 1, 2); var storageBottomLeft = new GridPoint2(0, -GLMathf.FloorDiv(size.X - 1, 2)); return (ImplicitShape.FlatHexRectangle(size) .ToExplicit(new GridRect(storageBottomLeft, new GridPoint2(storageWidth, storageHeight)))); }
protected override IExplicitShape <GridPoint3> Generate() { int extent = Mathf.CeilToInt(radius); return(ImplicitShape .Sphere(radius) .ToExplicit(new GridBounds( GridPoint3.One * -extent, GridPoint3.One * (2 * extent + 1)))); }
public static IGrid <GridPoint2, T> Rect <T>(int width, int height) { var dimensions = new GridPoint2(width, height); var grid = ImplicitShape .Parallelogram(dimensions) .ToExplicit(new GridRect(GridPoint2.Zero, dimensions)) .ToGrid <T>(); return(grid); }
/// <summary> /// A Two step maze creates the maze in two steps by startRadius and then increases it by factor. /// </summary> private IGrid <GridPoint2, RectFEV.MazeType> TwoStep() { var origin = new GridPoint2(1 - startRadius, 1 - startRadius); var size = new GridPoint2(2 * startRadius - 1, 2 * startRadius - 1); var smallGridShape = ImplicitShape.Square(GridPoint2.Zero, startRadius).ToExplicit(new GridRect(origin, size)); var maze = RectFEV.GenerateMaze(smallGridShape, symmetry); maze = ExpandMaze(maze, factor); return(maze); }
public override List <IExplicitShape <int> > Execute(IEnumerable <IExplicitShape <int> > input) { var inputList = input.ToList(); var shape1 = inputList[0]; var shape2 = inputList[1]; var result = ImplicitShape.Func <int>(p => shape1.Contains(p) && !shape2.Contains(p)).ToExplicit(shape1.Bounds); return(new List <IExplicitShape <int> > { result }); }
private Grid2 <SpriteCell> CreateGrid() { var gridDimensions = new InspectableGridPoint2 { x = radius, y = radius }; var dimensions = gridDimensions.GetGridPoint(); var shape = ImplicitShape.Hexagon(radius); var storage = shape.ToExplicit(new GridRect(GridPoint2.Zero, dimensions)); var grid = new Grid2 <SpriteCell>(storage); return(grid); }
public IEnumerator BuildGrid() { totalCellCount = 0; var dimensions = new GridPoint2(width, height); grid = ImplicitShape .Parallelogram(dimensions) .ToExplicit(new GridRect(GridPoint2.Zero, dimensions)) .ToGrid <TileCell>(); map = new GridMap <GridPoint2>( Map.Linear(PointyHexPoint.SpaceMapTransform).PreScale(Vector3.one * 200), Map.HexRound()); int cellCount = 0; foreach (var point in grid.Points) { var cell = Instantiate(cellPrefab); cell.transform.parent = gridRoot.transform; var worldPoint = map.GridToWorld(point); cell.transform.localPosition = worldPoint; cellCount++; totalCellCount++; grid[point] = cell; if (cellCount >= cellsPerIteration) { cellCount = 0; yield return(null); } } }
protected override IExplicitShape <GridPoint3> Generate() { var shape1 = shape2Graph1.GetShape(); var shape2 = shape2Graph2.GetShape(); var shape3 = shape2Graph3.GetShape(); var bounds12 = GridRect.UnionBoundingBox(shape1.Bounds, shape2.Bounds); var bounds13 = GridRect.UnionBoundingBox(shape1.Bounds, shape3.Bounds); var bounds23 = GridRect.UnionBoundingBox(shape2.Bounds, shape3.Bounds); var layer1 = shape1.Layer(bounds23.Size.Y); var layer2 = shape2.Layer(bounds13.Size.X); var layer3 = shape3.Layer(bounds12.Size.Y); layer2 = layer2.SwapToXZY(); layer3 = layer3.SwapToZYX(); var layer1Translation = new GridPoint3(0, 0, bounds23.Point.Y); var layer2Translation = new GridPoint3(0, 0, bounds13.Point.X); var layer3Translation = new GridPoint3(0, 0, bounds12.Point.Y); var bound1 = new GridBounds(layer1.Bounds.Point + layer1Translation, layer1.Bounds.Size); var bound2 = new GridBounds(layer2.Bounds.Point + layer2Translation, layer2.Bounds.Size); var bound3 = new GridBounds(layer3.Bounds.Point + layer3Translation, layer3.Bounds.Size); var fixedLayer1 = layer1.Translate(layer1Translation); var fixedLayer2 = layer2.Translate(layer2Translation); var fixedLayer3 = layer3.Translate(layer3Translation); var fixedLayer12 = ImplicitShape.Intersection(fixedLayer1, fixedLayer2); var fixedLayer123 = ImplicitShape.Intersection(fixedLayer12, fixedLayer3); var bound12 = GridBounds.Intersection(bound1, bound2); var bound123 = GridBounds.Intersection(bound12, bound3); return(fixedLayer123.ToExplicit(bound123)); }
protected override IExplicitShape <GridPoint2> Generate() { return(ImplicitShape .Single2() .ToExplicit(new GridRect(GridPoint2.Zero, GridPoint2.One))); }
protected override IExplicitShape <int> Generate() { var interval = new GridInterval(0, size); return(ImplicitShape.Segment(interval).ToExplicit(interval)); }
protected override IExplicitShape <GridPoint3> Generate() { return(ImplicitShape .Single3() .ToExplicit(new GridBounds(GridPoint3.Zero, GridPoint3.One))); }
protected override IExplicitShape <int> Generate() { return(ImplicitShape .Single1() .ToExplicit(new GridInterval(0, 1))); }