diff --git a/src/triangle/_impl/_tri_delaunay_voronoi_impl.scad b/src/triangle/_impl/_tri_delaunay_voronoi_impl.scad index 9f392a71..9b91bb91 100644 --- a/src/triangle/_impl/_tri_delaunay_voronoi_impl.scad +++ b/src/triangle/_impl/_tri_delaunay_voronoi_impl.scad @@ -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); diff --git a/src/triangle/tri_delaunay_voronoi.scad b/src/triangle/tri_delaunay_voronoi.scad index 7e75845b..599e6773 100644 --- a/src/triangle/tri_delaunay_voronoi.scad +++ b/src/triangle/tri_delaunay_voronoi.scad @@ -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]]];