Outline progress and getting stuck

This commit is contained in:
Bán Dénes 2020-06-03 22:16:45 +02:00
parent c0a7fb4552
commit 12f97a9171
4 changed files with 207 additions and 50 deletions

View file

@ -6,17 +6,39 @@ zones:
- name: pinky
rotate: -5
origin: [7, -7]
rows:
- bind_x:
- bind_x: right
- bind_x: right
- name: ring
stagger: 12
rows:
- bind_x: left
- bind_x: left
- bind_x: right
- name: middle
stagger: 5
rows:
- bind_x: both
- bind_x: both
- bind_x:
- name: index
stagger: -6
rows:
- bind_x: right
- bind_x: left
- bind_x: left
- name: inner
stagger: -2
rows:
- bind_x:
- bind_x: left
- bind_x: left
rows:
- name: bottom
bind_y: up
- name: home
bind_y: up
- name: top
thumbfan:
anchor:
@ -28,15 +50,22 @@ zones:
padding: 21.25
rotate: -28
origin: [9.5, -9]
rows:
- bind_x: right
- name: home
column_wire: middle
padding: 21.25
rotate: -28
origin: [11.75, -9]
rows:
- bind_x: both
- name: far
column_wire: index
rows:
- bind_x: left
rows:
- name: thumb
bind_y: up
angle: -20
mirror:
ref: pinky_home
@ -55,8 +84,8 @@ mirror:
# new_width = 250 - (2 * old_origin.x)
distance: 223.7529778
outline:
footprint: 14
expansion: 5
footprint: 18
bind: 10
corner: 0.5
glue:
top:
@ -76,5 +105,5 @@ outline:
waypoints:
- percent: 50
width: 100
mid:
shrink: 5
- percent: 90
width: 50

View file

