Beispiel #1
0
        public static CubeCoordinates Round(Vector3 cube)
        {
            if (Mathf.Abs(cube.x + cube.y + cube.z) > NEARZERO)
            {
                throw new ArgumentOutOfRangeException("x+y+z should be zero");
            }

            CubeCoordinates r = new CubeCoordinates();

            r.x = Mathf.RoundToInt(cube.x);
            r.y = Mathf.RoundToInt(cube.y);
            r.z = Mathf.RoundToInt(cube.z);

            var x_diff = Mathf.Abs(r.x - cube.x);
            var y_diff = Mathf.Abs(r.y - cube.y);
            var z_diff = Mathf.Abs(r.z - cube.z);

            if (x_diff > y_diff && x_diff > z_diff)
            {
                r.x = -r.y - r.z;
            }
            else if (y_diff > z_diff)
            {
                r.y = -r.x - r.z;
            }
            else
            {
                r.z = -r.x - r.y;
            }

            return(r);
        }
Beispiel #2
0
 public AxialCoordinates(CubeCoordinates cube)
 {
     if (cube.x + cube.y + cube.z != 0)
     {
         throw new IndexOutOfRangeException("Coordinates are not part of hex grid");
     }
     q = cube.x;
     r = cube.y;
 }