1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-01 04:20:27 +02:00

fix hash bugs

This commit is contained in:
Justin Lin
2021-05-07 10:32:39 +08:00
parent c59b35fd81
commit a15f98dafb
2 changed files with 11 additions and 10 deletions

View File

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

View File

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