From a21f672839eda51de43cee2c6f0ff3c6e7fb23ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Sat, 6 Jun 2020 23:07:14 +0200 Subject: [PATCH] Basic outlining done --- config/regular.yaml | 2 +- helpers/outline.js | 27 ++++++++++++++++++++++----- helpers/utils.js | 8 +++++--- package-lock.json | 5 ++--- package.json | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/config/regular.yaml b/config/regular.yaml index 41d8687..0d53a10 100644 --- a/config/regular.yaml +++ b/config/regular.yaml @@ -14,7 +14,7 @@ zones: stagger: 12 rows: - bind_x: left - - bind_x: left + - bind_x: right - bind_x: right - name: middle stagger: 5 diff --git a/helpers/outline.js b/helpers/outline.js index 3667973..a4c2c68 100644 --- a/helpers/outline.js +++ b/helpers/outline.js @@ -19,12 +19,17 @@ const outline = (points, config) => { const glue_conf = config.outline.glue + const internal_part = (line) => { + // taking the middle part only, so that we don't interfere with corner rounding + return u.line(m.point.middle(line, 0.4), m.point.middle(line, 0.6)) + } + const get_line = (def={}) => { const point = points[def.key] if (!point) throw new Error(`Point ${def.key} not found...`) const rect = m.model.originate(point.rect(footprint)) line = rect.paths[def.line || 'top'] - return line + return internal_part(line) } assert.ok(glue_conf.top) @@ -68,6 +73,7 @@ const outline = (points, config) => { jsu = require('util') let i = 0 + const keys = {} let left_keys = {} let right_keys = {} for (const zone of Object.values(config.zones)) { @@ -101,17 +107,28 @@ const outline = (points, config) => { let key = new m.models.RoundRectangle(to_x - from_x, to_y - from_y, corner) key = m.model.moveRelative(key, [from_x, from_y]) key = p.position(key) - console.log(i+1, pname, jsu.inspect(key, true, null, true)) - if (i == 7) throw 7 - // keys[pname] = u.deepcopy(key) + // console.log(i+1, pname, jsu.inspect(key, true, null, true)) + // if (i == 7) throw 7 + keys[pname] = u.deepcopy(p.position(u.rect(14, 14, [-7, -7]))) if (mirrored) { // TODO running into the problem again where the right side doesn't combine properly // have to debug this at a lower level, it might be a bug in the makerjs source :/ // first step is to export these inspections and create a minimal reproduction // if that fails as well, I have to dive into the combineUnion code... + + // if (pname === 'mirror_inner_top') { + // u.dump_model({a: right_keys, b: key}, `debug_bad`, true) + // } + + right_keys = m.model.combineUnion(key, right_keys) u.dump_model({a: glue, c: right_keys}, `right_${++i}`) } else { + + // if (pname === 'inner_top') { + // u.dump_model({a: left_keys, b: key}, `debug_good`, true) + // } + left_keys = m.model.combineUnion(key, left_keys) u.dump_model({a: glue, b: left_keys}, `left_${++i}`) } @@ -126,7 +143,7 @@ const outline = (points, config) => { glue = m.model.combineUnion(glue, left_keys) u.dump_model({a: glue, b: left_keys, c: {models: right_keys}}, `all_after_left`) glue = m.model.combineUnion(glue, right_keys) - u.dump_model({a: glue, b: left_keys, c: {models: right_keys}}, `all_after_right`) + u.dump_model({a: glue, b: {models: keys}}, `fullll`) // glue = m.model.outline(glue, expansion) diff --git a/helpers/utils.js b/helpers/utils.js index 0c2f9c5..4823369 100644 --- a/helpers/utils.js +++ b/helpers/utils.js @@ -38,6 +38,10 @@ exports.rect = (w, h, o=[0, 0], mirrored=false) => { return m.model.move({paths: res}, o) } +const eq = exports.eq = (a=[], b=[]) => { + return a[0] === b[0] && a[1] === b[1] +} + exports.poly = (arr) => { let counter = 0 let prev = arr[arr.length - 1] @@ -45,12 +49,10 @@ exports.poly = (arr) => { paths: {} } for (const p of arr) { + if (eq(prev, p)) continue res.paths['p' + (++counter)] = line(prev, p) prev = p } return res } -exports.eq = (a, b) => { - return a[0] === b[0] && a[1] === b[1] -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3b8f660..4172cb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -189,9 +189,8 @@ } }, "makerjs": { - "version": "0.17.0", - "resolved": "https://registry.npmjs.org/makerjs/-/makerjs-0.17.0.tgz", - "integrity": "sha512-uUCQKnzqVwfIzwp4nJEcOBQoxoI5pOD4Y2+8lzRlcboWvO4+H2okzmZ6DiTAT+2w28qDN548Wl/EWXwj2FjACw==", + "version": "github:mrzealot/maker.js-dist#417521f11c9482fc9f518836348a4fb5a5b68b47", + "from": "github:mrzealot/maker.js-dist", "requires": { "@danmarshall/jscad-typings": "^1.0.0", "@types/bezier-js": "^0.0.6", diff --git a/package.json b/package.json index 6c3d127..84a177f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dependencies": { "fs-extra": "^9.0.0", "js-yaml": "^3.14.0", - "makerjs": "^0.17.0", + "makerjs": "github:mrzealot/maker.js-dist", "yargs": "^15.3.1" } }