示例#1
0
        /// <summary>
        /// The distance between two coordinates. (Diagonal distance is treated the same as axis distance)
        /// </summary>
        /// <param name="cc1"></param>
        /// <param name="cc2"></param>
        /// <returns>Returns an int representing distance. Returns -1 if either input is not valid.</returns>
        public static int SquareDistance(ChunkCoords cc1, ChunkCoords cc2)
        {
            if (!cc1.IsValid() || !cc2.IsValid())
            {
                return(-1);
            }
            cc1 = ConvertToUpRight(cc1);
            cc2 = ConvertToUpRight(cc2);
            int x = Mathf.Abs(cc1.x - cc2.x);
            int y = Mathf.Abs(cc1.y - cc2.y);

            return(Math.Max(x, y));
        }
示例#2
0
        /// Converts the x and y components of a coordinate set so that they are easier to compare
        public static ChunkCoords ConvertToUpRight(ChunkCoords cc)
        {
            if (cc.quadrant == Quadrant.UpperRight)
            {
                return(cc);
            }

            //check if it is in either of the two left-side quadrants
            if (cc.quadrant == Quadrant.UpperLeft || cc.quadrant == Quadrant.LowerLeft)
            {
                cc.x = -cc.x - 1;
            }

            //check if it is in either of the two bottom quadrants
            if (cc.quadrant == Quadrant.LowerRight || cc.quadrant == Quadrant.LowerLeft)
            {
                cc.y = -cc.y - 1;
            }

            cc.quadrant = Quadrant.UpperRight;
            return(cc);
        }
示例#3
0
        public static Vector2 GetCenterCell(ChunkCoords c, float chunkSize)
        {
            Vector2Pair bounds = GetCellArea(c, chunkSize);

            return(new Vector2((bounds.a.x + bounds.b.x) / 2f, (bounds.a.y + bounds.b.y) / 2f));
        }