예제 #1
0
            /// <summary>
            /// Constructs a cell with the same hash code as the given parameter.
            /// </summary>
            public Cell(int i, GeodesicGrid grid)
            {
                if (i < 0 || i >= grid.Count)
                {
                    throw new ArgumentOutOfRangeException();
                }

                if (i == 0)
                {
                    this = new Cell(0, -1, 0, grid);
                }
                else if (i == grid.Count - 1)
                {
                    this = new Cell(0, 2 * grid.n - 1, grid.n, grid);
                }
                else
                {
                    i -= 1;
                    var x = i / (grid.n * grid.n * 2);
                    i -= grid.n * grid.n * 2 * x;
                    var y = i / grid.n;
                    var z = i - grid.n * y;
                    this = new Cell(x, y, z, grid);
                }
            }
예제 #2
0
            public Cell(int x, int y, int z, GeodesicGrid grid)
                : this()
            {
                this.grid = grid;
                int n = grid.n;

                if (z < -1 || y < -1 || z > n || y > 2 * n)
                {
                    throw new ArgumentOutOfRangeException();
                }

                if (y == -1)
                {
                    if (z == 0)
                    {
                        x = 0;
                    }
                    else if (z == -1)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    else
                    {
                        x = x - 1;
                        y = z - 1;
                        z = 0;
                    }
                }
                else if (z == -1)
                {
                    x = x + 1;
                    if (y < n)
                    {
                        z = y;
                        y = 0;
                    }
                    else
                    {
                        y = y - n;
                        z = n - 1;
                    }
                }
                else if (y == 2 * n)
                {
                    if (z == n)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    x = x + 1;
                    y = n + z;
                    z = n - 1;
                }
                else if (z == n)
                {
                    if (y < n)
                    {
                        x = x - 1;
                        y = y + n;
                        z = 0;
                    }
                    else if (y < 2 * n - 1)
                    {
                        x = x - 1;
                        z = y - n + 1;
                        y = 2 * n - 1;
                    }
                    else
                    {
                        x = 4;
                    }
                }

                x %= 5;
                if (x < 0)
                {
                    x += 5;
                }

                X = x;
                Y = y;
                Z = z;
            }
예제 #3
0
 public bool Equals(GeodesicGrid other)
 {
     return(n == other.n);
 }