From d957f556d6ef0ad797a0dbabc7da16efd2f6ef89 Mon Sep 17 00:00:00 2001
From: Adrian Mariano <avm4@cornell.edu>
Date: Wed, 15 Sep 2021 20:03:15 -0400
Subject: [PATCH] bug fixes

---
 geometry.scad | 6 +++++-
 rounding.scad | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/geometry.scad b/geometry.scad
index 0ad2043b..bfa14c08 100644
--- a/geometry.scad
+++ b/geometry.scad
@@ -1599,16 +1599,20 @@ function point_in_polygon(point, poly, nonzero=false, eps=EPSILON) =
 //   vnf_wireframe(vnf_tri, d=.15);
 
 function polygon_triangulate(poly, ind, eps=EPSILON) =
+    let(a=echo(poly=poly)echo(ind=ind))
     assert(is_path(poly), "Polygon `poly` should be a list of 2d or 3d points")
     assert(is_undef(ind) 
            || (is_vector(ind) && min(ind)>=0 && max(ind)<len(poly) ),
            "Improper or out of bounds list of indices")
     let( ind = deduplicate_indexed(poly,is_undef(ind) ? count(len(poly)) : ind) )
+    len(ind) < 3 ? [] :
+    len(ind) == 3 ? [ind] :
     len(poly[ind[0]]) == 3 
       ? // represents the polygon projection on its plane as a 2d polygon 
         let( 
             pts = select(poly,ind),
-            nrm = polygon_normal(pts)
+            nrm = polygon_normal(pts),
+            a=echo(pts=pts)echo(nrm=nrm)
         )
         // here, instead of an error, it might return [] or undef
         assert( nrm!=undef, 
diff --git a/rounding.scad b/rounding.scad
index 823f56bc..45555da2 100644
--- a/rounding.scad
+++ b/rounding.scad
@@ -1958,7 +1958,8 @@ function rounded_prism(bottom, top, joint_bot=0, joint_top=0, joint_sides=0, k_b
         vnf = vnf_merge([ each subindex(top_samples,0),
                           each subindex(bot_samples,0),
                           for(pts=edge_points) vnf_vertex_array(pts),
-                          vnf_triangulate(vnf_add_faces(EMPTY_VNF,faces))
+                          debug ? vnf_add_faces(EMPTY_VNF,faces) 
+                                : vnf_triangulate(vnf_add_faces(EMPTY_VNF,faces))
                        ])
     )
     debug ? [concat(top_patch, bot_patch), vnf] : vnf;