diff --git a/examples/maze/cube_maze.scad b/examples/maze/cube_maze.scad index 8212f4db..462ec430 100644 --- a/examples/maze/cube_maze.scad +++ b/examples/maze/cube_maze.scad @@ -21,7 +21,7 @@ module cube_maze(maze_rows, block_width, wall_thickness, inner_cube, travel_all) module one_maze() { translate([origin, origin, half_cube_size]) linear_extrude(wall_thickness) - square_maze([1, 1], maze_rows, block_width, wall_thickness); + square_maze(maze_rows, block_width, wall_thickness); } one_maze(); diff --git a/examples/maze/heart_maze.scad b/examples/maze/heart_maze.scad index a6fa74c5..8d82c95b 100644 --- a/examples/maze/heart_maze.scad +++ b/examples/maze/heart_maze.scad @@ -60,9 +60,9 @@ module heart_to_heart_wall(radius, length, angle, thickness) { module heart_maze(maze, radius, cblocks, levels, thickness = 1) { function no_wall(block) = get_wall_type(block) == "NO_WALL"; - function upper_wall(block) = get_wall_type(block) == "UPPER_WALL"; + function top_wall(block) = get_wall_type(block) == "TOP_WALL"; function right_wall(block) = get_wall_type(block) == "RIGHT_WALL"; - function upper_right_wall(block) = get_wall_type(block) == "UPPER_RIGHT_WALL"; + function top_right_wall(block) = get_wall_type(block) == "TOP_RIGHT_WALL"; function get_x(block) = mz_square_get(block, "x"); function get_y(block) = mz_square_get(block, "y"); @@ -80,12 +80,12 @@ module heart_maze(maze, radius, cblocks, levels, thickness = 1) { for(i = [0:len(maze) - 1]) { block = maze[i]; - cr = get_x(block); - cc = get_y(block) - 1; + cr = get_x(block) + 1; + cc = get_y(block); angle = cc * arc_angle; - if(upper_wall(block) || upper_right_wall(block)) { + if(top_wall(block) || top_right_wall(block)) { heart_to_heart_wall(r * cr, r, cc * arc_angle , thickness); } } @@ -95,10 +95,10 @@ module heart_maze(maze, radius, cblocks, levels, thickness = 1) { // road to the next level for(i = [0:len(maze) - 1]) { block = maze[i]; - cr = get_x(block); - cc = get_y(block) - 1; + cr = get_x(block) + 1; + cc = get_y(block); - if(no_wall(block) || upper_wall(block)) { + if(no_wall(block) || top_wall(block)) { ring_heart_sector(r * (cr + 1), (cc + 0.5) * arc_angle , thickness, thickness * 0.75); } } diff --git a/examples/maze/maze_masking.scad b/examples/maze/maze_masking.scad index d8d3efe0..04a4e45a 100644 --- a/examples/maze/maze_masking.scad +++ b/examples/maze/maze_masking.scad @@ -3,7 +3,7 @@ use ; use ; use ; -start = [2, 2]; +start = [1, 1]; mask = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], diff --git a/examples/maze/pyramid_maze.scad b/examples/maze/pyramid_maze.scad index dcf24584..76dc023e 100644 --- a/examples/maze/pyramid_maze.scad +++ b/examples/maze/pyramid_maze.scad @@ -17,7 +17,7 @@ module pyramid_maze(maze_rows, block_width, wall_thickness) { intersection() { linear_extrude(leng * 2) translate([-half_leng, -half_leng]) - square_maze([1, 1], maze_rows, block_width, wall_thickness); + square_maze(maze_rows, block_width, wall_thickness); pyramid(leng + wall_thickness); } diff --git a/examples/maze/random_scala.scad b/examples/maze/random_scala.scad index 3508361c..95322251 100644 --- a/examples/maze/random_scala.scad +++ b/examples/maze/random_scala.scad @@ -21,7 +21,7 @@ module random_scala(rows, columns, start, width, height) { random_scala( rows = 2, columns = 3, - start = [1, 1], + start = [0, 0], width = .5, height = .25 ); \ No newline at end of file diff --git a/examples/maze/regular_polygon_maze.scad b/examples/maze/regular_polygon_maze.scad index 27a98fa6..9fe2bf47 100644 --- a/examples/maze/regular_polygon_maze.scad +++ b/examples/maze/regular_polygon_maze.scad @@ -26,7 +26,7 @@ module ring_regular_polygon_sector(radius, angle, thickness, width, sides) { } module regular_polygon_to_polygon_wall(radius, length, angle, thickness, sides) { - intersection() { + intersection() { difference() { circle(radius + length, $fn = sides); circle(radius, $fn = sides); @@ -38,9 +38,9 @@ module regular_polygon_to_polygon_wall(radius, length, angle, thickness, sides) module regular_polygon_maze(radius, cblocks, levels, thickness = 1, sides) { function no_wall(block) = get_wall_type(block) == "NO_WALL"; - function upper_wall(block) = get_wall_type(block) == "UPPER_WALL"; + function top_wall(block) = get_wall_type(block) == "TOP_WALL"; function right_wall(block) = get_wall_type(block) == "RIGHT_WALL"; - function upper_right_wall(block) = get_wall_type(block) == "UPPER_RIGHT_WALL"; + function top_right_wall(block) = get_wall_type(block) == "TOP_RIGHT_WALL"; function get_x(block) = mz_square_get(block, "x"); function get_y(block) = mz_square_get(block, "y"); @@ -62,12 +62,12 @@ module regular_polygon_maze(radius, cblocks, levels, thickness = 1, sides) { for(i = [0:len(maze) - 1]) { block = maze[i]; - cr = get_x(block); - cc = get_y(block) - 1; + cr = get_x(block) + 1; + cc = get_y(block); angle = cc * arc_angle; - if(upper_wall(block) || upper_right_wall(block)) { + if(top_wall(block) || top_right_wall(block)) { regular_polygon_to_polygon_wall(r * cr, r, cc * arc_angle , thickness, sides); } } @@ -80,10 +80,10 @@ module regular_polygon_maze(radius, cblocks, levels, thickness = 1, sides) { // road to the next level for(i = [0:len(maze) - 1]) { block = maze[i]; - cr = get_x(block); - cc = get_y(block) - 1; + cr = get_x(block) + 1; + cc = get_y(block); - if(no_wall(block) || upper_wall(block)) { + if(no_wall(block) || top_wall(block)) { ring_regular_polygon_sector(r * (cr + 1), (cc + 0.5) * arc_angle , thickness, thickness * 0.75 , sides); } } diff --git a/examples/maze/senbon_torii.scad b/examples/maze/senbon_torii.scad index a40d54a3..151460d1 100644 --- a/examples/maze/senbon_torii.scad +++ b/examples/maze/senbon_torii.scad @@ -2,7 +2,7 @@ use ; rows = 2; columns = 2; -start = [1, 1]; +start = [0, 0]; width = .5; height = .05; test_torii = "FALSE"; // [TRUE, FALSE] diff --git a/examples/maze/step_pyramid_maze.scad b/examples/maze/step_pyramid_maze.scad index 0947fb50..36eb72a6 100644 --- a/examples/maze/step_pyramid_maze.scad +++ b/examples/maze/step_pyramid_maze.scad @@ -40,7 +40,7 @@ module step_pyramid_maze(maze_rows, block_width, stairs_width) { translate([-(maze_rows * block_width) / 2, -(maze_rows * block_width) / 2, 0]) difference() { - square_maze([1, 1], maze_rows, block_width, stairs_width); + square_maze(maze_rows, block_width, stairs_width); // entry translate([0, stairs_width]) diff --git a/examples/maze/stereographic_square_maze.scad b/examples/maze/stereographic_square_maze.scad index a6d316dc..b69a7c7c 100644 --- a/examples/maze/stereographic_square_maze.scad +++ b/examples/maze/stereographic_square_maze.scad @@ -13,7 +13,7 @@ module stereographic_projection_maze2(maze_rows, block_width, wall_thickness, fn module maze() { translate([-block_width * maze_rows / 2, -block_width * maze_rows / 2, 0]) - square_maze([1, 1], maze_rows, block_width, wall_thickness); + square_maze(maze_rows, block_width, wall_thickness); } stereographic_extrude(shadow_side_leng = length, $fn = fn) diff --git a/src/maze/_impl/_mz_blocks_impl.scad b/src/maze/_impl/_mz_blocks_impl.scad index 33832467..f3fd5057 100644 --- a/src/maze/_impl/_mz_blocks_impl.scad +++ b/src/maze/_impl/_mz_blocks_impl.scad @@ -2,7 +2,7 @@ use <_mz_comm.scad>; // find out the index of a block with the position (x, y) function indexOf(x, y, maze, i = 0) = - i > len(maze) ? -1 : ( + i == len(maze) ? -1 : ( [get_x(maze[i]), get_y(maze[i])] == [x, y] ? i : indexOf(x, y, maze, i + 1) ); @@ -12,8 +12,8 @@ function visited(x, y, maze) = maze[indexOf(x, y, maze)][3]; // is (x, y) visitable? function visitable(x, y, maze, rows, columns) = - y > 0 && y <= rows && // y bound - x > 0 && x <= columns && // x bound + y >= 0 && y < rows && // y bound + x >= 0 && x < columns && // x bound !visited(x, y, maze); // unvisited // setting (x, y) as being visited @@ -58,23 +58,13 @@ function rand_dirs(c, seed) = _next_x_table = [1, 0, -1, 0]; function next_x(x, dir, columns, wrapping) = let(nx = x + _next_x_table[dir]) - wrapping ? - nx < 1 ? nx + columns : ( - nx > columns ? nx % columns : nx - ) - : - nx; + wrapping ? (nx < 0 ? nx + columns : nx % columns) : nx; // get y value by dir _next_y_table = [0, 1, 0, -1]; function next_y(y, dir, rows, wrapping) = let(ny = y + _next_y_table[dir]) - wrapping ? - ny < 1 ? ny + rows : ( - ny > rows ? ny % rows : ny - ) - : - ny; + wrapping ? (ny < 0 ? ny + rows : ny % rows) : ny; // go right and carve the right wall function carve_right(x, y, maze) = [ @@ -94,7 +84,7 @@ function carve_top(x, y, maze) = [ function carve_left(x, y, maze, columns) = let( x_minus_one = x - 1, - nx = x_minus_one < 1 ? x_minus_one + columns : x_minus_one + nx = x_minus_one < 0 ? x_minus_one + columns : x_minus_one ) [for(b = maze) [get_x(b), get_y(b)] == [nx, y] ? [nx, y, 1, 0] : b]; @@ -102,7 +92,7 @@ function carve_left(x, y, maze, columns) = function carve_bottom(x, y, maze, rows) = let( y_minus_one = y - 1, - ny = y_minus_one < 1 ? y_minus_one + rows : y_minus_one + ny = y_minus_one < 0 ? y_minus_one + rows : y_minus_one ) [for(b = maze) [get_x(b), get_y(b)] == [x, ny] ? [x, ny, 2, 0] : b]; diff --git a/src/maze/_impl/_mz_hamiltonian_impl.scad b/src/maze/_impl/_mz_hamiltonian_impl.scad index 4b7a6885..110d4a62 100644 --- a/src/maze/_impl/_mz_hamiltonian_impl.scad +++ b/src/maze/_impl/_mz_hamiltonian_impl.scad @@ -2,22 +2,22 @@ use <../../util/has.scad>; function _mz_hamiltonian_top(x, y) = let( - nx = (x - 1) * 2, - ny = (y - 1) * 2 + nx = x * 2, + ny = y * 2 ) [[nx, ny + 2], [nx + 1, ny + 2], [nx + 2, ny + 2]]; function _mz_hamiltonian_right(x, y) = let( - nx = (x - 1) * 2, - ny = (y - 1) * 2 + nx = x * 2, + ny = y * 2 ) [[nx + 2, ny + 2], [nx + 2, ny + 1], [nx + 2, ny]]; function _mz_hamiltonian_top_right(x, y) = let( - nx = (x - 1) * 2, - ny = (y - 1) * 2 + nx = x * 2, + ny = y * 2 ) [[nx, ny + 2], [nx + 1, ny + 2], [nx + 2, ny + 2], [nx + 2, ny + 1], [nx + 2, ny]]; diff --git a/src/maze/_impl/_mz_hex_walls.scad b/src/maze/_impl/_mz_hex_walls.scad index 3fb0d0ec..0e153a79 100644 --- a/src/maze/_impl/_mz_hex_walls.scad +++ b/src/maze/_impl/_mz_hex_walls.scad @@ -33,8 +33,8 @@ function _row_wall(cell_radius, x_cell, y_cell) = function _build_cell(cell_radius, block) = let( - x = _get_x(block) - 1, - y = _get_y(block) - 1, + x = _get_x(block), + y = _get_y(block), walls = concat( _row_wall(cell_radius, x, y), [_is_top_wall(block) || _is_top_right_wall(block) ? _top(cell_radius) : []], diff --git a/src/maze/_impl/_mz_initialize.scad b/src/maze/_impl/_mz_initialize.scad index b365a28c..f6c20953 100644 --- a/src/maze/_impl/_mz_initialize.scad +++ b/src/maze/_impl/_mz_initialize.scad @@ -2,8 +2,8 @@ use <_mz_comm.scad>; // create a starting maze for being visited later. function _rc_maze(rows, columns) = [ - for(y = [1:rows]) - for(x = [1:columns]) + for(y = [0:rows - 1]) + for(x = [0:columns - 1]) block( x, y, // all blocks have top and right walls @@ -19,9 +19,9 @@ function _mz_mask(mask) = columns = len(mask[0]) ) [ - for(y = [1:rows]) - for(x = [1:columns]) - mask[rows - y][x - 1] == 0 ? + for(y = [0:rows - 1]) + for(x = [0:columns - 1]) + mask[rows - y - 1][x] == 0 ? block( x, y, 4, // mask @@ -31,8 +31,7 @@ function _mz_mask(mask) = block( x, y, // all blocks have top and right walls - 3, - // unvisited + 3, // unvisited false ) ]; \ No newline at end of file diff --git a/src/maze/_impl/_mz_square_walls_impl.scad b/src/maze/_impl/_mz_square_walls_impl.scad index d63ee2bd..26961f25 100644 --- a/src/maze/_impl/_mz_square_walls_impl.scad +++ b/src/maze/_impl/_mz_square_walls_impl.scad @@ -2,7 +2,7 @@ use <_mz_comm.scad>; function _square_walls(block, block_width) = let( - loc = [get_x(block) - 1, get_y(block) - 1] * block_width, + loc = [get_x(block), get_y(block)] * block_width, top = top_wall(block) || top_right_wall(block) ? [[0, block_width] + loc, [block_width, block_width] + loc] : [], right = right_wall(block) || top_right_wall(block) ? [[block_width, block_width] + loc, [block_width, 0] + loc] : [] ) diff --git a/src/maze/mz_hamiltonian.scad b/src/maze/mz_hamiltonian.scad index 4b5c17dc..ed533281 100644 --- a/src/maze/mz_hamiltonian.scad +++ b/src/maze/mz_hamiltonian.scad @@ -28,4 +28,4 @@ function mz_hamiltonian(rows, columns, start, seed) = ), dot_pts = dedup(sort(all, by = "vt"), sorted = true) ) - _mz_hamiltonian_travel(dot_pts, start + [-1, -1], rows * columns * 4); \ No newline at end of file + _mz_hamiltonian_travel(dot_pts, start, rows * columns * 4); \ No newline at end of file diff --git a/src/maze/mz_square_blocks.scad b/src/maze/mz_square_blocks.scad index 1644aa2c..cf51a9d7 100644 --- a/src/maze/mz_square_blocks.scad +++ b/src/maze/mz_square_blocks.scad @@ -1,7 +1,7 @@ use <_impl/_mz_blocks_impl.scad>; use ; -function mz_square_blocks(rows, columns, start = [1, 1], maze, x_wrapping = false, y_wrapping = false, seed) = +function mz_square_blocks(rows, columns, start = [0, 0], maze, x_wrapping = false, y_wrapping = false, seed) = go_maze( start[0], start[1], // starting point is_undef(maze) ? mz_square_initialize(rows, columns) : maze,