From afdc467daffcc1604789596f27950d499877249c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Sun, 31 May 2020 20:33:23 +0200 Subject: [PATCH] Point fixes and asymmetry tests --- config/regular.yaml | 19 ++++++++++++++----- config/squished.yaml | 19 ++++++------------- helpers/points.js | 14 ++++++++++---- helpers/utils.js | 14 ++++++++++++++ 4 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 helpers/utils.js diff --git a/config/regular.yaml b/config/regular.yaml index b790a1f..f71b5c6 100644 --- a/config/regular.yaml +++ b/config/regular.yaml @@ -39,18 +39,27 @@ zones: - name: thumb angle: -20 mirror: - ref: pinky_bottom + ref: pinky_home # The mk1's origin was the bottom left corner of the bottom pinky key. # But it later got rotated by the bottom *right* corner as the pinky angle # and then rotated again for the inter-half angle so [0, 0] was nowhere on # the actual result. # - # Since the new origin is the center of the pinky bottom, we have to convert + # Since the new origin is the center of the pinky home, we have to convert # the old, round 250 width to this new coordinate system if we want backward - # compatibility. The following snippet was used to arrive at 233.5881016. + # compatibility. The following snippet was used to arrive at this distance. # - # old_origin = new Point(7, 7) + # old_origin = new Point(7, 7 + 19) # old_origin.rotate(5, [14, 0]) # old_origin.rotate(-20, [0, 0]) # new_width = 250 - (2 * old_origin.x) - distance: 233.5881016 \ No newline at end of file + 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 diff --git a/config/squished.yaml b/config/squished.yaml index 0c47cd0..aff9e70 100644 --- a/config/squished.yaml +++ b/config/squished.yaml @@ -5,7 +5,7 @@ zones: columns: - name: pinky rotate: -5 - origin: [7, -7] + origin: [7, -10] - name: ring stagger: 12 - name: middle @@ -51,29 +51,22 @@ zones: - name: near padding: 16 column_wire: ring - # TODO: this is just a test for Dan - - name: nearer - column_wire: pinky rows: - name: thumb angle: -20 mirror: - ref: pinky_bottom + ref: pinky_home # The mk1's origin was the bottom left corner of the bottom pinky key. # But it later got rotated by the bottom *right* corner as the pinky angle # and then rotated again for the inter-half angle so [0, 0] was nowhere on # the actual result. # - # Since the new origin is the center of the pinky bottom, we have to convert + # Since the new origin is the center of the pinky home, we have to convert # the old, round 250 width to this new coordinate system if we want backward - # compatibility. The following snippet was used to arrive at 233.5881016. + # compatibility. The following snippet was used to arrive at this distance. # - # old_origin = new Point(7, 7) + # old_origin = new Point(7, 7 + 19) # old_origin.rotate(5, [14, 0]) # old_origin.rotate(-20, [0, 0]) # new_width = 250 - (2 * old_origin.x) - # - # TODO: Hahaaa, the squishing fails, because the width reference points are - # NOT stationary! gotta move to distances between some other points - # (definitely something from among the HOME positions!!!) - distance: 233.5881016 \ No newline at end of file + distance: 223.7529778 \ No newline at end of file diff --git a/helpers/points.js b/helpers/points.js index 9b9d0c6..04cbc1c 100644 --- a/helpers/points.js +++ b/helpers/points.js @@ -1,6 +1,8 @@ const m = require('makerjs') const fs = require('fs-extra') +const u = require('./utils') + const Point = exports.Point = class Point { constructor(x=0, y=0, r=0, meta={}) { if (Array.isArray(x)) { @@ -54,7 +56,7 @@ const Point = exports.Point = class Point { this.x, this.y, this.r, - this.meta + u.deepcopy(this.meta) ) } } @@ -186,14 +188,18 @@ exports.parse = (config) => { x += (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) mp.meta.mirrored = true - const mname = `mirror_${name}` - mirrored_points[mname] = mp + delete mp.meta.asym + mirrored_points[`mirror_${name}`] = mp + if (p.meta.col.asym == 'right' || p.meta.row.asym == 'right') { + p.meta.col.skip = true + } } Object.assign(points, mirrored_points) } - + const filtered = {} for (const [k, p] of Object.entries(points)) { if (p.meta.col.skip || p.meta.row.skip) continue diff --git a/helpers/utils.js b/helpers/utils.js new file mode 100644 index 0000000..9397be5 --- /dev/null +++ b/helpers/utils.js @@ -0,0 +1,14 @@ +const m = require('makerjs') +const fs = require('fs-extra') + +exports.deepcopy = (value) => JSON.parse(JSON.stringify(value)) + +exports.dump_model = (model, file='model', json=false) => { + const assembly = m.model.originate({ + model, + units: 'mm' + }) + + fs.writeFileSync(`${file}.dxf`, m.exporter.toDXF(assembly)) + if (json) fs.writeFileSync(`${file}.json`, JSON.stringify(assembly, null, ' ')) +} \ No newline at end of file