private static bool TryExtract(ITopoArray <Tile> sample, int nx, int ny, int nz, int x, int y, int z, out PatternArray pattern) { var width = sample.Topology.Width; var height = sample.Topology.Height; var depth = sample.Topology.Depth; var values = new Tile[nx, ny, nz]; for (int tx = 0; tx < nx; tx++) { var sx = (x + tx) % width; for (int ty = 0; ty < ny; ty++) { var sy = (y + ty) % height; for (int tz = 0; tz < nz; tz++) { var sz = (z + tz) % depth; var index = sample.Topology.GetIndex(sx, sy, sz); if (!sample.Topology.ContainsIndex(index)) { pattern = default(PatternArray); return(false); } values[tx, ty, tz] = sample.Get(sx, sy, sz); } } } pattern = new PatternArray { Values = values }; return(true); }
public static PatternArray PatternEdge(PatternArray patternArray, int dx, int dy, int dz) { var a = patternArray; var edgeWidth = a.Width - Math.Abs(dx); var ix = Math.Max(0, dx); var edgeHeight = a.Height - Math.Abs(dy); var iy = Math.Max(0, dy); var edgeDepth = a.Depth - Math.Abs(dz); var iz = Math.Max(0, dz); var edge = new PatternArray { Values = new Tile[edgeWidth, edgeHeight, edgeDepth] }; for (var x = 0; x < edgeWidth; x++) { for (var y = 0; y < edgeHeight; y++) { for (var z = 0; z < edgeDepth; z++) { edge.Values[x, y, z] = patternArray.Values[x + ix, y + iy, z + iz]; } } } return edge; }
/** * Return true if the pattern1 is compatible with pattern2 * when pattern2 is at a distance (dy,dx) from pattern1. */ private bool Aggrees(PatternArray a, PatternArray b, int dx, int dy, int dz) { var xmin = dx < 0 ? 0 : dx; var xmax = dx < 0 ? dx + b.Width : a.Width; var ymin = dy < 0 ? 0 : dy; var ymax = dy < 0 ? dy + b.Height : a.Height; var zmin = dz < 0 ? 0 : dz; var zmax = dz < 0 ? dz + b.Depth : a.Depth; for (var x = xmin; x < xmax; x++) { for (var y = ymin; y < ymax; y++) { for (var z = zmin; z < zmax; z++) { if (a.Values[x, y, z] != b.Values[x - dx, y - dy, z - dz]) { return(false); } } } } return(true); }