Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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))));
        }
Ejemplo n.º 3
0
        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))));
        }
Ejemplo n.º 4
0
        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))));
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <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];
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 9
0
 /// <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));
 }
Ejemplo n.º 10
0
        public override IExplicitShape <int> Transform(IExplicitShape <int> input)
        {
            var shape       = input.Translate(offset);
            var storageRect = GridInterval.Translate(input.Bounds, offset);

            return(shape.ToExplicit(storageRect));
        }
Ejemplo n.º 11
0
 public virtual IEnumerable <Vector3> GetNormals(
     IExplicitShape <GridPoint3> shape,
     GridMap <GridPoint3> gridMap,
     bool flip)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 12
0
 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)));
 }
Ejemplo n.º 13
0
            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);
            }
Ejemplo n.º 14
0
        /// <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)))));
        }
Ejemplo n.º 15
0
        /// <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];
        }
Ejemplo n.º 16
0
        /// <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)));
        }
Ejemplo n.º 17
0
        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)));
        }
Ejemplo n.º 18
0
 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)))));
 }
Ejemplo n.º 19
0
 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)))));
 }
Ejemplo n.º 20
0
 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)));
 }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        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));
        }
Ejemplo n.º 23
0
        public PuzzleGrid(IExplicitShape <GridPoint2> gridShape)
        {
            grid = gridShape.ToGrid <T>();
            grid.Fill(default(T));

            shapes = gridShape.ToGrid <IExplicitShape <GridPoint2> >();
            shapes.Fill((IExplicitShape <GridPoint2>)null);
        }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 25
0
        private void PaintBackground(IExplicitShape <GridPoint2> shape)
        {
            foreach (var point in shape.Points)
            {
                var polyominoCell = Grid[point].GetComponent <PolyominoCell>();

                polyominoCell.Filled = false;
            }
        }
Ejemplo n.º 26
0
        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));
        }
Ejemplo n.º 27
0
        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;
            }
        }
Ejemplo n.º 28
0
 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
 }
Ejemplo n.º 29
0
        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));
        }
Ejemplo n.º 30
0
 private TightShape2(IExplicitShape <GridPoint2> shape, bool alreadyTight)
 {
     if (alreadyTight)
     {
         this.shape = shape;
     }
     else
     {
         InitTightShape(shape);
     }
 }