/// <summary>
        /// It apply a Star norm to a given point.
        /// </summary>
        /// <param name="point">Point to apply the operation.</param>
        private static float StarNorm(GridPoint2 point)
        {
            var x = point.X;
            var y = point.Y;

            return(Mathf.Min(Mathf.Max(x, y, -x - y), Mathf.Max(-x, -y, x + y)));
        }
Exemple #2
0
 public static IImplicitShape <GridPoint2> PointyHexThinRectangle(GridPoint2 dimensions)
 {
     return(new FunctionShape <GridPoint2>(point =>
                                           point.X >= -GLMathf.FloorDiv(point.Y, 2) &&
                                           point.X + GLMathf.FloorMod(point.Y, 2) < -GLMathf.FloorDiv(point.Y, 2) + dimensions.X &&
                                           point.Y >= 0 &&
                                           point.Y < dimensions.Y));
 }
Exemple #3
0
 public static IImplicitShape <GridPoint2> FlatHexThinRectangle(GridPoint2 dimensions)
 {
     return(new FunctionShape <GridPoint2>(point =>
                                           point.Y >= -(GLMathf.FloorDiv(point.X, 2)) &&
                                           point.Y + GLMathf.FloorMod(point.X, 2) < -(GLMathf.FloorDiv(point.X, 2)) + dimensions.Y &&
                                           point.X >= 0 &&
                                           point.X < dimensions.X));
 }
 public static IImplicitShape <GridPoint2> HexRectangle(GridPoint2 dimensions)
 {
     return(new FunctionShape <GridPoint2>(point =>
                                           point.Y >= 0 &&
                                           point.Y < dimensions.Y &&
                                           point.X >= -GLMathf.FloorDiv(point.Y, 2) &&
                                           point.X < -GLMathf.FloorDiv(point.Y, 2) + dimensions.X));
 }
Exemple #5
0
    private void Move()
    {
        if (!keepDirectionForFrame)
        {
            CurrentDirection = CurrentAttemptedDirection;
        }
        Vector3 dir = Grid.GridMap.GridToWorld(CurrentDirection);

        UpdatePosition(dir);
        UpdateRotation(dir);

        keepDirectionForFrame = false;
    }
Exemple #6
0
        public override TCell this[GridPoint2 point]
        {
            get
            {
                var accessPoint = point - shape.Bounds.Point;
                return(cells[accessPoint.X, accessPoint.Y]);
            }

            set
            {
                var accessPoint = point - shape.Bounds.Point;
                cells[accessPoint.X, accessPoint.Y] = value;
            }
        }
Exemple #7
0
        public static Grid2 <float> ImageToGreyScaleGrid(Texture2D texture, int xOffset, int yOffset)
        {
            var dimensions    = new GridPoint2(texture.width, texture.height);
            var storageRect   = new GridRect(GridPoint2.Zero, dimensions);
            var implicitShape = ImplicitShape.Parallelogram(dimensions);
            var explicitShape = implicitShape.ToExplicit(storageRect);

            var grid        = new Grid2 <float>(explicitShape);
            var textureData = texture.GetPixels().Select(c => c.grayscale).ToArray();

            grid.Fill(p => textureData[(p.X + xOffset) % texture.width + (texture.width * ((p.Y + yOffset) % texture.height))]);

            return(grid);
        }
Exemple #8
0
        public void Remove(GridPoint2 point)
        {
            if (grid.Contains(point))
            {
                var shape = shapes[point];

                if (shape != null)
                {
                    foreach (var shapePoint in shape.Points)
                    {
                        grid[shapePoint]   = default(T);
                        shapes[shapePoint] = null;
                    }
                }
            }
        }
Exemple #9
0
        public IExplicitShape <GridPoint2> Place(IExplicitShape <GridPoint2> shape, GridPoint2 point, T item)
        {
            if (!Contains(shape, point))
            {
                throw new InvalidOperationException("Shape is not completely in grid.");
            }
            if (!IsEmpty(shape, point))
            {
                throw new InvalidOperationException("Shape is not completely empty.");
            }

            var offsetShape = shape.Translate(point);

            foreach (var shapePoint in offsetShape.Points)
            {
                grid[shapePoint]   = item;
                shapes[shapePoint] = offsetShape;
            }

            return(offsetShape);
        }
Exemple #10
0
        public IEnumerable <GridPoint2> GetSpiralIterator(GridPoint2 origin, int ringCount)
        {
            var point = origin;

            yield return(point);

            for (var k = 1; k < ringCount; k++)
            {
                point += RectPoint.NorthWest;

                for (var i = 0; i < 4; i++)
                {
                    for (var j = 0; j < 2 * k; j++)
                    {
                        point += SpiralIteratorDirections[i];

                        if (Contains(point))
                        {
                            yield return(point);
                        }
                    }
                }
            }
        }
