예제 #1
0
        override public FlatHexPoint RawWorldToGrid(Vector2 point)
        {
            int x = GLMathf.FloorToInt((point.x + cellDimensions.x / 2) / cellDimensions.x);
            int y = GLMathf.FloorToInt((point.y - x * cellDimensions.y / 2 + cellDimensions.y / 2) / cellDimensions.y);

            return(new FlatHexPoint(x, y));
        }
예제 #2
0
        /**
         *      Gives a new point that represents the
         *      reminder when the first point is divided
         *      by the second point	component-wise. The
         *      division is integer division.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public DiamondPoint Mod(DiamondPoint otherPoint)
        {
            var x = GLMathf.Mod(X, otherPoint.X);
            var y = GLMathf.Mod(Y, otherPoint.Y);

            return(new DiamondPoint(x, y));
        }
예제 #3
0
        public DiamondShapeInfo <TCell> FatRectangle(int width, int height)
        {
            int diamondSize       = width + GLMathf.Div(height, 2);
            var storageBottomLeft = new DiamondPoint(0, 1 - width);

            return(Shape(diamondSize, diamondSize, p => IsInsideFatRectangle(p, width, height), storageBottomLeft));
        }
예제 #4
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)))));
 }
예제 #5
0
        /// <summary>
        /// Gives a new point that represents the
        ///	first point divided by the second point
        ///	component-wise. The division is integer
        ///	division.
        ///
        ///	Since version 1.6 (Rect)
        ///	Since version 1.7 (other)
        /// </summary>
        public DiamondPoint Div(DiamondPoint otherPoint)
        {
            var x = GLMathf.FloorDiv(X, otherPoint.X);
            var y = GLMathf.FloorDiv(Y, otherPoint.Y);

            return(new DiamondPoint(x, y));
        }
예제 #6
0
        public VectorPoint Div(VectorPoint other)
        {
            var newX = GLMathf.FloorDiv(x, other.X);
            var newY = GLMathf.FloorDiv(y, other.Y);

            return(new VectorPoint(newX, newY));
        }
예제 #7
0
        /// <summary>
        /// Gives a new point that represents the
        ///	first point divided by the second point
        ///	component-wise. The division is integer
        ///	division.
        ///
        ///	Since version 1.6 (Rect)
        ///	Since version 1.7 (other)
        /// </summary>
        public FlatHexPoint Div(FlatHexPoint otherPoint)
        {
            var x = GLMathf.FloorDiv(X, otherPoint.X);
            var y = GLMathf.FloorDiv(Y, otherPoint.Y);

            return(new FlatHexPoint(x, y));
        }
예제 #8
0
        /// <summary>
        /// Gives a new point that represents the
        ///	first point divided by the second point
        ///	component-wise. The division is integer
        ///	division.
        ///
        ///	Since version 1.6 (Rect)
        ///	Since version 1.7 (other)
        /// </summary>
        public RectPoint Div(RectPoint otherPoint)
        {
            var x = GLMathf.FloorDiv(X, otherPoint.X);
            var y = GLMathf.FloorDiv(Y, otherPoint.Y);

            return(new RectPoint(x, y));
        }
예제 #9
0
        /**
         *      Gives a new point that represents the
         *      reminder when the first point is divided
         *      by the second point	component-wise. The
         *      division is integer division.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public RectPoint Mod(RectPoint otherPoint)
        {
            var x = GLMathf.Mod(X, otherPoint.X);
            var y = GLMathf.Mod(Y, otherPoint.Y);

            return(new RectPoint(x, y));
        }
예제 #10
0
        /// <summary>
        /// Gives a new point that represents the
        ///	reminder when the first point is divided
        ///	by the second point	component-wise. The
        ///	division is integer division.
        ///
        ///	Since version 1.6 (Rect)
        ///	Since version 1.7 (other)
        /// </summary>
        public PointyHexPoint Mod(PointyHexPoint otherPoint)
        {
            var x = GLMathf.FloorMod(X, otherPoint.X);
            var y = GLMathf.FloorMod(Y, otherPoint.Y);

            return(new PointyHexPoint(x, y));
        }
예제 #11
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)));
 }
예제 #12
0
        /**
         *      Gives a new point that represents the
         *      reminder when the first point is divided
         *      by the second point	component-wise. The
         *      division is integer division.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public FlatHexPoint Mod(FlatHexPoint otherPoint)
        {
            var x = GLMathf.Mod(X, otherPoint.X);
            var y = GLMathf.Mod(Y, otherPoint.Y);

            return(new FlatHexPoint(x, y));
        }
예제 #13
0
        /**
         *      Gives a new point that represents the
         *      first point divided by the second point
         *      component-wise. The division is integer
         *      division.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public PointyHexPoint Div(PointyHexPoint otherPoint)
        {
            var x = GLMathf.Div(X, otherPoint.X);
            var y = GLMathf.Div(Y, otherPoint.Y);

            return(new PointyHexPoint(x, y));
        }
예제 #14
0
        public VectorPoint Mod(VectorPoint other)
        {
            var newX = GLMathf.Mod(x, other.X);
            var newY = GLMathf.Mod(y, other.Y);

            return(new VectorPoint(newX, newY));
        }
예제 #15
0
        public PointyHexShapeInfo <TCell> ThinRectangle(int width, int height)
        {
            int storageWidth      = width + GLMathf.Div(height - 1, 2);
            int storageHeight     = height;
            var storageBottomLeft = new PointyHexPoint(-GLMathf.Div(height - 1, 2), 0);

            return(Shape(storageWidth, storageHeight, x => IsInsideThinRectangle(x, width, height), storageBottomLeft));
        }
예제 #16
0
        public GridPoint3 FloorMod(GridPoint3 otherPoint)
        {
            var modX = GLMathf.FloorMod(X, otherPoint.X);
            var modY = GLMathf.FloorMod(Y, otherPoint.Y);
            var modZ = GLMathf.FloorMod(Z, otherPoint.Z);

            return(new GridPoint3(modX, modY, modZ));
        }
예제 #17
0
        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))));
        }
예제 #18
0
        public GridPoint3 FloorDiv(GridPoint3 otherPoint)
        {
            var divX = GLMathf.FloorDiv(X, otherPoint.X);
            var divY = GLMathf.FloorDiv(Y, otherPoint.Y);
            var divZ = GLMathf.FloorDiv(Z, otherPoint.Z);

            return(new GridPoint3(divX, divY, divZ));
        }
예제 #19
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));
 }
예제 #20
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));
 }
예제 #21
0
        public FlatHexShapeInfo <TCell> ThinRectangle(int width, int height)
        {
            var storageWidth      = width;
            var storageHeight     = height + GLMathf.FloorDiv(width - 1, 2);
            var storageBottomLeft = new FlatHexPoint(0, -GLMathf.FloorDiv(width - 1, 2));

            return(Shape(storageWidth, storageHeight, x => IsInsideThinRectangle(x, width, height), storageBottomLeft));
        }
예제 #22
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));
 }
예제 #23
0
        public override LinePoint RawWorldToGrid(Vector2 worldPoint)
        {
            var point = (worldPoint + cellDimensions / 2);

            var m = GLMathf.FloorToInt(point.x / cellDimensions.x);

            return(m);
        }
예제 #24
0
        public DiamondShapeInfo <TCell> Rectangle(int width, int height)
        {
            //Note: this fit is not the tightest possible.
            int diamondSize = width + GLMathf.Div(height, 2);

            var storageBottomLeft = new DiamondPoint(0, 1 - width);

            return(Shape(diamondSize, diamondSize, p => IsInsideRaggedRectangle(p, width, height), storageBottomLeft));
        }
예제 #25
0
        public IEnumerable <RectPoint> GetEdgeFaces()
        {
            var edgeAnchor = GetEdgeFaceAnchor();

            int edgeIndex = GLMathf.Mod(X + Y, 2);

            return(from faceDirection in EdgeFaceDirections[edgeIndex]
                   select faceDirection + edgeAnchor);
        }
예제 #26
0
        private static bool IsInsideThinRectangle(PointyHexPoint point, int width, int height)
        {
            int startX = -(GLMathf.FloorDiv(point.Y, 2));

            return
                (point.X >= startX &&
                 point.X + GLMathf.FloorMod(point.Y, 2) < startX + width &&
                 point.Y >= 0 &&
                 point.Y < height);
        }
예제 #27
0
        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))));
        }
예제 #28
0
        private static bool IsInsideFatRectangle(PointyHexPoint point, int width, int height)
        {
            int startX = -(GLMathf.Div(point.Y, 2));

            return
                (point.X >= startX - GLMathf.Mod(point.Y, 2) &&
                 point.X < startX + width &&
                 point.Y >= 0 &&
                 point.Y < height);
        }
예제 #29
0
        private bool IsInsideThinRectangle(FlatHexPoint point, int width, int height)
        {
            int startY = -(GLMathf.FloorDiv(point.X, 2));

            return
                (point.Y >= startY &&
                 point.Y + GLMathf.FloorMod(point.X, 2) < startY + height &&
                 point.X >= 0 &&
                 point.X < width);
        }
예제 #30
0
        private static bool IsInsideFatRectangle(FlatHexPoint point, int width, int height)
        {
            int startY = -(GLMathf.FloorDiv(point.X, 2));

            return
                (point.Y >= startY - GLMathf.FloorMod(point.X, 2) &&
                 point.Y < startY + height &&
                 point.X >= 0 &&
                 point.X < width);
        }