@ -8,64 +8,181 @@ const u = require('./utils')
const outline = (points, config) => {
const holes = {}
for (const [key, p] of Object.entries(points)) {
holes[key] = p.rect(14)
}
assert.ok(config.outline)
const footprint = config.outline.footprint || 18
const corner = config.outline.corner || 0
const global_bind = config.outline.bind || 5
if (config.glue) {
let glue = {paths: {}}
if (config.outline.glue) {
const glue_conf = config.outline.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))
const rect = m.model.originate(point.rect(footprint))
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)
assert.ok(glue_conf.top)
const tll = get_line(glue_conf.top.left)
const trl = get_line(glue_conf.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)
assert.ok(glue_conf.bottom)
const bll = get_line(glue_conf.bottom.left)
const brl = get_line(glue_conf.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
const left_waypoints = []
const right_waypoints = []
for (const w of glue_conf.waypoints || []) {
const percent = w.percent / 100
const center_x = tip[0] + percent * (bip[0] - tip[0])
const center_y = tip[1] + percent * (bip[1] - tip[1])
const left_x = center_x - (w.left || w.width / 2)
const right_x = center_x + (w.right || w.width / 2)
left_waypoints.push([left_x, center_y])
right_waypoints.unshift([right_x, center_y])
}
const waypoints =
[trp, tip, tlp]
.concat(left_waypoints)
.concat([blp, bip, brp])
.concat(right_waypoints)
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
glue = u.poly(waypoints)
}
// TODO
jsu = require('util')
let i = 0
let left_keys = {}
let right_keys = {}
for (const zone of Object.values(config.zones)) {
// interate cols in reverse order so they can
// always overlap with the growing middle patch
for (const col of zone.columns.slice().reverse()) {
for (const [pname, p] of Object.entries(points)) {
if (p.meta.col.name != col.name) continue
let from_x = -footprint / 2, to_x = footprint / 2
let from_y = -footprint / 2, to_y = footprint / 2
const bind = p.meta.row.bind || p.meta.col.bind || global_bind
const mirrored = p.meta.mirrored
const bind_x = p.meta.row.bind_x || p.meta.col.bind_x
if ((bind_x == 'left' && !mirrored) || (bind_x == 'right' && mirrored) || bind_x == 'both') {
from_x -= bind
}
if ((bind_x == 'right' && !mirrored) || (bind_x == 'left' && mirrored) || bind_x == 'both') {
to_x += bind
}
const bind_y = p.meta.row.bind_y || p.meta.col.bind_y
if (bind_y == 'down' || bind_y == 'both') {
from_y -= bind
}
if (bind_y == 'up' || bind_y == 'both') {
to_y += bind
}
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)
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...
right_keys = m.model.combineUnion(key, right_keys)
u.dump_model({a: glue, c: right_keys}, `right_${++i}`)
} else {
left_keys = m.model.combineUnion(key, left_keys)
u.dump_model({a: glue, b: left_keys}, `left_${++i}`)
}
// u.dump_model({a: glue}, `glue_${i++}`)
}
}
}
u.dump_model({a: glue, b: left_keys, c: {models: right_keys}}, `all_before`)
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`)
// glue = m.model.outline(glue, expansion)
// const keys = {}
// // let i = 1
// for (const zone of Object.values(config.zones)) {
// // interate cols in reverse order so they can
// // always overlap with the growing middle patch
// for (const col of zone.columns.slice().reverse()) {
// for (const [pname, p] of Object.entries(points)) {
// if (p.meta.col.name != col.name) continue
// // let key = new m.models.RoundRectangle(footprint, footprint, corner)
// let key = u.rect(footprint, footprint)
// key = m.model.moveRelative(key, [-footprint/2, -footprint/2])
// key = p.position(key)
// keys[pname] = u.deepcopy(key)
// key = m.model.outline(key, expansion)
// glue = m.model.combineUnion(glue, key)
// // u.dump_model(keys, `keys_${i}`)
// // u.dump_model({a: glue}, `glue_${i++}`)
// }
// }
// }
// u.dump_model({a: glue, b: {models: keys}}, `all`)
// glue = m.model.outline(glue, expansion, 1, true)
// u.dump_model({a: glue}, `glue_post`)
// u.dump_model({
// a: {
// models: {a: glue},
// // 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),
// // }
// },
// b: { models: keys }
// }, '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)
@ -116,7 +233,7 @@ exports.draw = (points, config) => {
// TODO this is just a test
outline(points, config.outline)
outline(points, config)
}

View file

@ -64,6 +64,10 @@ const Point = exports.Point = class Point {
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)
}
position(model) {
return m.model.moveRelative(m.model.rotate(model, this.r), this.p)
}
}
const dump = exports.dump = (points, opts={}) => {
@ -122,16 +126,23 @@ const render_zone = (cols, rows, anchor=new Point(), reverse=false) => {
// and we don't want to apply them twice...
col_anchor.r = 0
for (const row of col.rows || rows) {
// combine row data from zone-wide defs and col-specific defs
const col_specific = col.rows || []
const zone_wide = rows || []
const actual_rows = []
for (let i = 0; i < zone_wide.length && i < col_specific.length; ++i) {
actual_rows.push(Object.assign({}, zone_wide[i], col_specific[i]))
}
for (const row of actual_rows) {
let point = col_anchor.clone()
for (const r of rotations) {
point.rotate(r.angle, r.origin)
}
point.r += col.angle || 0
point.meta = {col, row}
const key = `${col.name}_${row.name}`
points[key] = point
const name = `${col.name}_${row.name}`
point.meta = {col, row, name}
points[name] = point
col_anchor.y += row.padding || 19
}
@ -185,12 +196,12 @@ exports.parse = (config) => {
}
if (config.mirror) {
let x = anchor(config.mirror, points).x
x += (config.mirror.distance || 0) / 2
let axis = anchor(config.mirror, points).x
axis += (config.mirror.distance || 0) / 2
const mirrored_points = {}
for (const [name, p] of Object.entries(points)) {
if (p.meta.col.asym == 'left' || p.meta.row.asym == 'left') continue
const mp = p.clone().mirror(x)
const mp = p.clone().mirror(axis)
mp.meta.mirrored = true
delete mp.meta.asym
mirrored_points[`mirror_${name}`] = mp

View file

@ -1,11 +1,11 @@
const m = require('makerjs')
const fs = require('fs-extra')
exports.deepcopy = (value) => JSON.parse(JSON.stringify(value))
const deepcopy = exports.deepcopy = (value) => JSON.parse(JSON.stringify(value))
exports.dump_model = (model, file='model', json=false) => {
const assembly = m.model.originate({
models: model,
models: deepcopy(model),
units: 'mm'
})