1
0

Outline progress

This commit is contained in:
Bán Dénes 2020-06-02 22:59:05 +02:00
parent 8e9cdd1364
commit c0a7fb4552
4 changed files with 127 additions and 55 deletions

View File

@ -55,11 +55,26 @@ mirror:
# new_width = 250 - (2 * old_origin.x) # new_width = 250 - (2 * old_origin.x)
distance: 223.7529778 distance: 223.7529778
outline: outline:
top: footprint: 14
left: inner_top expansion: 5
right: mirror_inner_top corner: 0.5
bottom: glue:
left: far_thumb top:
right: mirror_far_thumb left:
hole: 14 key: inner_top
expansion: 5 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

View File

@ -4,63 +4,103 @@ const assert = require('assert').strict
const u = require('./utils') const u = require('./utils')
const a_lot = 100
const outline = (points, config) => {
const outline = (points, size, config={}) => { const holes = {}
const models = {} for (const [key, p] of Object.entries(points)) {
holes[key] = p.rect(14)
}
// create the two tops if (config.glue) {
assert.ok(config.top.left)
assert.ok(config.top.right)
const tlp = points[config.top.left]
const trp = points[config.top.right]
tl = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-size/2, -size/2]), tlp.r), tlp.p) const get_line = (def={}) => {
tr = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-a_lot+size/2, -size/2]), trp.r), trp.p) const point = points[def.key]
tl = m.model.originate(tl) if (!point) throw new Error(`Point ${def.key} not found...`)
tr = m.model.originate(tr) const size = config.footprint || 18
const top_intersect = m.path.intersection(tl.paths.top, tr.paths.top).intersectionPoints[0] const rect = m.model.originate(point.rect(size))
console.log(tlp.p, tl, tl.paths.top, ',,,', trp.p, tr, tr.paths.top, top_intersect) line = rect.paths[def.line || 'top']
return line
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)
}
} }
}, 'valami', true)
throw 2
// create the two bottoms assert.ok(config.glue.top)
assert.ok(config.bottom.left) const tll = get_line(config.glue.top.left)
assert.ok(config.bottom.right) const trl = get_line(config.glue.top.right)
const blp = points[config.bottom.left] const tip = m.path.converge(tll, trl)
const brp = points[config.bottom.right] 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) // // create the two bottoms
const brl = new m.paths.Line(brp.p, brp.add([a_lot, 0]).rotate(brp.r, brp.p).p) // assert.ok(config.bottom.left)
const bottom_intersect = m.path.intersection(bll, brl).intersectionPoints[0] // 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) // console.log(tll, trl, top_intersect)
throw 2 // throw 2
for (const p of Object.values(points)) { // for (const p of Object.values(points)) {
const r = new m.models.RoundRectangle(size, size, config.corner || 0) // const r = new m.models.RoundRectangle(size, size, config.corner || 0)
} // }
} }
exports.draw = (points, config) => { exports.draw = (points, config) => {
@ -76,7 +116,7 @@ exports.draw = (points, config) => {
// TODO this is just a test // TODO this is just a test
outline(points, 18, config.outline) outline(points, config.outline)
} }

View File

@ -59,6 +59,11 @@ const Point = exports.Point = class Point {
u.deepcopy(this.meta) 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={}) => { const dump = exports.dump = (points, opts={}) => {

View File

@ -21,13 +21,21 @@ exports.circle = (p, r) => {
return new m.paths.Circle(p, r) return new m.paths.Circle(p, r)
} }
exports.rect = (w, h, o=[0, 0]) => { exports.rect = (w, h, o=[0, 0], mirrored=false) => {
return m.model.move({paths: { const res = {
top: line([0, h], [w, h]), top: line([0, h], [w, h]),
right: line([w, h], [w, 0]), right: line([w, h], [w, 0]),
bottom: line([w, 0], [0, 0]), bottom: line([w, 0], [0, 0]),
left: line([0, 0], [0, h]) 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) => { exports.poly = (arr) => {
@ -41,4 +49,8 @@ exports.poly = (arr) => {
prev = p prev = p
} }
return res return res
}
exports.eq = (a, b) => {
return a[0] === b[0] && a[1] === b[1]
} }