From 5b725bd6bb1364bcb81cb1d335f7c9f4e9d83481 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 28 Jul 2022 15:21:02 +0800 Subject: [PATCH] use matrix index convention --- src/__comm__/_convex_hull3.scad | 6 +++--- src/experimental/_impl/_tiles_wfc_impl.scad | 2 +- src/matrix/m_replace.scad | 18 +++++++++--------- src/maze/_impl/_mz_cube_impl.scad | 2 +- src/maze/_impl/_mz_square_cells_impl.scad | 10 +++++----- src/pp/_impl/_pp_poisson2.scad | 2 +- src/pp/_impl/_pp_poisson3.scad | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/__comm__/_convex_hull3.scad b/src/__comm__/_convex_hull3.scad index 97fadf4e..5de1e15c 100644 --- a/src/__comm__/_convex_hull3.scad +++ b/src/__comm__/_convex_hull3.scad @@ -28,9 +28,9 @@ function next_vis(i, pts, cur_faces, cur_faces_leng, next, vis, j = 0) = d = (pts[f0] - pts[i]) * normal(pts, f), nx = d >= 0 ? [each next, f] : next, s = sign(d), - vis1 = m_replace(vis, f1, f0, s), - vis2 = m_replace(vis1, f2, f1, s), - vis3 = m_replace(vis2, f0, f2, s) + vis1 = m_replace(vis, f0, f1, s), + vis2 = m_replace(vis1, f1, f2, s), + vis3 = m_replace(vis2, f2, f0, s) ) next_vis(i, pts, cur_faces, cur_faces_leng, nx, vis3, j + 1); diff --git a/src/experimental/_impl/_tiles_wfc_impl.scad b/src/experimental/_impl/_tiles_wfc_impl.scad index 4bdc88c7..5d11cf51 100644 --- a/src/experimental/_impl/_tiles_wfc_impl.scad +++ b/src/experimental/_impl/_tiles_wfc_impl.scad @@ -70,7 +70,7 @@ function _replaceStatesAt(wf, x, y, states) = wf_width(wf), wf_height(wf), wf_weights(wf), - m_replace(wf_eigenstates(wf), x, y, states) + m_replace(wf_eigenstates(wf), y, x, states) ]; function wf_not_collapsed_coords(wf, notCollaspedCoords) = diff --git a/src/matrix/m_replace.scad b/src/matrix/m_replace.scad index fb838355..d52a8cfe 100644 --- a/src/matrix/m_replace.scad +++ b/src/matrix/m_replace.scad @@ -1,14 +1,14 @@ -function m_replace(m, x, y, value) = +function m_replace(m, i, j, value) = let( - rowY = m[y], - newRowY = [ - for(i = [0:len(rowY) - 1]) - if(i == x) value - else rowY[i] + rowI = m[i], + newRowI = [ + for(c = [0:len(rowI) - 1]) + if(c == j) value + else rowI[c] ] ) [ - for(i = [0:len(m) - 1]) - if(i == y) newRowY - else m[i] + for(r = [0:len(m) - 1]) + if(r == i) newRowI + else m[r] ]; diff --git a/src/maze/_impl/_mz_cube_impl.scad b/src/maze/_impl/_mz_cube_impl.scad index f58fd980..4a751d6a 100644 --- a/src/maze/_impl/_mz_cube_impl.scad +++ b/src/maze/_impl/_mz_cube_impl.scad @@ -11,7 +11,7 @@ function update(cells, cell) = z = cell.z, rowY = [for(c = cells[z][y]) if(c.x == x) cell else c] ) - m_replace(cells, y, z, rowY); + m_replace(cells, z, y, rowY); // is (x, y) visited? function visited(x, y, z, cells) = cells[z][y][x][4]; diff --git a/src/maze/_impl/_mz_square_cells_impl.scad b/src/maze/_impl/_mz_square_cells_impl.scad index 11a30f56..975cba1c 100644 --- a/src/maze/_impl/_mz_square_cells_impl.scad +++ b/src/maze/_impl/_mz_square_cells_impl.scad @@ -14,7 +14,7 @@ function visitable(x, y, cells, rows, columns) = // setting (x, y) as being visited function set_visited(x, y, cells) = - m_replace(cells, x, y, [x, y, get_type(cells[y][x]), VISITED]); + m_replace(cells, y, x, [x, y, get_type(cells[y][x]), VISITED]); // 0(right), 1(top), 2(left), 3(bottom) _rand_dir_table = [ @@ -61,11 +61,11 @@ function next_y(y, dir, rows, wrapping) = // go right and carve the right wall function carve_right(x, y, cells) = - m_replace(cells, x, y, top_right_wall(cells[y][x]) ? [x, y, TOP_WALL, VISITED] : [x, y, NO_WALL, VISITED]); + m_replace(cells, y, x, top_right_wall(cells[y][x]) ? [x, y, TOP_WALL, VISITED] : [x, y, NO_WALL, VISITED]); // go up and carve the top wall function carve_top(x, y, cells) = - m_replace(cells, x, y, top_right_wall(cells[y][x]) ? [x, y, RIGHT_WALL, VISITED] : [x, y, NO_WALL, VISITED]); + m_replace(cells, y, x, top_right_wall(cells[y][x]) ? [x, y, RIGHT_WALL, VISITED] : [x, y, NO_WALL, VISITED]); // go left and carve the right wall of the left cell function carve_left(x, y, cells, columns) = @@ -73,7 +73,7 @@ function carve_left(x, y, cells, columns) = x_minus_one = x - 1, nx = x_minus_one < 0 ? x_minus_one + columns : x_minus_one ) - m_replace(cells, nx, y, [nx, y, TOP_WALL, UNVISITED]); + m_replace(cells, y, nx, [nx, y, TOP_WALL, UNVISITED]); // go down and carve the top wall of the bottom cell function carve_bottom(x, y, cells, rows) = @@ -81,7 +81,7 @@ function carve_bottom(x, y, cells, rows) = y_minus_one = y - 1, ny = y_minus_one < 0 ? y_minus_one + rows : y_minus_one ) - m_replace(cells, x, ny, [x, ny, RIGHT_WALL, UNVISITED]); + m_replace(cells, ny, x, [x, ny, RIGHT_WALL, UNVISITED]); // 0(right), 1(top), 2(left), 3(bottom) function carve(dir, x, y, cells, rows, columns) = diff --git a/src/pp/_impl/_pp_poisson2.scad b/src/pp/_impl/_pp_poisson2.scad index 5a2b199f..d871d095 100644 --- a/src/pp/_impl/_pp_poisson2.scad +++ b/src/pp/_impl/_pp_poisson2.scad @@ -116,7 +116,7 @@ function sampling_trySampleFromOneActive(s, seed) = w = sampling_w(s), x = floor(sample.x / w), y = floor(sample.y / w), - nx_grid = m_replace(sampling_grid(s), x, y, sample) + nx_grid = m_replace(sampling_grid(s), y, x, sample) ) [ sampling_r(s), diff --git a/src/pp/_impl/_pp_poisson3.scad b/src/pp/_impl/_pp_poisson3.scad index e01afa6c..f181294a 100644 --- a/src/pp/_impl/_pp_poisson3.scad +++ b/src/pp/_impl/_pp_poisson3.scad @@ -5,7 +5,7 @@ use <../../util/find_index.scad> function grid_replace(g, x, y, z, p) = [ for(i = [0:len(g) - 1]) - if(i == z) m_replace(g[z], x, y, p) + if(i == z) m_replace(g[z], y, x, p) else g[i] ];