/// <summary> /// Make a new instance, copy from other instance (copy c'tor A, second c'tor variant). /// Makes a copy of the other ring buffer (but only copies useful data, to safe time). /// </summary> /// <param name="other">the other instance</param> public GenericRingBuffer3D(GenericRingBuffer3D <T> other) : this(other.MemSlots, other.CellsX, other.CellsY) { //we copy as much as we can from the other //use 'newestGenPos', work into the direction of 'oldestGenPos' (fit as much as we can) //use top-left corner (0,0), work into x and y direction as far as we can //if this new ringbuffer is bigger than the other: fill with 'defaultValue' this.newestGenPos = other.newestGenPos; this.oldestGenPos = other.oldestGenPos; int i = oldestGenPos; do { MakeGeneration(i, false); Array.Copy(other.ringBuffer[i], ringBuffer[i], ringBuffer[i].Length); i++; if (i >= MemSlots) { i = 0; } }while (i != newestGenPos); }
/// <summary> /// Make a new instance, copy from other instance (copy c'tor B, third c'tor variant). /// Tries to grab as much data from the other instance as possible. /// </summary> /// <param name="mem">number of memory slots in the ring buffer (1st dimension)</param> /// <param name="x">number of cells in x direction (2nd dimension)</param> /// <param name="y">number of cells in y direction (3rd dimension)</param> /// <param name="other">the other instance</param> /// <param name="defaultValue">default value for excess cells (if new instance has more space than the other instance)</param> public GenericRingBuffer3D(int mem, int x, int y, GenericRingBuffer3D <T> other) : this(mem, x, y) { //we copy as much as we can from the other //use 'newestGenPos', work into the direction of 'oldestGenPos' (fit as much as we can) //use top-left corner (0,0), work into x and y direction as far as we can //if this new ringbuffer is bigger than the other: fill with 'defaultValue' this.newestGenPos = other.newestGenPos; this.oldestGenPos = other.oldestGenPos; int i = oldestGenPos; do { MakeGeneration(i, true); int ox = other.CellsX; int oy = other.CellsY; T[,] arr = ringBuffer[i]; T[,] oarr = other.ringBuffer[i]; for (int a = 0; a < x; a++) { if (a >= ox) { break; } for (int b = 0; b < y; b++) { if (b >= oy) { break; } arr[a, b] = oarr[a, b]; } } i++; if (i >= MemSlots) { i = 0; } }while (i != newestGenPos); }