From 8efaaf3432706c5eeb3f64da5ed2da0170772179 Mon Sep 17 00:00:00 2001 From: "Jeroen F.J. Laros" Date: Thu, 6 May 2021 20:46:46 +0200 Subject: [PATCH] Added duplication vector for burr_plate() module. --- src/main/scad/puzzlecad/puzzlecad-burr.scad | 6 ++++-- src/main/scad/puzzlecad/puzzlecad-parser.scad | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/scad/puzzlecad/puzzlecad-burr.scad b/src/main/scad/puzzlecad/puzzlecad-burr.scad index 992b8b5..a8b92ad 100644 --- a/src/main/scad/puzzlecad/puzzlecad-burr.scad +++ b/src/main/scad/puzzlecad/puzzlecad-burr.scad @@ -48,9 +48,11 @@ module burr_piece(burr_spec) { * The other arguments should be left as defaults (they're used for recursive calls to burr_plate). */ -module burr_plate(burr_specs, num_copies = 1) { +module burr_plate(burr_specs, num_copies = 1, dup = []) { - burr_infos = [ for (burr_spec = burr_specs) to_burr_info(burr_spec) ]; + burr_dups = dups(dup, burr_specs); + + burr_infos = [ for (burr_spec = burr_dups) to_burr_info(burr_spec) ]; layout_burr_infos = $auto_layout ? auto_layout_plate(burr_infos) : burr_infos; diff --git a/src/main/scad/puzzlecad/puzzlecad-parser.scad b/src/main/scad/puzzlecad/puzzlecad-parser.scad index 2fd05e5..4ac4283 100644 --- a/src/main/scad/puzzlecad/puzzlecad-parser.scad +++ b/src/main/scad/puzzlecad/puzzlecad-parser.scad @@ -209,3 +209,7 @@ function bit_of(n, exponent) = floor(n / pow(2, exponent)) % 2; function copies(n, burr) = n == 0 ? [] : concat(copies(n-1, burr), [burr]); +function dups(v, r, i = 0) = + i < len(v) + ? dups(v, concat(r, [for (x = [0:1:v[i][1] - 1]) r[v[i][0]]]), i + 1) + : r;