public static IExplicitShape <int> Translate(this IExplicitShape <int> shape, int n) { var newBounds = GridInterval.Translate(shape.Bounds, n); var newShape = ImplicitShape.Translate(shape, n).ToExplicit(newBounds); return(newShape); }
public static IExplicitShape <GridPoint3> ReflectZInBounds(this IExplicitShape <GridPoint3> shape) { var bounds = shape.Bounds; var func = new Func <GridPoint3, GridPoint3>(p => new GridPoint3(p.X, p.Y, bounds.Extreme.Z - p.Z + bounds.Point.Z - 1)); return(bounds.Where(p => shape.Contains(func(p)))); }
public static IExplicitShape <GridPoint2> ReflectYInBounds(this IExplicitShape <GridPoint2> shape) { var bounds = shape.Bounds; var func = new Func <GridPoint2, GridPoint2>(p => new GridPoint2(p.X, bounds.Extreme.Y - p.Y + bounds.Point.Y - 1)); return(bounds.Where(p => shape.Contains(func(p)))); }
public static IExplicitShape <int> ReflectXInBounds(this IExplicitShape <int> shape) { var bounds = shape.Bounds; var func = new Func <int, int>(p => bounds.Extreme - p + bounds.Point - 1); return(bounds.Where(p => shape.Contains(func(p)))); }
public static IExplicitShape <GridPoint3> Translate(this IExplicitShape <GridPoint3> shape, GridPoint3 n) { var newBounds = GridBounds.Translate(shape.Bounds, n); var newShape = ImplicitShape.Translate(shape, n).ToExplicit(newBounds); return(newShape); }
/// <summary> /// Initializes a new instance of the <see cref="Grid1{TCell}"/> class with /// the specified shape. /// Cells are not initialized, they have the default value of type <c>TCell</c>. /// </summary> /// <param name="shape">The shape of this grid.</param> public Grid1(IExplicitShape <int> shape) { this.shape = shape; var storageDimensions = shape.Bounds.Size; cells = new TCell[storageDimensions]; }
private GridMap <GridPoint2> CreateMap(IExplicitShape <GridPoint2> grid) { var cellDimensions = cellPrefab.Sprite.rect.size; var scale = new Vector3(1, .85f, 1); //VectorExtensions.To3DXY(cellDimensions, 1); var spaceMap = Map .Translate(new Vector3(0, 3.2f, 0)) .ComposeWith(Map.Linear(Matrixf33.Scale(scale))) .ComposeWith(Map.Polar(cellDimensions.y, 1.0f / gridDimensions.x)); var roundMap = Map.RectRound(); var parallelogramMap = Map.ParallelogramWrapX(gridDimensions.x); var composeMap = parallelogramMap.ComposeWith(roundMap); var spaceAlignMap = spaceMap.AlignGridInRect(grid, p => scale, new Bounds(ScreenRect.center, ScreenRect.size), horizontalAlignment, verticalAlignment); var spaceAlignAnchorMap = spaceAlignMap.AnchorPivotInRect(grid, p => scale, horizontalAnchorPivot, verticalAnchorPivot); var gridMap = new GridMap <GridPoint2>(spaceAlignAnchorMap, composeMap); return(gridMap); }
public override IExplicitShape <GridPoint3> Transform(IExplicitShape <GridPoint3> input) { switch (newPermutation) { case CoordinatePermutation.XYZ: break; case CoordinatePermutation.XZY: return(input.SwapToXZY()); case CoordinatePermutation.YXZ: return(input.SwapToYXZ()); case CoordinatePermutation.YZX: return(input.SwapToYZX()); case CoordinatePermutation.ZXY: return(input.SwapToZXY()); case CoordinatePermutation.ZYX: return(input.SwapToZYX()); default: throw new ArgumentOutOfRangeException(); } return(input); }
/// <summary> /// Creates a shape that is the product of this shape with another shape. /// </summary> /// <remarks> /// Takes the first shape, and for each point, scale that point by /// the given amount, and create a copy of the second shape at that point. /// The combined shape is the product of the two shapes. /// </remarks> public static IImplicitShape <GridPoint3> Product( this IExplicitShape <GridPoint3> shape1, IImplicitShape <GridPoint3> shape2, GridPoint3 scale) { return(new ProductShape3(shape1, shape2, scale)); }
public override IExplicitShape <int> Transform(IExplicitShape <int> input) { var shape = input.Translate(offset); var storageRect = GridInterval.Translate(input.Bounds, offset); return(shape.ToExplicit(storageRect)); }
public virtual IEnumerable <Vector3> GetNormals( IExplicitShape <GridPoint3> shape, GridMap <GridPoint3> gridMap, bool flip) { throw new NotSupportedException(); }
public override IEnumerable <Vector3> GetNormals(IExplicitShape <int> shape, GridMap <int> map, bool flip) { return(shape .Points .SelectMany(p => vertices[GLMathf.FloorMod(p, colorFunction.x0)] .Select((q, i) => map.GridToWorld(q + map.DeRound(p) + (flip ? -normals[GLMathf.FloorMod(p, colorFunction.x0)][i] : normals[GLMathf.FloorMod(p, colorFunction.x0)][i])).normalized))); }
public ProductShape2(IExplicitShape <GridPoint2> shape1, IImplicitShape <GridPoint2> shape2, GridPoint2 scaleFactor) { var translationShapes = shape1.Points .Select(point => shape2.Translate(point.Mul(scaleFactor))); unionShape = new UnionShape <GridPoint2>(translationShapes); }
/// <inheritdoc/> public override IEnumerable <Vector3> GetVertices(IExplicitShape <GridPoint3> shape, GridMap <GridPoint3> map) { //var triangles = GetCellTriangles().ToArray(); var vertices = GetCellVertices().ToArray(); return(shape.Points.SelectMany(p => vertices.Select(q => map.GridToWorld(q + map.DeRound(p))))); }
/// <summary> /// Initializes a new instance of the <see cref="Grid1{TCell}"/> class with /// the specified shape. /// Cells are not initialized, they have the default value of type <c>TCell</c>. /// </summary> /// <param name="shape">The shape of this grid.</param> public Grid3(IExplicitShape <GridPoint3> shape) { this.shape = shape; var storageDimensions = shape.Bounds.Size; cells = new TCell[storageDimensions.X, storageDimensions.Y, storageDimensions.Z]; }
/// <inheritdoc/> public override IEnumerable <Vector3> GetNormals(IExplicitShape <GridPoint3> explicitShape, GridMap <GridPoint3> gridMap, bool flip) { var normals = GetCellNormals().ToArray(); var vertices = GetCellVertices().ToArray(); return(explicitShape.Points.SelectMany(p => vertices.Select((q, i) => gridMap.GridToWorld(q + gridMap.DeRound(p) + (flip ? -normals[i] : normals[i])).normalized))); }
private IEnumerable <int> GetTrianglesNormal(IExplicitShape <GridPoint3> shape) { var triangles = GetCellTriangles().ToArray(); var vertices = GetCellVertices().ToArray(); return(shape.Points.SelectMany((p, i) => triangles.Select(t => t + i * vertices.Length))); }
public override IEnumerable <Vector3> GetVertices(IExplicitShape <int> shape, GridMap <int> map) { return(shape .Points .SelectMany(p => vertices[GLMathf.FloorMod((int)p, colorFunction.x0)] .Select(q => map.GridToWorld(q + map.DeRound(p))))); }
public override IEnumerable <Vector3> GetVertices(IExplicitShape <GridPoint3> shape, GridMap <GridPoint3> map) { return(shape .Points .SelectMany(p => vertices[p.GetColor(colorFunction)] .Select(q => map.GridToWorld(q + map.DeRound(p))))); }
public override IEnumerable <Vector3> GetNormals(IExplicitShape <GridPoint3> explicitShape, GridMap <GridPoint3> gridMap, bool flip) { return(explicitShape .Points .SelectMany(p => vertices[p.GetColor(colorFunction)] .Select((q, i) => gridMap.GridToWorld(q + gridMap.DeRound(p) + (flip ? -normals[p.GetColor(colorFunction)][i] : normals[p.GetColor(colorFunction)][i])).normalized))); }
private GridMap <GridPoint2> CreateMap(IExplicitShape <GridPoint2> grid) { var cellDimensions = cellPrefab.Sprite.rect.size; //static invocation is used here because the Unity compiler //gets confused otherwise. var scale = cellDimensions.To3DXY(1); var scaleSpaceMap = Map.Linear(Matrixf33.Scale(scale)); var spaceMap = Map.Linear(PointyHexPoint.SpaceMapTransform.Mul(Matrixf33.RotateZ(-30 * Mathf.Deg2Rad))); spaceMap = spaceMap.ComposeWith(scaleSpaceMap); var roundMap = Map.HexRound(); var spaceAlignMap = spaceMap.AlignGridInRect( grid, p => scale, p => p.ToVector2().To3DXY(), new Bounds(ScreenRect.center, ScreenRect.size), horizontalAlignment, verticalAlignment); var spaceAlignAnchorMap = spaceAlignMap.AnchorPivotInRect(grid, p => scale, horizontalAnchorPivot, verticalAnchorPivot); var gridMap = new GridMap <GridPoint2>(spaceAlignAnchorMap, roundMap); return(gridMap); }
public static IExplicitShape <GridPoint3> CenterOnOrigin(this IExplicitShape <GridPoint3> shape) { var size = shape.Bounds.Size / 2; var newPoint = -size; var translation = newPoint - shape.Bounds.Point; return(shape.Translate(translation)); }
public PuzzleGrid(IExplicitShape <GridPoint2> gridShape) { grid = gridShape.ToGrid <T>(); grid.Fill(default(T)); shapes = gridShape.ToGrid <IExplicitShape <GridPoint2> >(); shapes.Fill((IExplicitShape <GridPoint2>)null); }
public override IExplicitShape <GridPoint3> Transform(IExplicitShape <GridPoint3> input) { var offset1 = offset.GetGridPoint(); var shape = input.Translate(offset1); var storageRect = GridBounds.Translate(input.Bounds, offset1); return(shape.ToExplicit(storageRect)); }
private void PaintBackground(IExplicitShape <GridPoint2> shape) { foreach (var point in shape.Points) { var polyominoCell = Grid[point].GetComponent <PolyominoCell>(); polyominoCell.Filled = false; } }
public static IExplicitShape <GridPoint3> Layer(this IExplicitShape <GridPoint2> shape, int layerCount) { var bounds = shape.Bounds; var newBounds = new GridBounds(bounds.Point.To3DXY(0), bounds.Size.To3DXY(layerCount)); // static call is necessary so that this method does not get called instead //Remember: explicit shapes _are_ implicit shapes too. return(ImplicitShape.Layer(shape, layerCount).ToExplicit(newBounds)); }
private void PaintShape(IExplicitShape <GridPoint2> placedShape) { foreach (var point in placedShape.Points) { var polyominoCell = Grid[point].GetComponent <PolyominoCell>(); polyominoCell.FillColor = colors[(int)currentShapeType]; polyominoCell.Filled = true; } }
private void InitMesh(Mesh mesh, IExplicitShape <GridPoint3> grid, GridMap <GridPoint3> map) { mesh.vertices = meshData.GetVertices(grid, map).ToArray(); mesh.triangles = meshData.GetTriangles(grid, doubleSided, flipTriangles).ToArray(); mesh.uv = meshData.GetUVs(grid).ToArray(); //mesh.normals = meshData1.GetNormals(grid, map, doubleSided, flipTriangles).ToArray(); mesh.RecalculateNormals(); mesh.RecalculateBounds(); //mesh.normals }
public static IExplicitShape <GridPoint3> SwapToZYX(this IExplicitShape <GridPoint3> shape) { var bounds = shape.Bounds; var point = bounds.Point; var size = bounds.Size; var newBounds = new GridBounds( new GridPoint3(point.Z, point.Y, point.X), new GridPoint3(size.Z, size.Y, size.X)); return(ImplicitShape.SwapToZYX(shape).ToExplicit(newBounds)); }
private TightShape2(IExplicitShape <GridPoint2> shape, bool alreadyTight) { if (alreadyTight) { this.shape = shape; } else { InitTightShape(shape); } }