mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 06:47:46 +02:00
fix hash bugs
This commit is contained in:
@@ -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, indicesOfCell) =
|
function indicesOfCell(iTris, triIndices) =
|
||||||
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);
|
_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 :
|
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, 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);
|
||||||
|
@@ -7,15 +7,16 @@ 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],
|
_indices_hash = function(indices) indices[3],
|
||||||
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, hash = _indices_hash)[0]],
|
vertices = [for(t = tris) hashmap_get(circles, t, hash = _indices_hash)[0]],
|
||||||
|
i_range = [0:len(tris) - 1],
|
||||||
i_rts = [
|
i_rts = [
|
||||||
for(i = [0:len(tris) - 1])
|
for(i = i_range)
|
||||||
let(
|
let(
|
||||||
a = tris[i][0],
|
a = tris[i][0],
|
||||||
b = tris[i][1],
|
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]]
|
[for(i_rt = i_rts) if(i_rt[0] == i) i_rt[1]]
|
||||||
],
|
],
|
||||||
triIndices = hashmap([
|
triIndices = hashmap([
|
||||||
for(i = [0:len(tris) - 1])
|
for(i = i_range)
|
||||||
let(
|
let(
|
||||||
a = tris[i][0],
|
a = tris[i][0],
|
||||||
b = tris[i][1],
|
b = tris[i][1],
|
||||||
@@ -41,10 +42,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, _indices_hash)) // counter-clockwise
|
reverse(indicesOfCell(connectedTris[i], triIndices)) // counter-clockwise
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
[for(cell = cells) [for(i = cell) vertices[i]]];
|
[for(cell = cells) [for(i = cell) vertices[i]]];
|
||||||
|
Reference in New Issue
Block a user