Exemple #1
0
        /// <summary>Shift the offset by the given delta, causing existing elements to wrap to the opposite sides.</summary>
        public void Rotate(Coord3 offsetDelta)
        {
            Coord3 offset = this.offset;

            for (int i = 0; i < 3; i++)
            {
                offset[i] += offsetDelta[i];
            }
            this.offset = offset;
        }
Exemple #2
0
        /// <summary>Construct a 3D array with the given dimensions and starting offset.</summary>
        public Partial3DArray(Coord3 dimensions, Coord3?offset = null, bool cyclic = false)
        {
            if (dimensions.x < 1 || dimensions.y < 1 || dimensions.z < 1)
            {
                throw new System.ArgumentOutOfRangeException();
            }

            array           = new T[dimensions.x, dimensions.y, dimensions.z];
            this.offset     = offset ?? Coord3.zero;
            this.dimensions = dimensions;
            this.cyclic     = cyclic;
        }
Exemple #3
0
        public static Coord3[] Spherical(int coverage, float ringWidth = 1.0f)
        {
            int lutSpan   = coverage * 2 - 1;
            int numShells = (int)(Mathf.Sqrt(3) * (lutSpan / ringWidth)) + 2;

            List <Coord3>[] shells = new List <Coord3> [numShells];
            for (int shell = 0; shell < numShells; shell++)
            {
                shells[shell] = new List <Coord3>();
            }


            for (int x = -coverage + 1; x < coverage; x++)
            {
                for (int y = -coverage + 1; y < coverage; y++)
                {
                    for (int z = -coverage + 1; z < coverage; z++)
                    {
                        Coord3 ic = new Coord3 {
                            x = x, y = y, z = z
                        };
                        shells[(int)(Mathf.Sqrt(x * x + y * y + z * z) / ringWidth)].Add(ic);
                    }
                }
            }

            Coord3[] lut = new Coord3[lutSpan * lutSpan * lutSpan];
            int      i   = 0;

            for (int shell = 0; shell < numShells; shell++)
            {
                for (int j = 0; j < shells[shell].Count; j++)
                {
                    lut[i] = shells[shell][j];
                    i++;
                }
            }
            return(lut);
        }
Exemple #4
0
        /// <summary>Shift the offset by the given delta, pushing existing elements off the ends of the array.</summary>
        public void Shift(Coord3 offsetDelta, T fillValue = default(T))
        {
            Debug.Log("Shifting from offset " + this.offset + " by " + offsetDelta);

            for (int x = 0; x < dimensions.x; x++)
            {
                for (int y = 0; y < dimensions.y; y++)
                {
                    for (int z = 0; z < dimensions.z; z++)
                    {
                        // if the fields are about to be 'shifted out', replace them with the default value
                        if ((offsetDelta.x > 0 && x < offsetDelta.x) ||
                            (offsetDelta.x < 0 && x >= dimensions.x + offsetDelta.x) ||
                            (offsetDelta.y > 0 && y < offsetDelta.y) ||
                            (offsetDelta.y < 0 && y >= dimensions.y + offsetDelta.y) ||
                            (offsetDelta.z > 0 && z < offsetDelta.z) ||
                            (offsetDelta.z < 0 && z >= dimensions.z + offsetDelta.z))
                        {
                            if (x == 0 && z == 0)
                            {
                                Debug.Log("Erasing value at iteration y: " + y + "; mapped to y: " + y.Ring(dimensions.y, this.offset.y));
                            }

                            array[x.Ring(dimensions.x, this.offset.x),
                                  y.Ring(dimensions.y, this.offset.y),
                                  z.Ring(dimensions.z, this.offset.z)] = fillValue;
                        }
                    }
                }
            }

            Coord3 offset = this.offset;

            for (int i = 0; i < 3; i++)
            {
                offset[i] += offsetDelta[i];
            }
            this.offset = offset;
        }
Exemple #5
0
 /// <summary>Access the element at the given index.</summary>
 public T this[Coord3 index] {
     get { return(this[index.x, index.y, index.z]); }
     set { this[index.x, index.y, index.z] = value; }
 }