1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-15 03:05:41 +02:00

use indicesOfCell

This commit is contained in:
Justin Lin
2021-05-06 19:10:55 +08:00
parent 003a13c247
commit d4dbbc7952
2 changed files with 9 additions and 8 deletions

View File

@@ -2,18 +2,18 @@ use <../tri_delaunay.scad>;
use <../../util/map/hashmap_get.scad>; use <../../util/map/hashmap_get.scad>;
use <../../util/find_index.scad>; use <../../util/find_index.scad>;
function indicesOfCell(iTris, triIndices) = function indicesOfCell(iTris, triIndices, indicesOfCell) =
let( let(
vi = iTris[0][0], vi = iTris[0][0],
indices = [], indices = [],
leng = len(iTris) leng = len(iTris)
) )
_indicesOfCell(iTris, triIndices, leng, indices, vi); _indicesOfCell(iTris, triIndices, leng, indices, vi, indicesOfCell);
function _indicesOfCell(iTris, triIndices, leng, indices, vi, i = 0) = function _indicesOfCell(iTris, triIndices, leng, indices, vi, indicesOfCell, i = 0) =
i == leng ? indices : i == leng ? indices :
let( let(
t = iTris[find_index(iTris, function(t) t[0] == vi)], t = iTris[find_index(iTris, function(t) t[0] == vi)],
nIndices = concat(indices, hashmap_get(triIndices, t)) nIndices = concat(indices, hashmap_get(triIndices, t, hash = indicesOfCell))
) )
_indicesOfCell(iTris, triIndices, leng, nIndices, t[1], i + 1); _indicesOfCell(iTris, triIndices, leng, nIndices, t[1], indicesOfCell, i + 1);

View File

@@ -7,12 +7,13 @@ use <../util/reverse.scad>;
function tri_delaunay_voronoi(d) = function tri_delaunay_voronoi(d) =
let( let(
_indices_hash = function(indices) indices[0] * 961 + indices[1] * 31 + indices[2],
coords = delaunay_coords(d), coords = delaunay_coords(d),
coords_leng = len(coords), coords_leng = len(coords),
circles = delaunay_circles(d), circles = delaunay_circles(d),
tris = hashmap_keys(delaunay_triangles(d)), tris = hashmap_keys(delaunay_triangles(d)),
// circumcircle centers // circumcircle centers
vertices = [for(t = tris) hashmap_get(circles, t)[0]], vertices = [for(t = tris) hashmap_get(circles, t, hash = _indices_hash)[0]],
i_rts = [ i_rts = [
for(i = [0:len(tris) - 1]) for(i = [0:len(tris) - 1])
let( let(
@@ -40,10 +41,10 @@ function tri_delaunay_voronoi(d) =
rt3 = [a, b, c] rt3 = [a, b, c]
) )
each [[rt1, i], [rt2, i], [rt3, i]] each [[rt1, i], [rt2, i], [rt3, i]]
]), ], hash = _indices_hash),
cells = [ cells = [
for(i = [4:coords_leng - 1]) for(i = [4:coords_leng - 1])
reverse(indicesOfCell(connectedTris[i], triIndices)) // counter-clockwise reverse(indicesOfCell(connectedTris[i], triIndices, _indices_hash)) // counter-clockwise
] ]
) )
[for(cell = cells) [for(i = cell) vertices[i]]]; [for(cell = cells) [for(i = cell) vertices[i]]];