Speed optimizations to triangulate_faces()

This commit is contained in:
Revar Desmera 2020-03-30 16:52:08 -07:00
parent 857e7a94fb
commit 2b2012d1d1
2 changed files with 9 additions and 10 deletions

View file

@ -89,9 +89,10 @@ function _check_point_in_ear(point, tests) =
// Arguments:
// v = The array to normalize.
function normalize_vertex_perimeter(v) =
(len(v) < 2)? v :
(v[len(v)-1] != v[0])? v :
[for (i=[0:1:len(v)-2]) v[i]]
let(lv = len(v))
(lv < 2)? v :
(v[lv-1] != v[0])? v :
[for (i=[0:1:lv-2]) v[i]]
;
@ -181,12 +182,10 @@ function triangulate_face(points, face) =
// faces = Array of faces for the polyhedron. Each face is a list of 3 or more indices into the `points` array.
function triangulate_faces(points, faces) =
[
for (i=[0:1:len(faces)-1])
let(facet = normalize_vertex_perimeter(faces[i]))
for (face = triangulate_face(points, facet))
if (face[0]!=face[1] && face[1]!=face[2] && face[2]!=face[0]) face
]
;
for (face=faces) each
len(face)==3? [face] :
triangulate_face(points, normalize_vertex_perimeter(face))
];
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,245];
BOSL_VERSION = [2,0,246];
// Section: BOSL Library Version Functions