From abf1a78290f977fa01b29ed33b8163653d701db9 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Tue, 31 Mar 2020 03:09:04 -0700 Subject: [PATCH] Bugfix for set_union() when b contains duplicate items. --- arrays.scad | 21 +++++++++++++++------ version.scad | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arrays.scad b/arrays.scad index 9846a22..4636cda 100644 --- a/arrays.scad +++ b/arrays.scad @@ -991,14 +991,23 @@ function permute(l,n=2,_s=0) = // // set_v now equals [[5,0,1,2,6], [2,3,5,7,11,1,8]] function set_union(a, b, get_indices=false) = let( - found = search(b, a, num_returns_per_match=1), - nset = concat(a, [ - for (i=idx(found)) if(found[i]==[]) b[i] - ]) + found1 = search(b, a), + found2 = search(b, b), + c = [ + for (i=idx(b)) + if (found1[i] == [] && found2[i] == i) + b[i] + ], + nset = concat(a, c) ) !get_indices? nset : let( - nidx = cumsum([len(a), for (i=found) (i==[])? 1 : 0]), - idxs = [for (i=idx(found)) (found[i]==[])? nidx[i] : found[i]] + la = len(a), + found3 = search(b, c), + idxs = [ + for (i=idx(b)) + (found1[i] != [])? found1[i] : + la + found3[i] + ] ) [idxs, nset]; diff --git a/version.scad b/version.scad index 889e44d..6ebd97d 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,249]; +BOSL_VERSION = [2,0,250]; // Section: BOSL Library Version Functions