1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-04 13:57:33 +02:00

optimization

This commit is contained in:
Justin Lin
2022-04-29 21:17:05 +08:00
parent bff5b022a7
commit b68d053332

View File

@@ -62,20 +62,21 @@ function delaunay_addpoint(d, p, _indices_hash) =
let( let(
idx = len(delaunay_coords(d)), idx = len(delaunay_coords(d)),
ndelaunay = delaunayAddCoords(d, p), ndelaunay = delaunayAddCoords(d, p),
badTriangles = delaunayBadTriangles(ndelaunay, p, _indices_hash), badTriangles = delaunayBadTriangles(ndelaunay, p, _indices_hash)
boundaries = delaunayBoundaries(ndelaunay, badTriangles, _indices_hash), )
ndelaunay2 = delBadTriangles(ndelaunay, badTriangles, _indices_hash), adjustNeighbors(
newTriangles = [ delBadTriangles(ndelaunay, badTriangles, _indices_hash),
for(b = boundaries) [
for(b = delaunayBoundaries(ndelaunay, badTriangles, _indices_hash))
let(edge = b[0]) let(edge = b[0])
[ [
[idx, edge[0], edge[1], ihash(idx, edge[0], edge[1])], // t [idx, edge[0], edge[1], ihash(idx, edge[0], edge[1])], // t
edge, edge,
b[1] // delaunayTri b[1] // delaunayTri
] ]
] ],
) _indices_hash
adjustNeighbors(ndelaunay2, newTriangles, _indices_hash); );
function adjustNeighbors(d, newTriangles, _indices_hash) = function adjustNeighbors(d, newTriangles, _indices_hash) =
let( let(
@@ -87,7 +88,7 @@ function adjustNeighbors(d, newTriangles, _indices_hash) =
ncs = [ ncs = [
for(nt = newTriangles) for(nt = newTriangles)
let(t = nt[0]) let(t = nt[0])
[t, _tri_circumcircle([coords[t[0]], coords[t[1]], coords[t[2]]])] [t, _tri_circumcircle([for(i = t) coords[i]])]
], ],
nd = [ nd = [
coords, coords,
@@ -122,7 +123,6 @@ function _adjustNeighborsOtri(d, newTriangles, leng, _indices_hash, i = 0) =
function _adjustNeighborsDtri(d, newTriangles, leng, _indices_hash, i = 0) = function _adjustNeighborsDtri(d, newTriangles, leng, _indices_hash, i = 0) =
i == leng ? d : i == leng ? d :
let( let(
t = newTriangles[i][0],
edge = newTriangles[i][1], edge = newTriangles[i][1],
delaunayTri = newTriangles[i][2], delaunayTri = newTriangles[i][2],
rd = is_undef(delaunayTri) ? d : rd = is_undef(delaunayTri) ? d :
@@ -133,7 +133,7 @@ function _adjustNeighborsDtri(d, newTriangles, leng, _indices_hash, i = 0) =
nbri = find_index(neighbors, function(nbr) nbr != undef && contains(nbr, edge[1]) && contains(nbr, edge[0])), nbri = find_index(neighbors, function(nbr) nbr != undef && contains(nbr, edge[1]) && contains(nbr, edge[0])),
nd = nbri == -1 ? d : updateNbrs(d, delaunayTri, [ nd = nbri == -1 ? d : updateNbrs(d, delaunayTri, [
for(j = 0; j < leng_nbrs; j = j + 1) for(j = 0; j < leng_nbrs; j = j + 1)
j == nbri ? t : neighbors[j] j == nbri ? newTriangles[i][0] : neighbors[j]
], _indices_hash) ], _indices_hash)
) )
nd nd
@@ -142,16 +142,14 @@ function _adjustNeighborsDtri(d, newTriangles, leng, _indices_hash, i = 0) =
_adjustNeighborsDtri(rd, newTriangles, leng, _indices_hash, i + 1); _adjustNeighborsDtri(rd, newTriangles, leng, _indices_hash, i + 1);
function updateNbrs(d, delaunayTri, neighbors, _indices_hash) = function updateNbrs(d, delaunayTri, neighbors, _indices_hash) =
let( [
coords = delaunay_coords(d), delaunay_coords(d),
triangles = delaunay_triangles(d), hashmap_put(
circles = delaunay_circles(d), hashmap_del(delaunay_triangles(d), delaunayTri, hash = _indices_hash),
nTriangles = hashmap_put(
hashmap_del(triangles, delaunayTri, hash = _indices_hash),
delaunayTri, neighbors, hash = _indices_hash delaunayTri, neighbors, hash = _indices_hash
) ),
) delaunay_circles(d)
[coords, nTriangles, circles]; ];
function delaunayAddCoords(d, p) = function delaunayAddCoords(d, p) =
[ [
@@ -161,12 +159,9 @@ function delaunayAddCoords(d, p) =
]; ];
function delaunayBadTriangles(d, p, _indices_hash) = function delaunayBadTriangles(d, p, _indices_hash) =
let( let(circles = delaunay_circles(d))
triangles = delaunay_triangles(d),
circles = delaunay_circles(d)
)
[ [
for(t = hashmap_keys(triangles)) for(t = hashmap_keys(delaunay_triangles(d)))
if(inCircumcircle(t, p, circles, _indices_hash)) if(inCircumcircle(t, p, circles, _indices_hash))
t t
]; ];
@@ -184,12 +179,7 @@ function inCircumcircle(t, p, circles, _indices_hash) =
v * v <= cc_rr(c); v * v <= cc_rr(c);
function delaunayBoundaries(d, badTriangles, _indices_hash) = function delaunayBoundaries(d, badTriangles, _indices_hash) =
let( _delaunayBoundaries(d, badTriangles, [], badTriangles[0], 0, _indices_hash);
boundaries = [],
t = badTriangles[0],
vi = 0
)
_delaunayBoundaries(d, badTriangles, boundaries, t, vi, _indices_hash);
function _delaunayBoundaries(d, badTriangles, boundaries, t, vi, _indices_hash) = function _delaunayBoundaries(d, badTriangles, boundaries, t, vi, _indices_hash) =
let( let(
@@ -197,22 +187,17 @@ function _delaunayBoundaries(d, badTriangles, boundaries, t, vi, _indices_hash)
opTri = hashmap_get(triangles, t, hash = _indices_hash)[vi] opTri = hashmap_get(triangles, t, hash = _indices_hash)[vi]
) )
contains(badTriangles, opTri) ? contains(badTriangles, opTri) ?
let( let(i = search([t], hashmap_get(triangles, opTri, hash = _indices_hash))[0])
i = search([t], hashmap_get(triangles, opTri, hash = _indices_hash))[0], _delaunayBoundaries(d, badTriangles, boundaries, opTri, (i + 1) % 3, _indices_hash) :
nvi = (i + 1) % 3,
nt = opTri
)
_delaunayBoundaries(d, badTriangles, boundaries, nt, nvi, _indices_hash) :
let( let(
nboundaries = [each boundaries, [ nboundaries = [each boundaries, [
[t[(vi + 1) % 3], t[vi > 0 ? vi - 1 : (vi + 2)]], // edge [t[(vi + 1) % 3], t[vi > 0 ? vi - 1 : (vi + 2)]], // edge
opTri // delaunayTri opTri // delaunayTri
]], ]]
nvi = (vi + 1) % 3,
v1 = nboundaries[0][0][0],
v2 = nboundaries[len(nboundaries) - 1][0][1]
) )
v1 == v2 ? nboundaries : _delaunayBoundaries(d, badTriangles, nboundaries, t, nvi, _indices_hash); nboundaries[0][0][0] == nboundaries[len(nboundaries) - 1][0][1] ?
nboundaries :
_delaunayBoundaries(d, badTriangles, nboundaries, t, (vi + 1) % 3, _indices_hash);
function delBadTriangles(d, badTriangles, _indices_hash) = function delBadTriangles(d, badTriangles, _indices_hash) =
[ [