示例#1
0
        /// <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)));
        }
示例#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));
 }
示例#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));
 }
示例#4
0
 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));
 }
示例#5
0
    private void Move()
    {
        if (!keepDirectionForFrame)
        {
            CurrentDirection = CurrentAttemptedDirection;
        }
        Vector3 dir = Grid.GridMap.GridToWorld(CurrentDirection);

        UpdatePosition(dir);
        UpdateRotation(dir);

        keepDirectionForFrame = false;
    }
示例#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;
            }
        }
示例#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);
        }
示例#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;
                    }
                }
            }
        }
示例#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);
        }
示例#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);
                        }
                    }
                }
            }
        }
示例#11
0
        public bool IsEmpty(IExplicitShape <GridPoint2> shape, GridPoint2 point)
        {
            var offsetShape = shape.Translate(point);

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

            return(offsetShape.Points.All(p => grid.Contains(p)));
        }
示例#14
0
 public IExplicitShape <GridPoint2> GetShape(GridPoint2 point)
 {
     return(shapes[point]);
 }
示例#15
0
 public static IEnumerable <GridPoint2> GetOrthogonalAndDiagonalNeighbors(GridPoint2 point)
 {
     return(point.GetVectorNeighbors(OrthogonalAndDiagonalDirections));
 }
示例#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));
 }
示例#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));
 }
示例#18
0
 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));
 }
示例#19
0
 public static GridPoint2 ReflectAboutX(GridPoint2 point)
 {
     return(new GridPoint2(point.X, -point.Y));
 }
示例#20
0
 public static GridPoint2 Rotate270(GridPoint2 point)
 {
     return(new GridPoint2(point.Y, -point.X));
 }
示例#21
0
 public static GridPoint2 Rotate180(GridPoint2 point)
 {
     return(new GridPoint2(-point.X, -point.Y));
 }
示例#22
0
 public static int DownTriPseudoNorm(GridPoint2 point)
 {
     return(Mathf.Max(-point.X, -point.Y, point.X + point.Y));
 }
示例#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));
 }
示例#24
0
 public static int StarNorm(GridPoint2 point)
 {
     return(Mathf.Min(UpTriPseudoNorm(point), DownTriPseudoNorm(point)));
 }
示例#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));
 }
示例#26
0
 public static int UpTriPseudoNorm(GridPoint2 point)
 {
     return(Mathf.Max(point.X, point.Y, -point.X - point.Y));
 }
示例#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));
 }
示例#28
0
 public void SetDirection(GridPoint2 nextDirection)
 {
     CurrentAttemptedDirection = nextDirection;
 }
示例#29
0
 public static IImplicitShape <GridPoint2> HexFatRectangle(GridPoint2 dimensions)
 {
     return(PointyHexFatRectangle(dimensions));
 }
示例#30
0
 public T this[GridPoint2 point]
 {
     get { return(grid[point]); }
 }