mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-09 08:16:50 +02:00
optimization
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
use <../tri_delaunay.scad>;
|
|
||||||
use <../../util/map/hashmap_get.scad>;
|
use <../../util/map/hashmap_get.scad>;
|
||||||
|
|
||||||
function indicesOfCell(iTris, triIndices) =
|
function indicesOfCell(iTris, triIndices) =
|
||||||
_indicesOfCell(iTris, triIndices, len(iTris), [], iTris[0][0]);
|
let(leng = len(iTris))
|
||||||
|
[
|
||||||
function _indicesOfCell(iTris, triIndices, leng, indices, vi, i = 0) =
|
for(i = 0, vi = iTris[0][0], t = iTris[search([vi], iTris)[0]];
|
||||||
i == leng ? indices :
|
i < leng;
|
||||||
let(
|
i = i + 1,
|
||||||
t = iTris[search([vi], iTris)[0]],
|
vi = t[1],
|
||||||
nIndices = concat(indices, hashmap_get(triIndices, t))
|
t = i < leng ? iTris[search([vi], iTris)[0]] : undef)
|
||||||
)
|
hashmap_get(triIndices, t)
|
||||||
_indicesOfCell(iTris, triIndices, leng, nIndices, t[1], i + 1);
|
];
|
||||||
|
@@ -24,36 +24,24 @@ function tri_delaunay_voronoi(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 = i_range)
|
for(tri = tris)
|
||||||
let(
|
let(a = tri[0], b = tri[1], c = tri[2])
|
||||||
tris_i = tris[i],
|
each [[a, [b, c, a]], [b, [c, a, b]], [c, tri]]
|
||||||
a = tris_i[0],
|
|
||||||
b = tris_i[1],
|
|
||||||
c = tris_i[2],
|
|
||||||
rt1 = [b, c, a],
|
|
||||||
rt2 = [c, a, b],
|
|
||||||
rt3 = [a, b, c]
|
|
||||||
)
|
|
||||||
each [[a, rt1], [b, rt2], [c, rt3]]
|
|
||||||
],
|
],
|
||||||
connectedTris = [
|
connectedTris = [
|
||||||
for(i = [0:coords_leng - 1])
|
for(i = [0:coords_leng - 1])
|
||||||
[for(i_rt = i_rts) if(i_rt[0] == i) i_rt[1]]
|
[for(j = search(i, i_rts, num_returns_per_match=0)) i_rts[j][1]]
|
||||||
],
|
],
|
||||||
triIndices = hashmap([
|
triIndices = hashmap([
|
||||||
for(i = i_range)
|
for(i = [0:len(tris) - 1])
|
||||||
let(
|
let(
|
||||||
tris_i = tris[i],
|
tri = tris[i],
|
||||||
a = tris_i[0],
|
a = tri[0],
|
||||||
b = tris_i[1],
|
b = tri[1],
|
||||||
c = tris_i[2],
|
c = tri[2]
|
||||||
rt1 = [b, c, a],
|
|
||||||
rt2 = [c, a, b],
|
|
||||||
rt3 = [a, b, c]
|
|
||||||
)
|
)
|
||||||
each [[rt1, i], [rt2, i], [rt3, i]]
|
each [[[b, c, a], i], [[c, a, b], i], [tri, i]]
|
||||||
]),
|
]),
|
||||||
cells = [
|
cells = [
|
||||||
for(i = [4:coords_leng - 1])
|
for(i = [4:coords_leng - 1])
|
||||||
|
Reference in New Issue
Block a user