From 0f615bee9d3c34f13fe9600ce368f018fb1b746c Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 16 Mar 2021 11:34:58 +0800 Subject: [PATCH] add neighbor_compatibilities --- src/experimental/tiles_wfc.scad | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/experimental/tiles_wfc.scad b/src/experimental/tiles_wfc.scad index 51c03fe0..be51794b 100644 --- a/src/experimental/tiles_wfc.scad +++ b/src/experimental/tiles_wfc.scad @@ -185,6 +185,20 @@ function _wf_coord_min_entropy(wf, coords, coords_leng, entropy, entropyCoord, i _wf_coord_min_entropy(wf, coords, coords_leng, entropy, entropyCoord, i + 1); +// TileMap + +function neighbor_dirs(x, y, width, height) = + concat( + x > 0 ? [[-1, 0]] : [], // left + x < width - 1 ? [[ 1, 0]] : [], // right + y > 0 ? [[ 0, -1]] : [], // top + y < height - 1 ? [[ 0, 1]] : [] // bottom + ); + +function neighbor_compatibilities(sample, x, y, width, height) = + let(me = sample[y][x]) + [for(dir = neighbor_dirs(x, y, width, height)) [me, sample[y + dir[1]][x + dir[0]], dir]]; + width = len(sample[0]); height = len(sample); @@ -203,3 +217,4 @@ for(y = [0:height - 1]) { } assert(wf_entropy(wf, 0, 0) == 1.458879520793018); assert(wf_coord_min_entropy(wf_collapse(wf, 0, 0)) != [0, 0]); +echo(neighbor_compatibilities(sample, 0, 0, width, height)); \ No newline at end of file