1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-19 13:01:37 +02:00
This commit is contained in:
Justin Lin
2022-08-11 09:33:14 +08:00
parent 04e089613a
commit 2cf3ac6781
2 changed files with 32 additions and 67 deletions

View File

@@ -1,36 +0,0 @@
use <../../util/set/hashset_has.scad>
include <../../__comm__/_pt2_hash.scad>
function _mz_tiles_top(x, y) =
let(
nx = x * 2,
ny = y * 2
)
[[nx + 1, ny + 2]];
function _mz_tiles_right(x, y) =
let(
nx = x * 2,
ny = y * 2
)
[[nx + 2, ny + 1]];
function _mz_tiles_top_right(x, y) =
let(
nx = x * 2,
ny = y * 2
)
[[nx + 1, ny + 2], [nx + 2, ny + 1]];
hash = function(p) _pt2_hash(p);
function _mz_tile_type(dots, x, y) =
let(
px = x * 2 + 1,
py = y * 2 + 1,
c1 = !hashset_has(dots, [px, py + 1], hash = hash) ? 1 : 0,
c2 = !hashset_has(dots, [px + 1, py], hash = hash) ? 2 : 0,
c3 = !hashset_has(dots, [px, py - 1], hash = hash) ? 4 : 0,
c4 = !hashset_has(dots, [px - 1, py], hash = hash) ? 8 : 0
)
c1 + c2 + c3 + c4;

View File

@@ -1,52 +1,53 @@
/**
* mz_tiles.scad
*
* @copyright Justin Lin, 2020
* @copyright Justin Lin, 2022
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-mz_tiles.html
*
**/
use <_impl/_mz_tiles_impl.scad>
use <mz_square_get.scad>
use <../util/set/hashset.scad>
include <../__comm__/_pt2_hash.scad>
function mz_tiles(cells, left_border = true, bottom_border = true) =
let(
rows = len(cells),
columns = len(cells[0]),
top_cells = cells[rows - 1],
right_cells = [for(r = [0:rows - 1]) cells[r][columns - 1]],
all = concat(
edges = [
for(y = 0; y <= rows; y = y + 1)
[
for(row = cells, cell = row)
let(
x = cell.x,
y = cell.y,
type = mz_square_get(cell, "t"),
pts = type == "TOP_WALL" ? _mz_tiles_top(x, y) :
type == "RIGHT_WALL" ? _mz_tiles_right(x, y) :
type == "TOP_RIGHT_WALL" || type == "MASK" ? _mz_tiles_top_right(x, y) : []
)
each pts
],
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"))
[x * 2 + 1, type == "RIGHT_WALL" || type == "NO_WALL" ? 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"))
[type == "TOP_WALL" || type == "NO_WALL" ? 1 : 0, y * 2 + 1]
for(x = 0; x <= columns; x = x + 1)
if(y == 0 && x == 0)
[0, 0]
else if(y == 0)
let(type = mz_square_get(cells[rows - 1][x - 1], "t"))
[
bottom_border ? 0 : type == "NO_WALL" || type == "RIGHT_WALL" ? 1 : 0,
0
]
else if(x == 0)
let(type = mz_square_get(cells[y - 1][columns - 1], "t"))
[
0,
left_border ? 0 : type == "NO_WALL" || type == "TOP_WALL" ? 1 : 0
]
else
let(type = mz_square_get(cells[y - 1][x - 1], "t"))
[
type == "NO_WALL" || type == "RIGHT_WALL" ? 1 : 0,
type == "NO_WALL" || type == "TOP_WALL" ? 1 : 0
]
]
),
dot_pts = hashset(all, hash = function(p) _pt2_hash(p))
],
_mz_tile_type = function(edges, cx, cy)
let(x = cx + 1, y = cy + 1)
(edges[y][x][0] == 1 ? 1 : 0) +
(edges[y][x][1] == 1 ? 2 : 0) +
(edges[y - 1][x][0] == 1 ? 4 : 0) +
(edges[y][x - 1][1] == 1 ? 8 : 0)
)
[
for(y = [0:rows - 1], x = [0:columns - 1])
[x, y, _mz_tile_type(dot_pts, x, y)]
[x, y, _mz_tile_type(edges, x, y)]
];