filter zero area polygons in vnf_from_polygons

This commit is contained in:
Adrian Mariano 2024-01-26 19:40:00 -05:00
parent ad504a5962
commit dd02bb42c5

View file

@ -423,20 +423,23 @@ function vnf_join(vnfs) =
// Topics: VNF Generators, Lists // Topics: VNF Generators, Lists
// See Also: vnf_tri_array(), vnf_join(), vnf_vertex_array(), vnf_from_region() // See Also: vnf_tri_array(), vnf_join(), vnf_vertex_array(), vnf_from_region()
// Usage: // Usage:
// vnf = vnf_from_polygons(polygons); // vnf = vnf_from_polygons(polygons, [eps]);
// Description: // Description:
// Given a list of 3D polygons, produces a VNF containing those polygons. // Given a list of 3D polygons, produces a VNF containing those polygons.
// It is up to the caller to make sure that the points are in the correct order to make the face // It is up to the caller to make sure that the points are in the correct order to make the face
// normals point outwards. No checking for duplicate vertices is done. If you want to // normals point outwards. No checking for duplicate vertices is done. If you want to
// remove duplicate vertices use {{vnf_merge_points()}}. // remove duplicate vertices use {{vnf_merge_points()}}. Polygons with zero area are discarded from the face list by default.
// Arguments: // Arguments:
// polygons = The list of 3D polygons to turn into a VNF // polygons = The list of 3D polygons to turn into a VNF
function vnf_from_polygons(polygons) = // eps = Polygons with area small than this are discarded. Default: EPSILON
function vnf_from_polygons(polygons,eps=EPSILON) =
assert(is_list(polygons) && is_path(polygons[0]),"Input should be a list of polygons") assert(is_list(polygons) && is_path(polygons[0]),"Input should be a list of polygons")
let( let(
offs = cumsum([0, for(p=polygons) len(p)]), offs = cumsum([0, for(p=polygons) len(p)]),
faces = [for(i=idx(polygons)) faces = [for(i=idx(polygons))
[for (j=idx(polygons[i])) offs[i]+j] let(area=polygon_area(polygons[i]))
if (is_def(area) && area > eps)
[for (j=idx(polygons[i])) offs[i]+j]
] ]
) )
[flatten(polygons), faces]; [flatten(polygons), faces];