Update vnf_merge

This commit is contained in:
RonaldoCMP 2021-06-30 11:22:48 +01:00
parent 5b2f6d7582
commit d4ebb740f6

View file

@ -166,16 +166,19 @@ function vnf_merge(vnfs, cleanup=false, eps=EPSILON) =
let( faces = vnfs[i][1] ) let( faces = vnfs[i][1] )
for (face = faces) for (face = faces)
if ( len(face) >= 3 ) if ( len(face) >= 3 )
[ for (j = face) offs[i] + j ] [ for (j = face)
assert( j>=0 && j<len(vnfs[i][0]),
str("VNF number ", i, " has a face indexing an nonexistent vertex") )
offs[i] + j ]
] ]
) )
! cleanup ? [verts, faces] : ! cleanup ? [verts, faces] :
let( let(
dedup = search_radius(verts,verts,r=eps), // collect vertex duplicates dedup = vector_search(verts,eps,verts), // collect vertex duplicates
map = [for(i=idx(verts)) min(dedup[i]) ], // remap duplic vertices map = [for(i=idx(verts)) min(dedup[i]) ], // remap duplic vertices
offset = cumsum([for(i=idx(verts)) map[i]==i ? 0 : 1 ]), // remaping face vertex offsets offset = cumsum([for(i=idx(verts)) map[i]==i ? 0 : 1 ]), // remaping face vertex offsets
map2 = list(idx(verts))-offset, // map old vertex indices to new vertex indices map2 = list(idx(verts))-offset, // map old vertex indices to new indices
nverts = [for(i=idx(verts)) if(map[i]==i) verts[i] ], nverts = [for(i=idx(verts)) if(map[i]==i) verts[i] ], // eliminates all unreferenced vertices
nfaces = nfaces =
[ for(face=faces) [ for(face=faces)
let( let(
@ -594,7 +597,7 @@ function _triangulate_planar_convex_polygons(polys) =
// Function: vnf_bend() // Function: vnf_bend()
// Usage: // Usage:
// bentvnf = vnf_bend(vnf); // bentvnf = vnf_bend(vnf,r,d,[axis]);
// Description: // Description:
// Given a VNF that is entirely above, or entirely below the Z=0 plane, bends the VNF around the // Given a VNF that is entirely above, or entirely below the Z=0 plane, bends the VNF around the
// Y axis, splitting up faces as necessary. Returns the bent VNF. Will error out if the VNF // Y axis, splitting up faces as necessary. Returns the bent VNF. Will error out if the VNF