From dd02bb42c5b37b10fb721ea851131b7b689af702 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Fri, 26 Jan 2024 19:40:00 -0500 Subject: [PATCH] filter zero area polygons in vnf_from_polygons --- vnf.scad | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vnf.scad b/vnf.scad index 06ecff4..28f6e97 100644 --- a/vnf.scad +++ b/vnf.scad @@ -423,20 +423,23 @@ function vnf_join(vnfs) = // Topics: VNF Generators, Lists // See Also: vnf_tri_array(), vnf_join(), vnf_vertex_array(), vnf_from_region() // Usage: -// vnf = vnf_from_polygons(polygons); +// vnf = vnf_from_polygons(polygons, [eps]); // Description: // 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 // 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: // 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") let( offs = cumsum([0, for(p=polygons) len(p)]), 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];