From c0a7fb4552edd053bf78927d7e4c2bf240dee0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Tue, 2 Jun 2020 22:59:05 +0200 Subject: [PATCH] Outline progress --- config/regular.yaml | 31 ++++++++--- helpers/outline.js | 128 +++++++++++++++++++++++++++++--------------- helpers/points.js | 5 ++ helpers/utils.js | 18 +++++-- 4 files changed, 127 insertions(+), 55 deletions(-) diff --git a/config/regular.yaml b/config/regular.yaml index f71b5c6..922c7e8 100644 --- a/config/regular.yaml +++ b/config/regular.yaml @@ -55,11 +55,26 @@ mirror: # new_width = 250 - (2 * old_origin.x) distance: 223.7529778 outline: - top: - left: inner_top - right: mirror_inner_top - bottom: - left: far_thumb - right: mirror_far_thumb - hole: 14 - expansion: 5 \ No newline at end of file + footprint: 14 + expansion: 5 + corner: 0.5 + glue: + top: + left: + key: inner_top + line: top + right: + key: mirror_inner_top + line: top + bottom: + left: + key: far_thumb + line: right + right: + key: mirror_far_thumb + line: left + waypoints: + - percent: 50 + width: 100 + mid: + shrink: 5 \ No newline at end of file diff --git a/helpers/outline.js b/helpers/outline.js index 2ac3613..b1ee641 100644 --- a/helpers/outline.js +++ b/helpers/outline.js @@ -4,63 +4,103 @@ const assert = require('assert').strict const u = require('./utils') -const a_lot = 100 +const outline = (points, config) => { -const outline = (points, size, config={}) => { - const models = {} + const holes = {} + for (const [key, p] of Object.entries(points)) { + holes[key] = p.rect(14) + } - // create the two tops - assert.ok(config.top.left) - assert.ok(config.top.right) - const tlp = points[config.top.left] - const trp = points[config.top.right] + if (config.glue) { - tl = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-size/2, -size/2]), tlp.r), tlp.p) - tr = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-a_lot+size/2, -size/2]), trp.r), trp.p) - tl = m.model.originate(tl) - tr = m.model.originate(tr) - const top_intersect = m.path.intersection(tl.paths.top, tr.paths.top).intersectionPoints[0] - console.log(tlp.p, tl, tl.paths.top, ',,,', trp.p, tr, tr.paths.top, top_intersect) - - u.dump_model({ - a: { - // models: {tl, tr}, - paths: { - tll: tl.paths.top, - trl: tr.paths.top, - tl: u.circle(tlp.p, 1), - tr: u.circle(trp.p, 1), - c: u.circle(top_intersect, 1) - } + const get_line = (def={}) => { + const point = points[def.key] + if (!point) throw new Error(`Point ${def.key} not found...`) + const size = config.footprint || 18 + const rect = m.model.originate(point.rect(size)) + line = rect.paths[def.line || 'top'] + return line } - }, 'valami', true) - throw 2 + - // create the two bottoms - assert.ok(config.bottom.left) - assert.ok(config.bottom.right) - const blp = points[config.bottom.left] - const brp = points[config.bottom.right] + assert.ok(config.glue.top) + const tll = get_line(config.glue.top.left) + const trl = get_line(config.glue.top.right) + const tip = m.path.converge(tll, trl) + const tlp = u.eq(tll.origin, tip) ? tll.end : tll.origin + const trp = u.eq(trl.origin, tip) ? trl.end : trl.origin + + assert.ok(config.glue.bottom) + const bll = get_line(config.glue.bottom.left) + const brl = get_line(config.glue.bottom.right) + const bip = m.path.converge(bll, brl) + const blp = u.eq(bll.origin, bip) ? bll.end : bll.origin + const brp = u.eq(brl.origin, bip) ? brl.end : brl.origin + + + + + u.dump_model({ + a: { + models: holes, + paths: { + tll: tll, + trl: trl, + tip: u.circle(tip, 1), + tlp: u.circle(tlp, 1), + trp: u.circle(trp, 1), + bll: bll, + brl: brl, + bip: u.circle(bip, 1), + blp: u.circle(blp, 1), + brp: u.circle(brp, 1), + } + } + }, 'valami', true) + + throw 3 + + + } + + + // let tl = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-size/2, -size/2]), tlp.r), tlp.p) + // let tr = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-a_lot+size/2, -size/2]), trp.r), trp.p) + // tl = m.model.originate(tl) + // tr = m.model.originate(tr) + // let top_intersect = m.path.intersection(tl.paths.top, tr.paths.top).intersectionPoints + // if (!top_intersect) { + // throw new Error('Top intersect') + // } + // console.log(tlp.p, tl, tl.paths.top, ',,,', trp.p, tr, tr.paths.top, top_intersect) - // create middle "patch" - const tll = new m.paths.Line(tlp.p, tlp.add([a_lot, 0]).rotate(tlp.r, tlp.p).p) - const trl = new m.paths.Line(trp.p, trp.add([a_lot, 0]).rotate(trp.r, trp.p).p) - const bll = new m.paths.Line(blp.p, blp.add([a_lot, 0]).rotate(blp.r, blp.p).p) - const brl = new m.paths.Line(brp.p, brp.add([a_lot, 0]).rotate(brp.r, brp.p).p) - const bottom_intersect = m.path.intersection(bll, brl).intersectionPoints[0] + // // create the two bottoms + // assert.ok(config.bottom.left) + // assert.ok(config.bottom.right) + // const blp = points[config.bottom.left] + // const brp = points[config.bottom.right] + + // // create middle "patch" + // const tll = new m.paths.Line(tlp.p, tlp.add([a_lot, 0]).rotate(tlp.r, tlp.p).p) + // const trl = new m.paths.Line(trp.p, trp.add([a_lot, 0]).rotate(trp.r, trp.p).p) + + + // const bll = new m.paths.Line(blp.p, blp.add([a_lot, 0]).rotate(blp.r, blp.p).p) + // const brl = new m.paths.Line(brp.p, brp.add([a_lot, 0]).rotate(brp.r, brp.p).p) + // const bottom_intersect = m.path.intersection(bll, brl).intersectionPoints[0] - console.log(tll, trl, top_intersect) - throw 2 + // console.log(tll, trl, top_intersect) + // throw 2 - for (const p of Object.values(points)) { - const r = new m.models.RoundRectangle(size, size, config.corner || 0) - } + // for (const p of Object.values(points)) { + // const r = new m.models.RoundRectangle(size, size, config.corner || 0) + // } } exports.draw = (points, config) => { @@ -76,7 +116,7 @@ exports.draw = (points, config) => { // TODO this is just a test - outline(points, 18, config.outline) + outline(points, config.outline) } \ No newline at end of file diff --git a/helpers/points.js b/helpers/points.js index b7bd62e..aaa1e39 100644 --- a/helpers/points.js +++ b/helpers/points.js @@ -59,6 +59,11 @@ const Point = exports.Point = class Point { u.deepcopy(this.meta) ) } + + rect(size=14) { + let rect = u.rect(size, size, [-size/2, -size/2], this.meta.mirrored) + return m.model.moveRelative(m.model.rotate(rect, this.r), this.p) + } } const dump = exports.dump = (points, opts={}) => { diff --git a/helpers/utils.js b/helpers/utils.js index 05df277..dd5474a 100644 --- a/helpers/utils.js +++ b/helpers/utils.js @@ -21,13 +21,21 @@ exports.circle = (p, r) => { return new m.paths.Circle(p, r) } -exports.rect = (w, h, o=[0, 0]) => { - return m.model.move({paths: { +exports.rect = (w, h, o=[0, 0], mirrored=false) => { + const res = { top: line([0, h], [w, h]), right: line([w, h], [w, 0]), bottom: line([w, 0], [0, 0]), left: line([0, 0], [0, h]) - }}, o) + } + if (mirrored) { + for (const [key, val] of Object.entries(res)) { + const tmp = val.origin + val.origin = val.end + val.end = tmp + } + } + return m.model.move({paths: res}, o) } exports.poly = (arr) => { @@ -41,4 +49,8 @@ exports.poly = (arr) => { prev = p } return res +} + +exports.eq = (a, b) => { + return a[0] === b[0] && a[1] === b[1] } \ No newline at end of file