public void Encapsulate(CoordDir coord) /// Resizes this rect so that coord is included { if (coord.x < offset.x) { size.x += offset.x - coord.x; offset.x = coord.x; } if (coord.x >= offset.x + size.x) { size.x = coord.x - offset.x + 1; } if (coord.y < offset.y) { size.y += offset.y - coord.y; offset.y = coord.y; } if (coord.y >= offset.y + size.y) { size.y = coord.y - offset.y + 1; } if (coord.z < offset.z) { size.z += offset.z - coord.z; offset.z = coord.z; } if (coord.z >= offset.z + size.z) { size.z = coord.z - offset.z + 1; } }
public CoordDir GetChunkCoord(CoordDir worldCoord, int chunkSize) //gets chunk CoordDirinates using wholeterrain unit CoordDir { return(new CoordDir ( worldCoord.x >= 0 ? (int)(worldCoord.x / chunkSize) : (int)((worldCoord.x + 1) / chunkSize) - 1, 0, worldCoord.z >= 0 ? (int)(worldCoord.z / chunkSize) : (int)((worldCoord.z + 1) / chunkSize) - 1 )); }
public Matrix3D(CoordDir offset, CoordDir size, T[] array = null) { cube = new CoordCube(offset, size); count = cube.size.x * cube.size.y * cube.size.z; if (array != null && array.Length < count) { Debug.LogError("Array length: " + array.Length + " is lower then matrix capacity: " + count); } if (array != null && array.Length >= count) { this.array = array; } else { this.array = new T[count]; } }
public int GetPos(CoordDir c) { #if WDEBUG if (c.x < offset.x || c.x >= offset.x + size.x) { throw new System.ArgumentOutOfRangeException("x", "Index Out Of Range (" + offset.x + "-" + (offset.x + size.x) + "): " + c.x); } if (c.y < offset.y || c.y >= offset.y + size.y) { throw new System.ArgumentOutOfRangeException("y", "Index Out Of Range (" + offset.y + "-" + (offset.y + size.y) + "): " + c.y); } if (c.z < offset.z || c.z >= offset.z + size.z) { throw new System.ArgumentOutOfRangeException("z", "Index Out Of Range (" + offset.z + "-" + (offset.z + size.z) + "): " + c.z); } #endif return((c.z - offset.z) * size.x * size.y + (c.y - offset.y) * size.x + c.x - offset.x); }
public static CoordDir Max(CoordDir[] coords) { CoordDir max = new CoordDir(int.MinValue, int.MinValue, int.MinValue, 7); for (int i = 0; i < coords.Length; i++) { if (coords[i].x > max.x) { max.x = coords[i].x; } if (coords[i].y > max.y) { max.y = coords[i].y; } if (coords[i].z > max.z) { max.z = coords[i].z; } } return(max); }
public static CoordDir Min(CoordDir[] coords) { CoordDir min = new CoordDir(int.MaxValue, int.MaxValue, int.MaxValue, 7); for (int i = 0; i < coords.Length; i++) { if (coords[i].x < min.x) { min.x = coords[i].x; } if (coords[i].y < min.y) { min.y = coords[i].y; } if (coords[i].z < min.z) { min.z = coords[i].z; } } return(min); }
public T this[CoordDir c] { get { #if WDEBUG if (c.x < cube.offset.x || c.x >= cube.offset.x + cube.size.x) { throw new System.ArgumentOutOfRangeException("c", "Index Out Of Range (" + cube.offset.x + "-" + cube.offset.x + cube.size.x + "): " + c.x); } if (c.y < cube.offset.y || c.y >= cube.offset.y + cube.size.y) { throw new System.ArgumentOutOfRangeException("c", "Index Out Of Range (" + cube.offset.y + "-" + cube.offset.y + cube.size.y + "): " + c.y); } if (c.z < cube.offset.z || c.z >= cube.offset.z + cube.size.z) { throw new System.ArgumentOutOfRangeException("c", "Index Out Of Range (" + cube.offset.z + "-" + cube.offset.z + cube.size.z + "): " + c.z); } #endif return(array[(c.z - cube.offset.z) * cube.size.x * cube.size.y + (c.y - cube.offset.y) * cube.size.x + c.x - cube.offset.x]); } set { #if WDEBUG if (c.x < cube.offset.x || c.x >= cube.offset.x + cube.size.x) { throw new System.ArgumentOutOfRangeException("x", "Index Out Of Range (" + cube.offset.x + "-" + cube.offset.x + cube.size.x + "): " + c.x); } if (c.y < cube.offset.y || c.y >= cube.offset.y + cube.size.y) { throw new System.ArgumentOutOfRangeException("y", "Index Out Of Range (" + cube.offset.y + "-" + cube.offset.y + cube.size.y + "): " + c.y); } if (c.z < cube.offset.z || c.z >= cube.offset.z + cube.size.z) { throw new System.ArgumentOutOfRangeException("z", "Index Out Of Range (" + cube.offset.z + "-" + cube.offset.z + cube.size.z + "): " + c.z); } #endif array[(c.z - cube.offset.z) * cube.size.x * cube.size.y + (c.y - cube.offset.y) * cube.size.x + c.x - cube.offset.x] = value; } }
public CoordDir(CoordDir c, byte d) { this.x = c.x; this.y = c.y; this.z = c.z; this.dir = d; }
public bool Contains(CoordDir c) { return(c.x >= offset.x && c.x < offset.x + size.x && c.y >= offset.y && c.y < offset.y + size.y && c.z >= offset.z && c.z < offset.z + size.z); }
public int this[CoordDir c] { get { return((c.z - offset.z) * size.x * size.y + (c.y - offset.y) * size.x + c.x - offset.x); } }
public CoordCube(int offsetX, int offsetY, int offsetZ, int sizeX, int sizeY, int sizeZ) { this.offset = new CoordDir(offsetX, offsetY, offsetZ, 7); this.size = new CoordDir(sizeX, sizeY, sizeZ, 7); }
public CoordCube(CoordDir offset, CoordDir size) { this.offset = offset; this.size = size; }