From 2cf0ce47d9843fa1b319a8ccfcd1363c6fcc235c Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Wed, 11 Mar 2020 22:14:16 -0700 Subject: [PATCH] Minimized area of subpaths assembled during boolean geometry. --- paths.scad | 30 +++++++++++++++++++++++------- version.scad | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/paths.scad b/paths.scad index 77746cb..cbd1c5d 100644 --- a/paths.scad +++ b/paths.scad @@ -655,22 +655,38 @@ function assemble_a_path_from_fragments(fragments, rightmost=true, eps=EPSILON) // Given a list of incomplete paths, assembles them together into complete closed paths if it can. // Arguments: // fragments = List of polylines to be assembled into complete polygons. -// rightmost = If true, assemble paths using rightmost turns. Leftmost if false. // eps = The epsilon error value to determine whether two points coincide. Default: `EPSILON` (1e-9) -function assemble_path_fragments(fragments, rightmost=true, eps=EPSILON, _finished=[]) = +function assemble_path_fragments(fragments, eps=EPSILON, _finished=[]) = len(fragments)==0? _finished : let( - result = assemble_a_path_from_fragments( - fragments=fragments, - rightmost=rightmost, + minxidx = min_index([ + for (frag=fragments) min(subindex(frag,0)) + ]), + promoted = [ + fragments[minxidx], + for (i=idx(fragments)) + if (i!=minxidx) + fragments[i] + ], + result_l = assemble_a_path_from_fragments( + fragments=promoted, + rightmost=false, eps=eps ), - newpath = result[0], + result_r = assemble_a_path_from_fragments( + fragments=promoted, + rightmost=true, + eps=eps + ), + l_area = abs(polygon_area(result_l[0])), + r_area = abs(polygon_area(result_r[0])), + result = l_area < r_area? result_l : result_r, + newpath = cleanup_path(result[0]), remainder = result[1], finished = concat(_finished, [newpath]) ) assemble_path_fragments( fragments=remainder, - rightmost=rightmost, eps=eps, + eps=eps, _finished=finished ); diff --git a/version.scad b/version.scad index b1383ee..69e05a5 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,180]; +BOSL_VERSION = [2,0,181]; // Section: BOSL Library Version Functions