mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-01 04:20:27 +02:00
refactor: border params are flexible
This commit is contained in:
@@ -12,19 +12,16 @@ use <../__comm__/_pt2_hash.scad>;
|
||||
use <_impl/_mz_wang_tiles_impl.scad>;
|
||||
use <mz_square_get.scad>;
|
||||
use <../util/find_index.scad>;
|
||||
use <../util/every.scad>;
|
||||
use <../util/sort.scad>;
|
||||
use <../util/set/hashset.scad>;
|
||||
use <../util/set/hashset_elems.scad>;
|
||||
|
||||
function mz_wang_tiles(cells) =
|
||||
function mz_wang_tiles(cells, left_border = true, bottom_border = true) =
|
||||
let(
|
||||
columns = find_index(cells, function(cell) cell.y != 0),
|
||||
rows = len(cells) / columns,
|
||||
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"),
|
||||
left_border = every(right_cells, function(cell) let(t = mz_square_get(cell, "t")) t == "TOP_RIGHT_WALL" || t == "MASK"),
|
||||
bottom_border = every(top_cells, function(cell) let(t = mz_square_get(cell, "t")) t == "TOP_RIGHT_WALL" || t == "TOP_WALL" || t == "MASK"),
|
||||
all = concat(
|
||||
[
|
||||
for(cell = cells)
|
||||
@@ -38,15 +35,15 @@ function mz_wang_tiles(cells) =
|
||||
)
|
||||
each pts
|
||||
],
|
||||
left_border ? [for(y = [0:rows - 1]) [0, y * 2 + 1]] : [
|
||||
for(y = [0:rows - 1])
|
||||
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]
|
||||
],
|
||||
bottom_border ? [for(x = [0:columns - 1]) [x * 2 + 1, 0]] : [
|
||||
for(x = [0:columns - 1])
|
||||
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]
|
||||
],
|
||||
left_border ? [for(y = [0:rows - 1]) [0, y * 2 + 1]] : [
|
||||
for(y = [0:rows - 1])
|
||||
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]
|
||||
]
|
||||
),
|
||||
dot_pts = sort(hashset_elems(hashset(all, hash = function(p) _pt2_hash(p))), by = "vt")
|
||||
|
Reference in New Issue
Block a user