mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-21 05:52:16 +02:00
refactor
This commit is contained in:
@@ -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;
|
|
@@ -1,52 +1,53 @@
|
|||||||
/**
|
/**
|
||||||
* mz_tiles.scad
|
* mz_tiles.scad
|
||||||
*
|
*
|
||||||
* @copyright Justin Lin, 2020
|
* @copyright Justin Lin, 2022
|
||||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||||
*
|
*
|
||||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-mz_tiles.html
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-mz_tiles.html
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
use <_impl/_mz_tiles_impl.scad>
|
|
||||||
use <mz_square_get.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) =
|
function mz_tiles(cells, left_border = true, bottom_border = true) =
|
||||||
let(
|
let(
|
||||||
rows = len(cells),
|
rows = len(cells),
|
||||||
columns = len(cells[0]),
|
columns = len(cells[0]),
|
||||||
top_cells = cells[rows - 1],
|
edges = [
|
||||||
right_cells = [for(r = [0:rows - 1]) cells[r][columns - 1]],
|
for(y = 0; y <= rows; y = y + 1)
|
||||||
all = concat(
|
|
||||||
[
|
[
|
||||||
for(row = cells, cell = row)
|
for(x = 0; x <= columns; x = x + 1)
|
||||||
let(
|
if(y == 0 && x == 0)
|
||||||
x = cell.x,
|
[0, 0]
|
||||||
y = cell.y,
|
else if(y == 0)
|
||||||
type = mz_square_get(cell, "t"),
|
let(type = mz_square_get(cells[rows - 1][x - 1], "t"))
|
||||||
pts = type == "TOP_WALL" ? _mz_tiles_top(x, y) :
|
[
|
||||||
type == "RIGHT_WALL" ? _mz_tiles_right(x, y) :
|
bottom_border ? 0 : type == "NO_WALL" || type == "RIGHT_WALL" ? 1 : 0,
|
||||||
type == "TOP_RIGHT_WALL" || type == "MASK" ? _mz_tiles_top_right(x, y) : []
|
0
|
||||||
)
|
|
||||||
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]
|
|
||||||
]
|
]
|
||||||
),
|
else if(x == 0)
|
||||||
dot_pts = hashset(all, hash = function(p) _pt2_hash(p))
|
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
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
_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])
|
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)]
|
||||||
];
|
];
|
Reference in New Issue
Block a user