mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-24 15:22:53 +02:00
refactor: accept cells
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use <maze/mz_square_initialize.scad>;
|
use <maze/mz_square_initialize.scad>;
|
||||||
|
use <maze/mz_square_cells.scad>;
|
||||||
use <maze/mz_wang_tiles.scad>;
|
use <maze/mz_wang_tiles.scad>;
|
||||||
use <util/rand.scad>;
|
use <util/rand.scad>;
|
||||||
use <city_tile.scad>;
|
use <city_tile.scad>;
|
||||||
@@ -15,10 +16,10 @@ module maze_city(rows, columns, skyscraper_prs) {
|
|||||||
rand() < skyscraper_prs ? 0 : 1]
|
rand() < skyscraper_prs ? 0 : 1]
|
||||||
];
|
];
|
||||||
|
|
||||||
tiles = mz_wang_tiles(
|
cells = mz_square_cells(rows, columns, [0, 0], init_cells = mz_square_initialize(rows, columns, mask));
|
||||||
rows, columns, [0, 0],
|
|
||||||
init_cells = mz_square_initialize(rows, columns, mask)
|
tiles = mz_wang_tiles(cells);
|
||||||
);
|
|
||||||
tile_width = 30;
|
tile_width = 30;
|
||||||
for(tile = tiles) {
|
for(tile = tiles) {
|
||||||
translate([tile.x, tile.y] * tile_width)
|
translate([tile.x, tile.y] * tile_width)
|
||||||
|
@@ -10,22 +10,16 @@
|
|||||||
|
|
||||||
use <../__comm__/_pt2_hash.scad>;
|
use <../__comm__/_pt2_hash.scad>;
|
||||||
use <_impl/_mz_wang_tiles_impl.scad>;
|
use <_impl/_mz_wang_tiles_impl.scad>;
|
||||||
use <mz_square_cells.scad>;
|
|
||||||
use <mz_square_get.scad>;
|
use <mz_square_get.scad>;
|
||||||
|
use <../util/find_index.scad>;
|
||||||
use <../util/sort.scad>;
|
use <../util/sort.scad>;
|
||||||
use <../util/set/hashset.scad>;
|
use <../util/set/hashset.scad>;
|
||||||
use <../util/set/hashset_elems.scad>;
|
use <../util/set/hashset_elems.scad>;
|
||||||
|
|
||||||
function mz_wang_tiles(rows, columns, start = [0, 0], init_cells, x_wrapping = false, y_wrapping = false, seed) =
|
function mz_wang_tiles(cells, left_border = true, bottom_border = true) =
|
||||||
let(
|
let(
|
||||||
cells = mz_square_cells(
|
columns = find_index(cells, function(cell) cell.y != 0),
|
||||||
rows, columns,
|
rows = len(cells) / columns,
|
||||||
start,
|
|
||||||
init_cells,
|
|
||||||
x_wrapping,
|
|
||||||
y_wrapping,
|
|
||||||
seed
|
|
||||||
),
|
|
||||||
top_cells = sort([for(cell = cells) if(cell.y == rows - 1) cell], by = "x"),
|
top_cells = sort([for(cell = cells) if(cell.y == rows - 1) cell], by = "x"),
|
||||||
right_cells = sort([for(cell = cells) if(cell.x == columns - 1) cell], by = "y"),
|
right_cells = sort([for(cell = cells) if(cell.x == columns - 1) cell], by = "y"),
|
||||||
all = concat(
|
all = concat(
|
||||||
@@ -41,16 +35,16 @@ function mz_wang_tiles(rows, columns, start = [0, 0], init_cells, x_wrapping = f
|
|||||||
)
|
)
|
||||||
each pts
|
each pts
|
||||||
],
|
],
|
||||||
y_wrapping ? [
|
bottom_border ? [for(x = [0:columns - 1]) [x * 2 + 1, 0]] : [
|
||||||
for(x = [0:columns - 1])
|
for(x = [0:columns - 1])
|
||||||
let(type = mz_square_get(top_cells[x], "t"))
|
let(type = mz_square_get(top_cells[x], "t"))
|
||||||
if(type == "RIGHT_WALL" || type == "NO_WALL") [x * 2 + 1, 1] else [x * 2 + 1, 0]
|
if(type == "RIGHT_WALL" || type == "NO_WALL") [x * 2 + 1, 1] else [x * 2 + 1, 0]
|
||||||
] : [for(x = [0:columns - 1]) [x * 2 + 1, 0]],
|
],
|
||||||
x_wrapping ? [
|
left_border ? [for(y = [0:rows - 1]) [0, y * 2 + 1]] : [
|
||||||
for(y = [0:rows - 1])
|
for(y = [0:rows - 1])
|
||||||
let(type = mz_square_get(right_cells[y], "t"))
|
let(type = mz_square_get(right_cells[y], "t"))
|
||||||
if(type == "TOP_WALL" || type == "NO_WALL") [1, y * 2 + 1] else [0, y * 2 + 1]
|
if(type == "TOP_WALL" || type == "NO_WALL") [1, y * 2 + 1] else [0, y * 2 + 1]
|
||||||
] : [for(y = [0:rows - 1]) [0, y * 2 + 1]]
|
]
|
||||||
),
|
),
|
||||||
dot_pts = sort(hashset_elems(hashset(all, hash = function(p) _pt2_hash(p))), by = "vt")
|
dot_pts = sort(hashset_elems(hashset(all, hash = function(p) _pt2_hash(p))), by = "vt")
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user