Exemple #11
0
        public bool IsEmpty(IExplicitShape <GridPoint2> shape, GridPoint2 point)
        {
            var offsetShape = shape.Translate(point);

            return(offsetShape.Points.All(p => shapes[p] == null));
        }
Exemple #12
0
 public bool IsEmpty(GridPoint2 point)
 {
     return(shapes[point] == null);
 }
Exemple #13
0
        public bool Contains(IExplicitShape <GridPoint2> shape, GridPoint2 point)
        {
            var offsetShape = shape.Translate(point);

            return(offsetShape.Points.All(p => grid.Contains(p)));
        }
Exemple #14
0
 public IExplicitShape <GridPoint2> GetShape(GridPoint2 point)
 {
     return(shapes[point]);
 }
Exemple #15
0
 public static IEnumerable <GridPoint2> GetOrthogonalAndDiagonalNeighbors(GridPoint2 point)
 {
     return(point.GetVectorNeighbors(OrthogonalAndDiagonalDirections));
 }
Exemple #16
0
 /// <summary>
 /// Creates a 2D Translate Shape.
 /// </summary>
 /// <param name="shape">Base Shape to translate.</param>
 /// <param name="offset">Offset of the translation.</param>
 public static IImplicitShape <GridPoint2> Translate(this IImplicitShape <GridPoint2> shape, GridPoint2 offset)
 {
     return(new TranslationShape2(shape, offset));
 }
Exemple #17
0
 /// <summary>
 /// Creates a 2D HalfPlane Shape given two points.
 /// </summary>
 /// <param name="point1">Base point 1 of the Plane.</param>
 /// <param name="point2">Base point 2 of the Plane.</param>
 public static IImplicitShape <GridPoint2> HalfPlane(GridPoint2 point1, GridPoint2 point2)
 {
     return(new Halfplane(point1, point2));
 }
 public static GridPoint2 Mul(this GridPoint2 v, Matrixi22 m)
 {
     return(new GridPoint2(
                v.X * m.a + v.Y * m.c,
                v.X * m.b + v.Y * m.d));
 }
Exemple #19
0
 public static GridPoint2 ReflectAboutX(GridPoint2 point)
 {
     return(new GridPoint2(point.X, -point.Y));
 }
Exemple #20
0
 public static GridPoint2 Rotate270(GridPoint2 point)
 {
     return(new GridPoint2(point.Y, -point.X));
 }
Exemple #21
0
 public static GridPoint2 Rotate180(GridPoint2 point)
 {
     return(new GridPoint2(-point.X, -point.Y));
 }
Exemple #22
0
 public static int DownTriPseudoNorm(GridPoint2 point)
 {
     return(Mathf.Max(-point.X, -point.Y, point.X + point.Y));
 }
Exemple #23
0
 /// <summary>
 /// Creates a 2D Single Shape with a given center value.
 /// </summary>
 /// <param name="point">Value for the center of the single shape.</param>
 public static IImplicitShape <GridPoint2> Single2(GridPoint2 point)
 {
     return(new SingleShape2(point));
 }
Exemple #24
0
 public static int StarNorm(GridPoint2 point)
 {
     return(Mathf.Min(UpTriPseudoNorm(point), DownTriPseudoNorm(point)));
 }
Exemple #25
0
 /// <summary>
 /// Creates a 2D Product Shape.
 /// </summary>
 /// <param name="shape1">Base shape to make the product operation.</param>
 /// <param name="shape2">Shape used for the product operation.</param>
 /// <param name="scale">Scale factor applied to the shape2.</param>
 public static IImplicitShape <GridPoint2> Product(this IExplicitShape <GridPoint2> shape1,
                                                   IImplicitShape <GridPoint2> shape2, GridPoint2 scale)
 {
     return(new ProductShape2(shape1, shape2, scale));
 }
Exemple #26
0
 public static int UpTriPseudoNorm(GridPoint2 point)
 {
     return(Mathf.Max(point.X, point.Y, -point.X - point.Y));
 }
Exemple #27
0
 /// <summary>
 /// Creates a 2D Parallelogram Shape.
 /// </summary>
 /// <param name="dimensions">Dimensions of the shape.</param>
 public static IImplicitShape <GridPoint2> Parallelogram(GridPoint2 dimensions)
 {
     return(new ParallelogramShape(dimensions));
 }
Exemple #28
0
 public void SetDirection(GridPoint2 nextDirection)
 {
     CurrentAttemptedDirection = nextDirection;
 }
Exemple #29
0
 public static IImplicitShape <GridPoint2> HexFatRectangle(GridPoint2 dimensions)
 {
     return(PointyHexFatRectangle(dimensions));
 }
Exemple #30
0
 public T this[GridPoint2 point]
 {
     get { return(grid[point]); }
 }