public object GetCellValue(Int2 gridCoord, LayerId layerId) { Int2 chunkCoord = GetChunkCoord(gridCoord, chunkWidth, chunkHeight); ChunkData chunk; if (TryGetChunkData(chunkCoord, out chunk)) { int index = GetCellIndex(gridCoord, chunkWidth, chunkHeight); IDataBuffer buffer = chunk.GetBuffer(layerId); return(buffer.GetValue(index)); } else { return(0); } }
/// <summary> /// Constructs a string representing the contents of this ndarray, formatted properly and somewhat customisable. /// </summary> /// <returns>A fancy string representing the contents of this ndarray.</returns> public string ToString(ToStringElement toStringElement, int dimensionNewLine = 2, bool printSeperator = true) { if (toStringElement == null) { toStringElement = element => element.ToString(); } int rank = Rank; int lastIndex = rank - 1; int openBraces = 0; long[] indices = new long[rank]; long[] shape = Shape; long[] strides = Strides; long length = Length; StringBuilder builder = new StringBuilder(); builder.Append("ndarray with shape " + ArrayUtils.ToString(shape) + ": "); if (dimensionNewLine < rank) { builder.Append('\n'); } for (long i = 0; i < length; i++) { indices = NDArrayUtils.GetIndices(i, shape, strides, indices); for (int y = rank - 1; y >= 0; y--) { if (indices[y] == 0) { builder.Append('['); openBraces++; } else { break; } } builder.Append(toStringElement(Data.GetValue(i))); if (printSeperator && indices[lastIndex] < shape[lastIndex] - 1) { builder.Append(", "); } bool requestNewLine = false; int maxRankNewLine = rank - dimensionNewLine; for (int y = rank - 1; y >= 0; y--) { if (indices[y] == shape[y] - 1) { builder.Append(']'); openBraces--; if (y > 0 && indices[y - 1] != shape[y - 1] - 1) { builder.Append(", "); if (!requestNewLine && y < maxRankNewLine) { requestNewLine = true; } } } else { break; } } if (requestNewLine) { builder.Append("\n "); for (int y = 0; y < openBraces; y++) { builder.Append(' '); } } } return(builder.ToString()); }