Outline progress
This commit is contained in:
parent
8e9cdd1364
commit
c0a7fb4552
4 changed files with 127 additions and 55 deletions
|
@ -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
|
||||
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
|
|
@ -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 = {}
|
||||
|
||||
// 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]
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}, '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]
|
||||
|
||||
// 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
|
||||
|
||||
for (const p of Object.values(points)) {
|
||||
const r = new m.models.RoundRectangle(size, size, config.corner || 0)
|
||||
const holes = {}
|
||||
for (const [key, p] of Object.entries(points)) {
|
||||
holes[key] = p.rect(14)
|
||||
}
|
||||
|
||||
if (config.glue) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 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
|
||||
|
||||
// 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)
|
||||
|
||||
|
||||
}
|
|
@ -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={}) => {
|
||||
|
|
|
@ -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) => {
|
||||
|
@ -42,3 +50,7 @@ exports.poly = (arr) => {
|
|||
}
|
||||
return res
|
||||
}
|
||||
|
||||
exports.eq = (a, b) => {
|
||||
return a[0] === b[0] && a[1] === b[1]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue