From 23ed8989ce99d3b3745d7feb79c5b2689f986e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Thu, 8 Oct 2020 20:11:36 +0200 Subject: [PATCH] Case bugfixes --- README.md | 4 ++-- src/cases.js | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 792ec44..29f5f74 100644 --- a/README.md +++ b/README.md @@ -499,7 +499,7 @@ cases: case_name: - outline: extrude: num # default = 1 - translate: [x, y, z] # default = [0, 0, 0] + shift: [x, y, z] # default = [0, 0, 0] rotate: [ax, ay, az] # default = [0, 0, 0] operation: add | subtract | intersect # default = add - ... @@ -507,7 +507,7 @@ cases: ``` `outline` specifies which outline to import onto the xy plane, while `extrude` specifies how much it should be extruded along the z axis. -After that, the object is `translate`d, `rotate`d, and combined with what we have so far according to `operation`. +After that, the object is `shift`d, `rotate`d, and combined with what we have so far according to `operation`. If we only want to use an object as a building block for further objects, we can employ the same "start with an underscore" trick we learned at the outlines section to make it "private". diff --git a/src/cases.js b/src/cases.js index 2c0da84..80b6b31 100644 --- a/src/cases.js +++ b/src/cases.js @@ -24,12 +24,11 @@ exports.parse = (config, outlines) => { const extrude = a.sane(part.extrude || 1, `${part_name}.extrude`, 'number') const shift = a.numarr(part.shift || [0, 0, 0], `${part_name}.shift`, 3) const rotate = a.numarr(part.rotate || [0, 0, 0], `${part_name}.rotate`, 3) - const operation = a.in(part.operation || 'add', `${part_name}.operation`, ['add', 'subtract', 'intersect', 'stack']) + const operation = a.in(part.operation || 'add', `${part_name}.operation`, ['add', 'subtract', 'intersect']) - let op = u.union - if (operation == 'subtract') op = u.subtract - else if (operation == 'intersect') op = u.intersect - else if (operation == 'stack') op = u.stack + let op = 'union' + if (operation == 'subtract') op = 'subtract' + else if (operation == 'intersect') op = 'intersect' const part_fn = `${part.outline}_fn` const part_var = `${part.outline}_var` @@ -41,17 +40,15 @@ exports.parse = (config, outlines) => { let op_statement = `let ${case_name} = ${part_var};` if (part_index > 1) { - op_statement = `${case_name} = ${case_name}.${operation}(${part_var});` + op_statement = `${case_name} = ${case_name}.${op}(${part_var});` } main.push(` // creating part ${part_index} of case ${case_name} let ${part_var} = ${part_fn}(); - ${part_var} = ${part_var}.rotateX(${rotate[0]}); - ${part_var} = ${part_var}.rotateY(${rotate[1]}); - ${part_var} = ${part_var}.rotateZ(${rotate[2]}); - ${part_var} = ${part_var}.translate(${shift}); + ${part_var} = rotate(${JSON.stringify(rotate)}, ${part_var}); + ${part_var} = translate(${JSON.stringify(shift)}, ${part_var}); ${op_statement} `)