diff --git a/tests/test_vnf.scad b/tests/test_vnf.scad index a119999..e793ff7 100644 --- a/tests/test_vnf.scad +++ b/tests/test_vnf.scad @@ -34,27 +34,13 @@ module test_vnf_faces() { test_vnf_faces(); -module test_vnf_add_face() { +module test_vnf_from_polygons() { verts = [[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]]; - faces = [[0,1,2],[0,3,1],[1,3,2],[2,3,0]]; - vnf1 = vnf_add_face(pts=select(verts,faces[0])); - vnf2 = vnf_add_face(vnf1, pts=select(verts,faces[1])); - vnf3 = vnf_add_face(vnf2, pts=select(verts,faces[2])); - vnf4 = vnf_add_face(vnf3, pts=select(verts,faces[3])); - assert(vnf1 == [select(verts,0,2),select(faces,[0])]); - assert(vnf2 == [verts,select(faces,[0:1])]); - assert(vnf3 == [verts,select(faces,[0:2])]); - assert(vnf4 == [verts,faces]); + faces = [[0,1,2],[0,1,3,2],[2,3,0]]; + assert(vnf_merge(cleanup=true, + [vnf_from_polygons([for (face=faces) select(verts,face)])]) == [verts,faces]); } -test_vnf_add_face(); - - -module test_vnf_add_faces() { - verts = [[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]]; - faces = [[0,1,2],[0,3,1],[1,3,2],[2,3,0]]; - assert(vnf_add_faces(faces=[for (face=faces) select(verts,face)]) == [verts,faces]); -} -test_vnf_add_faces(); +test_vnf_from_polygons(); module test_vnf_centroid() { @@ -85,8 +71,8 @@ test_vnf_area(); module test_vnf_merge() { - vnf1 = vnf_add_face(pts=[[-1,-1,-1],[1,-1,-1],[0,1,-1]]); - vnf2 = vnf_add_face(pts=[[1,1,1],[-1,1,1],[0,1,-1]]); + vnf1 = vnf_from_polygons([[[-1,-1,-1],[1,-1,-1],[0,1,-1]]]); + vnf2 = vnf_from_polygons([[[1,1,1],[-1,1,1],[0,1,-1]]]); assert(vnf_merge([vnf1,vnf2]) == [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[1,1,1],[-1,1,1],[0,1,-1]],[[0,1,2],[3,4,5]]]); } test_vnf_merge(); diff --git a/vnf.scad b/vnf.scad index 1af09cf..45cb54d 100644 --- a/vnf.scad +++ b/vnf.scad @@ -339,7 +339,7 @@ function vnf_merge(vnfs, cleanup=false, eps=EPSILON) = // Arguments: // polygons = The list of 3d polygons to turn into a VNF function vnf_from_polygons(polygons) = - assert(is_list(polygons)) + 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))