diff --git a/bins/index.html b/bins/index.html
index 33912ea..b4927b6 100644
--- a/bins/index.html
+++ b/bins/index.html
@@ -2957,6 +2957,30 @@
Your drawers
return [s + lt, e + g * dp];
});
}
+/* The notch a tab fits into, cut up into the floor of the piece across the seam from it
+ (pieceConnectors' `notches` or `pnotches`), as one closed solid. buildPiece cuts it, and
+ mountLimits keeps the mounting sites out of it; one shape, so the two cannot drift. */
+function tabNotch(cfg, nb, pad) {
+ if (cfg.connector === 'puzzle')
+ return extrudePoly(puzzleShape(nb.edge, nb.e, nb.s, cfg.puzzle, cfg.puzzle.clr, true),
+ -0.5, pad - 0.4);
+ const t = cfg.tab, H = pad + cfg.plateHeight;
+ const nWr = t.wr + 2*t.clr, nWt = t.wt + 2*t.clr, nDp = t.dp + t.clr;
+ // 4-pt taper: no vertex sits exactly on the region side plane; jitter breaks
+ // residual coincidences with ring geometry
+ const J = 0.0017, BK = 1.0, e = nb.e, s = nb.s + J;
+ let pts;
+ if (nb.edge === '+x' || nb.edge === '-x') {
+ const g = nb.edge === '-x' ? 1 : -1; // cut extends INTO the piece
+ pts = [[e - g*BK, s - nWr/2], [e + g*nDp, s - nWt/2],
+ [e + g*nDp, s + nWt/2], [e - g*BK, s + nWr/2]];
+ } else {
+ const g = nb.edge === '-y' ? 1 : -1;
+ pts = [[s - nWr/2, e - g*BK], [s - nWt/2, e + g*nDp],
+ [s + nWt/2, e + g*nDp], [s + nWr/2, e - g*BK]];
+ }
+ return extrudePoly(pts, -0.503, Math.min(t.h + 0.2, H - 0.8));
+}
// generic underside key halves (recess cut into one piece's edge region)
function keyHalf(type, edge, e, s, prm, grow) {
// returns polygon extending prm depth into the piece, 0.5 past the seam
@@ -3904,6 +3928,43 @@ Your drawers
facets graze the floor's own triangulation — screws at a 36 mm pitch leaked 192 edges
with 0.65 mm to spare. */
const MOUNT_WALL = 1.0;
+/* How near a pocket's ceiling may come to a dovetail notch's before the two count as
+ level, and how near its walls may come to any joint's cut without breaking into it.
+ See mountLimits. */
+const MOUNT_LEVEL = 0.05, MOUNT_SEAM = 0.01;
+/* How far a mounting bore about (x, y) can grow before it meets any of `segs`, as the
+ radius of the circle through its corners: the polygon cylinder() cuts, `sides` flats
+ with a corner at every 2πk/sides from +x. A point is in that polygon when it stands no
+ further out along any flat's normal than R cos(π/sides), so along one segment the
+ least R that takes a point of it in is at an end, or where the segment crosses the
+ line out through a corner, on which a point's R is its distance. */
+function boreReach(sides, segs, x, y) {
+ const step = 2 * Math.PI / sides, h = Math.cos(step / 2);
+ const cx = [], cy = [], nx = [], ny = [];
+ for (let k = 0; k < sides; k++) {
+ cx.push(Math.cos(k * step)); cy.push(Math.sin(k * step));
+ nx.push(Math.cos((k + 0.5) * step)); ny.push(Math.sin((k + 0.5) * step));
+ }
+ const at = (dx, dy) => {
+ let m = -Infinity;
+ for (let k = 0; k < sides; k++) m = Math.max(m, dx * nx[k] + dy * ny[k]);
+ return m / h;
+ };
+ let r = Infinity;
+ for (const [a, b] of segs) {
+ const ax = a[0] - x, ay = a[1] - y, ex = b[0] - a[0], ey = b[1] - a[1];
+ r = Math.min(r, at(ax, ay), at(ax + ex, ay + ey));
+ for (let k = 0; k < sides; k++) {
+ const den = ex * cy[k] - ey * cx[k];
+ if (Math.abs(den) < 1e-12) continue;
+ const t = (ay * cx[k] - ax * cy[k]) / den;
+ if (t < 0 || t > 1) continue;
+ const s = (ax + t * ex) * cx[k] + (ay + t * ey) * cy[k];
+ if (s >= 0) r = Math.min(r, s);
+ }
+ }
+ return r;
+}
/* The largest mounting cuts this configuration has room for, as diameters and depths in
the units the page's fields use. Magnets and screws sit holeOffset (13 mm, the spec's)
from each cell centre at ANY pitch, so the room round them shrinks with the pitch:
@@ -3918,11 +3979,21 @@ Your drawers
* - in a corner boss: it must stay in the boss, which is shorter than the solid floor
* and does not grow with the pocket, so it also caps the depth.
*
+ * And whichever way it opens, it must stay out of a joint's cut in the floor beside it:
+ * a key's recess, or the notch a tab fits into, where a dovetail's lets a pocket from
+ * beneath in only so far as its tab leaves room. That one needs `layout`, which says
+ * where the seams are; without it no joint is counted.
+ *
* These are measurements, not field ranges, and can come out below the field's minimum
* or negative — a screw shank at a 34 mm pitch has −0.1 mm. That means no cut of any size
* fits there; the page turns it into a check on the design rather than a range for the
- * field (src/ui.js readNumber), since no number typed into the field could fix it. */
-function mountLimits(cfg) {
+ * field (src/ui.js readNumber), since no number typed into the field could fix it.
+ *
+ * `known` is the `cuts` of an earlier answer for the same design on the same layout,
+ * with only the mounting sizes changed since: the joint's cuts are not measured again
+ * unless the floor has moved, which moves their ceilings. The page reads the magnet's
+ * size last and asks again for it, after the screws' sizes have settled the floor. */
+function mountLimits(cfg, layout, known) {
const half = cfg.pitch / 2, off = cfg.holeOffset;
const tol = cfg.tolerance === 'tight' ? +0.1 : cfg.tolerance === 'loose' ? -0.1 : 0;
// distance from a point at (s, s) to the edge of a rounded square of half-size h,
@@ -3940,7 +4011,7 @@ Your drawers
const inBoss = Math.min(roomIn(BOSS_W, BOSS_R, s), s) - MOUNT_WALL;
const bosses = cfg.baseMode === 'bosses';
const top = bosses ? inBoss : onFloor, under = bosses ? inBoss : inCell;
- const r10 = (x) => Math.floor(x * 10 + 1e-9) / 10; // the fields step in tenths
+ const r10 = (x) => Math.floor(x * 10 + 1e-9) / 10; // a cap is given in tenths, rounded down
/* A cell's four sites are 2 × holeOffset apart, 26 mm, so past a pitch of about 50 mm
the room above lets a cut reach the one beside it before it reaches anything else:
two 1-inch magnet pockets met at a 55 mm pitch and left 52 open edges. Each cut stops
@@ -3948,18 +4019,237 @@ Your drawers
stop at 12.5 mm and the wall between two pockets is at least MOUNT_WALL, 1 mm. */
const beside = off - MOUNT_WALL / 2;
const fit = (r) => Math.min(r, beside);
- const room = fit(cfg.magnetSide === 'top' ? top : under);
+ /* A joint cut up into the solid floor beside the sites: the recess a key or an H-clip
+ is put into from beneath (keyPlan's 'recess', in the floor or in the wall), or the
+ notch a dovetail or puzzle tab fits into (tabNotch). Each starts under the plate, as
+ a magnet pocket from beneath, a counterbore and a shank do, so any of those that
+ reaches one in plan has broken into it. A magnet from above meets it unless the
+ pocket's floor stands at least MOUNT_SKIN over the cut's ceiling. The housings a key
+ is dropped into from above (keySiteOps' 'cup' and 'snaptop') start 1.3 mm or more
+ over the socket floor: a pocket from above stops under them, and a shank, which
+ stays on the socket floor, is in the socket's open air up there.
+
+ Measured off the solids buildPiece cuts, at the sites it cuts pockets at: whole cells
+ only, so a housing beside a half cell or a margin is measured from the whole cell on
+ the other side of it, which is the only one with pockets. A corner boss is left out:
+ its pocket is cut in the boss, a shell of its own that no joint is cut from.
+
+ Issue #64: a bowtie in the floor at 42 mm, with magnets from beneath, built 12 bad
+ edges at 7.9 mm and 19 at 10, with Download on; puzzle tabs at 36 to 40 mm built 26
+ to 86 with the spec's 6.5 × 2.4 magnet. The pocket had run into the cut with its
+ ceiling level with the cut's: a 2 mm magnet or the default counterbore with a key's
+ 2 mm recess, a 2.4 mm magnet with a tab's notch. The two ceilings then share a face
+ that two subtractions split their own ways. All 86 pockets tried level with a cut
+ went bad; moved 0.001 mm up or down, 3 of them did, and 0.003 mm or more, none.
+ MOUNT_LEVEL counts 0.05 mm as level.
+
+ Off the level, what a pocket may do depends on the cut, measured on random designs
+ past where a pocket first meets one: keys and tabs, magnets from both sides, screw
+ heads and shanks, halves and margins, pitches that are not round numbers.
+ - A key's recess, an H-clip's or a puzzle tab's notch takes no pocket at all ('cut').
+ One a sliver in has gone bad off the level: 0.019 mm into a snap key's recess at
+ 36.52 mm, with a 0.5 mm fit clearance, at four depths on main. Let in wherever
+ the magnet or screw stayed clear of the key or tab, 7 of 2,519 such pockets at
+ the default fit or tighter went bad, 0.02 to 0.14 mm in, and 8 of 1,151 at
+ looser fits, 0.2 to 0.65 mm in.
+ - A dovetail's notch takes a pocket from beneath, a sliver or deep, unless it is
+ level with the notch ('level') or the magnet or screw in it would reach the other
+ piece's tab, which stands the fit clearance inside the notch ('part'). None of
+ 3,699 such designs went bad, 1,086 of them on the page's design at 40.5 to
+ 44.5 mm. So a 12.7 mm magnet at 42 mm, 2 or 3 mm thick, is taken: its pocket is
+ 0.04 to 0.09 mm into the notch and the magnet 0.24 mm clear of the tab.
+ - A pocket from above meets any of them unless its floor stands a layer over the
+ cut's ceiling ('floor').
+ The pocket is measured as fastenerCutter cuts it, as a polygon (boreReach), not by the
+ circle through its corners, which kept sizes out that came a flat's width short.
+
+ A pocket that stops short of a cut stops MOUNT_SEAM short. The weld in healCsgSeams
+ takes points VTOL apart for one, and a thinner wall than a few of those can come out
+ welded through: 4 of 715 pockets less than 0.005 mm short went bad, and none of 1,941
+ from 0.005 to 0.03 mm. Under a dovetail's notch that leaves a gap of refused sizes
+ below the largest (`gaps`), between the one that stops MOUNT_SEAM short and the one
+ that breaks in. Past the weld's reach there is still the lottery the room measured
+ here does not see, about one design in a thousand, single sizes with clean ones on
+ either side, and it needs the pocket and the cut together: a 14.1 mm counterbore 2.4
+ to 3 mm deep, 0.09 mm short of a dovetail's notch at 43.17 mm, loose, folds an edge
+ at the notch's corner, byte for byte as on main, and is clean at 2.35 mm deep, at
+ 14.075 and 14.125 mm across, at every size from there into the notch, and with no
+ counterbore. A guard out that far would refuse sizes that build clean on both sides
+ of it and still miss the next, 0.1 mm off. A wall of 1 mm would refuse the 6 mm
+ magnet from beneath with a bowtie at 42 mm, which has 0.84 mm to spare and always
+ built clean. */
+ const pad = platePad(cfg), again = !!known && known.pad === pad;
+ /* Each cut as { top, sites }: its ceiling, and each site in reach of it as how far a
+ bore's corner circle (`room`) and the bores themselves (`bore`, by their sides) can
+ grow before they meet the cut, and a magnet or screw (`body`) before it meets the
+ part in it. */
+ const jointCuts = again ? known.list : [];
+ /* Room past the most the cell or the floor leaves cannot stop a size, so nothing
+ further off than that is measured, and nothing at all where neither leaves any. A
+ plate the page will build has at most 900 cells; at 30 × 30 with puzzle tabs this
+ is a few milliseconds, on every redraw. */
+ const reach = Math.max(fit(top), fit(under));
+ if (layout && !again && !bosses && cfg.connector !== 'none' && reach > 0) {
+ const plan = keyPlan(cfg), H = pad + cfg.plateHeight;
+ /* A cut's footprint, as the segments its walls stand on, its extent and its ceiling,
+ for each seam it can be cut from, and the part's that goes in it: the key's half,
+ or the tab of the piece across the seam, as buildPiece stands it there, the fit
+ clearance inside the cut. Every cut from one seam is the same solid moved along it
+ (keyHalf, puzzleShape, tabNotch), so it is worked out at the origin once and each
+ site is moved the other way instead. */
+ const shapes = {};
+ const ring = (pts) => pts.map((p, i) => [p, pts[(i + 1) % pts.length]]);
+ const shapeOf = (edge) => {
+ if (shapes[edge]) return shapes[edge];
+ const at = { edge, e: 0, s: 0 };
+ const solid = plan.kind === 'recess'
+ ? keySiteOps(plan.kind, plan.shape, plan.prm, plan.clr, edge, 0, 0, H).cut
+ : tabNotch(cfg, at, pad);
+ const segs = [], bb = [Infinity, Infinity, -Infinity, -Infinity];
+ let ceiling = -Infinity;
+ for (const p of solid) {
+ for (const v of p.verts) {
+ ceiling = Math.max(ceiling, v[2]);
+ bb[0] = Math.min(bb[0], v[0]); bb[1] = Math.min(bb[1], v[1]);
+ bb[2] = Math.max(bb[2], v[0]); bb[3] = Math.max(bb[3], v[1]);
+ }
+ if (Math.abs(p.plane.n[2]) > 1e-9) continue;
+ const a = p.verts[0], b = p.verts.find((v) => Math.hypot(v[0] - a[0], v[1] - a[1]) > 1e-9);
+ if (b) segs.push([a, b]);
+ }
+ const part = plan.kind === 'recess' ? keyHalf(plan.shape, edge, 0, 0, plan.prm, 0)
+ : cfg.connector === 'puzzle' ? puzzleShape(OPP[edge], 0, 0, cfg.puzzle, 0, false)
+ : tabFootprint(OPP[edge], 0, 0, cfg.tab.wr, cfg.tab.wt, cfg.tab.dp, 0.8);
+ // the ceiling to the micron: a notch's is 2.2 + 0.2, 2.4000000000000004 as summed
+ const roof = Math.round(ceiling * 1e6) / 1e6;
+ return (shapes[edge] = { segs, bb, ceiling: roof, part: ring(part) });
+ };
+ // how far a point is from the footprint, less than none inside it
+ const from = (segs, x, y) => {
+ let d = Infinity, inside = false;
+ for (const [a, b] of segs) {
+ const dx = b[0] - a[0], dy = b[1] - a[1];
+ const t = Math.max(0, Math.min(1, ((x - a[0])*dx + (y - a[1])*dy) / (dx*dx + dy*dy)));
+ d = Math.min(d, Math.hypot(a[0] + t*dx - x, a[1] + t*dy - y));
+ if ((a[1] > y) !== (b[1] > y) && x < a[0] + (y - a[1]) * dx / dy) inside = !inside;
+ }
+ return inside ? -d : d;
+ };
+ for (const piece of layout.pieces) {
+ const conn = pieceConnectors(cfg, layout, piece);
+ // the cuts buildPiece makes in this piece: notches for tabs, recesses for keys
+ const cuts = [...conn.notches, ...conn.pnotches, ...(plan.kind !== 'recess' ? []
+ : conn.keyed.filter((bo) => !(plan.junction && offJunction(bo, cfg.pitch, piece))))];
+ for (const bo of cuts) {
+ const { segs, bb, ceiling, part } = shapeOf(bo.edge);
+ const across = bo.edge === '+x' || bo.edge === '-x';
+ const ox = across ? bo.e : bo.s, oy = across ? bo.s : bo.e;
+ // the whole cells with a site in reach of it (a half cell has none; see buildPiece)
+ const cells = (lo, hi, m, n) => [Math.max(0, Math.floor((lo - reach - off - half - m) / cfg.pitch)),
+ Math.min(n - 1, Math.ceil((hi + reach + off - half - m) / cfg.pitch))];
+ const [i0, i1] = cells(bb[0] + ox, bb[2] + ox, piece.mL, piece.nx);
+ const [j0, j1] = cells(bb[1] + oy, bb[3] + oy, piece.mF, piece.ny);
+ const sites = [];
+ for (let i = i0; i <= i1; i++) for (let j = j0; j <= j1; j++)
+ for (const sx of [-1, 1]) for (const sy of [-1, 1]) {
+ const x = piece.mL + i*cfg.pitch + half + sx*off - ox;
+ const y = piece.mF + j*cfg.pitch + half + sy*off - oy;
+ if (x < bb[0] - reach || x > bb[2] + reach || y < bb[1] - reach || y > bb[3] + reach) continue;
+ // the bores and the part stand further off than the corner circle, or as far
+ const room = from(segs, x, y);
+ if (room >= reach) continue;
+ const bore = (n) => room > 0 ? boreReach(n, segs, x, y) : room;
+ sites.push({ room, body: from(part, x, y), bore: { 12: bore(12), 14: bore(14) } });
+ }
+ if (sites.length) jointCuts.push({ top: ceiling, sites });
+ }
+ }
+ }
+ /* The bores as fastenerCutter cuts them, in one place: how many sides, and the largest
+ size whose corners stay inside a radius. A magnet's corners are 0.1 mm over its
+ radius, or out to where its flats stand on that radius if that is further; a screw's
+ bores have their corners on its size. */
+ const BORE = {
+ magnetD: { sides: 14, fits: (r) => 2 * Math.min(r - 0.1, r * Math.cos(Math.PI / 14)) },
+ screwHeadD: { sides: 14, fits: (r) => 2 * r },
+ screwHoleD: { sides: 12, fits: (r) => 2 * r },
+ };
+ // the room the cell, the floor or a boss leaves, and the hole beside
+ const own = { magnetD: fit(cfg.magnetSide === 'top' ? top : under), screwHoleD: fit(top), screwHeadD: fit(under) };
+ // a dovetail's notch takes a pocket from beneath that breaks into it; every other cut does not
+ const notch = cfg.connector === 'dovetail';
+ /* What the joint's cuts leave one size, as { cap, why, near }: the largest size, and what
+ stops it: 'cut', a pocket that would break into a key's recess or a puzzle tab's notch;
+ 'floor', one from above that leaves no layer of floor over a cut; 'level', one from
+ beneath as deep as a dovetail's notch; 'part', a magnet or screw that would reach the
+ tab in one. Each stops MOUNT_SEAM short of the cut. `near` is where that leaves sizes
+ under the cap refused, as [from, to]: a dovetail's notch, which a pocket may break
+ into, but not stop just short of. */
+ const jointFor = (f) => {
+ const { sides, fits } = BORE[f];
+ const above = f === 'magnetD' && cfg.magnetSide === 'top';
+ // how high a pocket from beneath goes; a shank goes through
+ const ceiling = f === 'magnetD' ? cfg.magnetH : f === 'screwHeadD' ? cfg.screwHeadDepth : Infinity;
+ let cap = Infinity, why = false;
+ const near = [];
+ for (const c of jointCuts) {
+ // a pocket from above clears a cut whose ceiling it leaves a layer of floor over
+ if (above && !(c.top + MOUNT_SKIN > pad - cfg.magnetH + 1e-6)) continue;
+ /* Level within MOUNT_LEVEL, measured to the micron, so a pocket that far above the
+ notch's ceiling and one that far below it are taken alike: 2.35 and 2.45 mm deep
+ against a notch 2.4 mm high, which both build clean. Unrounded, 2.45 counted as
+ level, and with the ceiling alone rounded 2.35 would. */
+ const level = Math.round(Math.abs(ceiling - c.top) * 1e6) / 1e6 < MOUNT_LEVEL;
+ const stop = above ? 'floor' : !notch ? 'cut' : level ? 'level' : 'part';
+ for (const s of c.sites) {
+ const short = fits(s.bore[sides] - MOUNT_SEAM);
+ const size = stop === 'part' ? 2 * s.body : short;
+ if (size < cap) { cap = size; why = stop; }
+ if (stop === 'part') near.push([short, fits(s.bore[sides])]);
+ }
+ }
+ return { cap, why, near };
+ };
+ const sizes = {}, joint = {}, gaps = {};
+ for (const f of ['magnetD', 'screwHoleD', 'screwHeadD']) {
+ const cell = BORE[f].fits(own[f]), J = jointFor(f);
+ let size = r10(Math.min(cell, J.cap));
+ joint[f] = J.cap < cell && J.why;
+ /* The sizes `near` refuses, out to the hundredths either side, since the field takes
+ hundredths: each gap is [from, to], both taken. A window is about 0.02 mm wide, so
+ rounded out to the tenths as the cap is, it refused up to a tenth that builds clean
+ (5.51 to 5.69 at 36 mm). One that reaches the cap brings it down to where it starts. */
+ const out = [];
+ for (const [a, b] of J.near.sort((x, y) => x[0] - y[0])) {
+ const from = Math.floor(a * 100 + 1e-9) / 100, to = (Math.floor(b * 100 + 1e-9) + 1) / 100;
+ if (to <= 0) continue;
+ if (out.length && from < out[out.length - 1][1]) out[out.length - 1][1] = Math.max(out[out.length - 1][1], to);
+ else out.push([from, to]);
+ }
+ gaps[f] = [];
+ for (const [from, to] of out) {
+ if (from >= size) break;
+ if (to > size) { size = from; joint[f] = 'near'; break; }
+ gaps[f].push([from, to]);
+ }
+ sizes[f] = size;
+ }
return {
- // a magnet pocket's corners are 0.1 mm over the magnet's radius, or out to where its
- // flats stand on that radius if that is further (fastenerCutter)
- magnetD: r10(2 * Math.min(room - 0.1, room * Math.cos(Math.PI / 14))),
- // a screw's bores have their corners on its size
- screwHoleD: r10(2 * fit(top)),
- screwHeadD: r10(2 * fit(under)),
+ magnetD: sizes.magnetD,
+ screwHoleD: sizes.screwHoleD,
+ screwHeadD: sizes.screwHeadD,
// in the solid floor the pad grows to suit, so only a boss caps the depth
depth: bosses ? r10(BOSS_H - MOUNT_SKIN) : Infinity,
// which of the sizes the cut beside it stops, rather than the floor, cell or boss
- beside: { magnetD: room === beside, screwHoleD: top >= beside, screwHeadD: under >= beside },
+ beside: { magnetD: own.magnetD === beside && !joint.magnetD,
+ screwHoleD: own.screwHoleD === beside && !joint.screwHoleD,
+ screwHeadD: own.screwHeadD === beside && !joint.screwHeadD },
+ // and which a joint's cut stops, before any of those, and how (jointFor)
+ joint,
+ // sizes under the largest refused all the same, as [from, to] with both ends taken
+ gaps,
+ // what was measured of the joint's cuts, for `known`
+ cuts: { pad, list: jointCuts },
};
}
@@ -4177,7 +4467,38 @@ Your drawers
}
return out;
};
- const fastenerFoot = wallsAt(0), fastenerTop = pad > 0.01 ? wallsAt(pad) : [];
+ /* The same, its corners only. Where the walls of two bores were unioned (a counterbore,
+ its screw's shank), the BSP split each wall along the other's planes, and wallsAt
+ hands back those split points as well: two on every flat of the shank, 24 points on
+ the socket floor that are no corner of anything. A 2.4 mm shank under a 4.8 mm head
+ at 44.08 mm, with loose tolerance, had a spoke within FAN_CLEAR of one of them from
+ every point fanCentre tries, so the socket floor's fan never moved and the cell
+ shipped with six open edges. A corner is where two walls that are not in line meet;
+ a split point is where one wall was cut in two. From the corners alone the fan moves
+ 0.2 mm and the floor closes. Only the socket floor's list, which only an open cell's
+ refan reads (buildPiece), so every cell that came out closed is built as before. */
+ const cornersAt = (z) => {
+ const ends = new Map(); // a wall end, to the directions of the walls that end there
+ for (const p of cellFastener || []) {
+ const zs = p.verts.map((v) => v[2]);
+ if (!(Math.min(...zs) < z && Math.max(...zs) > z) || Math.abs(p.plane.n[2]) > 1e-9) continue;
+ const d = [-p.plane.n[1], p.plane.n[0]]; // along the wall
+ let lo = null, hi = null;
+ for (const v of p.verts) {
+ const t = v[0]*d[0] + v[1]*d[1];
+ if (!lo || t < lo[0]) lo = [t, v];
+ if (!hi || t > hi[0]) hi = [t, v];
+ }
+ for (const [, v] of [lo, hi]) {
+ const k = `${v[0].toFixed(6)} ${v[1].toFixed(6)}`;
+ if (!ends.has(k)) ends.set(k, { at: [v[0], v[1]], dirs: [] });
+ ends.get(k).dirs.push(d);
+ }
+ }
+ return [...ends.values()].filter(({ dirs }) =>
+ dirs.some((a) => dirs.some((b) => Math.abs(a[0]*b[1] - a[1]*b[0]) > 1e-6))).map((e) => e.at);
+ };
+ const fastenerFoot = wallsAt(0), fastenerTop = pad > 0.01 ? cornersAt(pad) : [];
// ---- connectors ----
const conn = pieceConnectors(cfg, layout, piece);
@@ -4571,7 +4892,9 @@ Your drawers
* And once every cell is built, the shells settle cut again are checked as a whole, with
* those beside them: if they have more bad edges (checkManifold) than they had before,
* or more open or turned over (healCsgSeams), every one goes back to its first cut. So
- * settle never leaves a piece worse than it found it, whatever order the cells come in.
+ * settle never leaves those shells worse than it found them, whatever order the cells
+ * come in. What is made after the check is not judged by it: the dovetail and puzzle
+ * tabs, and what the top-insert pass cuts again (see the check below).
* `alt` and `pocket` are the cuts a cell was last taken with, so a cell cut again for
* one reason keeps what it was cut again for the other. */
const POCKET_TRIES = 7;
@@ -4744,22 +5067,7 @@ Your drawers
(nb.edge === '+x' ? Math.abs(x1 - W) : Math.abs(x0)) < nDp + 0.2)
: (nb.s > x0 - nWt && nb.s < x1 + nWt &&
(nb.edge === '+y' ? Math.abs(y1 - D) : Math.abs(y0)) < nDp + 0.2);
- if (near) {
- // 4-pt taper: no vertex sits exactly on the region side plane; jitter breaks
- // residual coincidences with ring geometry
- const J = 0.0017, BK = 1.0, e = nb.e, s = nb.s + J;
- let pts;
- if (nb.edge === '+x' || nb.edge === '-x') {
- const g = nb.edge === '-x' ? 1 : -1; // cut extends INTO the piece
- pts = [[e - g*BK, s - nWr/2], [e + g*nDp, s - nWt/2],
- [e + g*nDp, s + nWt/2], [e - g*BK, s + nWr/2]];
- } else {
- const g = nb.edge === '-y' ? 1 : -1;
- pts = [[s - nWr/2, e - g*BK], [s - nWt/2, e + g*nDp],
- [s + nWt/2, e + g*nDp], [s + nWr/2, e - g*BK]];
- }
- cuts.notch.push(...extrudePoly(pts, -0.503, Math.min(t.h + 0.2, H - 0.8)));
- }
+ if (near) cuts.notch.push(...tabNotch(cfg, nb, pad));
}
for (const bo of keyed) {
if (plan.junction && offJunction(bo, pitch, piece))
@@ -4789,9 +5097,7 @@ Your drawers
(pn.edge === '+x' ? Math.abs(x1 - W) : Math.abs(x0)) < reach)
: (pn.s > x0 - cfg.puzzle.lobeR*2 && pn.s < x1 + cfg.puzzle.lobeR*2 &&
(pn.edge === '+y' ? Math.abs(y1 - D) : Math.abs(y0)) < reach);
- if (near) cuts.puzzle.push(
- ...extrudePoly(puzzleShape(pn.edge, pn.e, pn.s, cfg.puzzle, cfg.puzzle.clr, true),
- -0.5, pad - 0.4));
+ if (near) cuts.puzzle.push(...tabNotch(cfg, pn, pad));
}
/* None in a half cell. A half-size bin's quarter feet carry no holes (feetHolesOff
in bins/bin.js), and where a half socket's would go is not settled: a whole
@@ -4915,8 +5221,10 @@ Your drawers
Only here, not on every cell: a 6 mm magnet from above at 42 mm has a spoke 2.3
microns from a corner in every cell and comes out closed, as most do. And only
where the fan moves and the cell is open at the floor's height: a cell open
- somewhere else, as a pocket that meets a joint's housing is, or one whose spokes
- are already clear, would be cut again for the same result. A bowtie plate at
+ somewhere else, as a pocket that meets a joint's housing is, would be cut again
+ for the same result, and so would one whose fan stays where it was, either because
+ its spokes are already clear or because fanCentre finds no point clear of every
+ corner and keeps the centre. A bowtie plate at
45.57 mm with screws, open in every piece on main as well, took twice as long
with every open cell cut again. */
if (region.open && floorAvoid.length && openAt(region, pad)) {
diff --git a/docs/ENGINE.md b/docs/ENGINE.md
index 8d1b491..cc15ae4 100644
--- a/docs/ENGINE.md
+++ b/docs/ENGINE.md
@@ -745,6 +745,56 @@ currently installed):
the fan moves, every cut is taken again on it. Only then: a 6 mm magnet from above at
42 mm has a spoke 2.3 microns from a corner in every cell and is closed, and a cell open
somewhere else (a pocket meeting a joint's housing) gains nothing from a new floor.
+ Corners, not every point a wall stands on: where a counterbore and its shank were
+ unioned, the BSP split each flat of the shank along the head's planes, and with those
+ split points counted as well (24 on the socket floor, against the shank's 12 corners)
+ a 2.4 mm shank under a 4.8 mm head at 44.08 mm, loose, had a point within `FAN_CLEAR`
+ of every centre `fanCentre` tried. The fan stayed put and the cell shipped six edges
+ open. From the corners alone it moves 0.2 mm and the floor closes.
+- **A pocket that reaches a joint's cut goes bad where the two ceilings are level.** A
+ key's recess, an H-clip's and a tab's notch are all cut up from under the plate, as a
+ magnet pocket from beneath and a counterbore are. Run into one, the pocket comes out
+ closed at nearly any depth but one: the recess's 2 mm (a 2 mm magnet, the default counterbore)
+ or the notch's 2.4 (the spec's 6.5 × 2.4 magnet), where the two ceilings share a face
+ that two subtractions each split their own way. A bowtie in the floor at 42 mm left 12
+ edges open at 7.9 mm and 19 at 10; puzzle tabs at 36 to 40 mm left 26 to 86 with the
+ spec's magnet. All 86 pockets tried level with a cut went bad; 0.001 mm off it, 3 did,
+ and 0.003 mm or more off it, none. Off the level it depends on the cut, and `mountLimits`
+ measures every mounting site of a whole cell against each cut on the layout, by the
+ pocket's own polygon (`boreReach`), not the circle through its corners:
+ - **A key's recess, an H-clip's or a puzzle tab's notch takes no pocket.** A sliver in
+ can go bad off the level too: 0.019 mm into a snap key's recess at 36.52 mm, with a
+ 0.5 mm fit clearance, on main at four depths. Let in wherever the magnet or screw stays
+ clear of the key or tab, 7 of 2,519 such pockets at the default fit or tighter went bad
+ (0.02 to 0.14 mm in), and 8 of 1,151 at looser fits (0.2 to 0.65 mm in).
+ - **A dovetail's notch takes a pocket from beneath**, a sliver or deep, unless it is
+ level with the notch (within 0.05 mm either way, `MOUNT_LEVEL`, measured to the
+ micron) or the magnet or screw in it would reach the other piece's tab,
+ which stands the fit clearance inside the notch. None of 3,699 such designs went bad,
+ 1,086 of them on the page's design at 40.5 to 44.5 mm. A 12.7 mm magnet at 42 mm, 2 or
+ 3 mm thick, is taken: its pocket is 0.04 to 0.09 mm into the notch and the magnet
+ 0.24 mm clear of the tab. 2.4 mm thick it is level, built 96 bad edges, and is refused.
+ - **A pocket from above** meets any of them unless its floor stands a layer over the
+ cut's ceiling. The housings a key is dropped into from above start 1.3 mm over the
+ socket floor and nothing reaches them, and a pocket in a corner boss is left out: the
+ boss is a shell of its own, and no joint is cut from it.
+
+ A pocket that stops short of a cut stops 0.01 mm short (`MOUNT_SEAM`): the weld in
+ `healCsgSeams` takes points `VTOL` apart for one, and a thinner wall can come out welded
+ through. 4 of 715 pockets less than 0.005 mm short went bad, and none of 1,941 from 0.005
+ to 0.03 mm. Under a dovetail's notch that leaves a few hundredths of a millimetre of
+ refused sizes below the largest, between the pocket that stops 0.01 mm short and the one
+ that breaks in, about 0.02 mm wide and rounded out to the hundredth either side, as the
+ field takes them: at 36 mm on the page's design 5.59, 5.6, 5.73 and 5.74 mm are refused,
+ and 5.58, 5.61, 5.72 and 5.75 are taken. The page says so at the field and names the
+ sizes taken either side. Past the weld's reach there is still the
+ lottery the room cannot see, about one design in a thousand, single sizes with clean
+ ones on either side, and it needs the pocket and the cut together: a 14.1 mm
+ counterbore 2.4 to 3 mm deep, 0.09 mm short of a dovetail's notch at 43.17 mm, loose,
+ folds an edge at the notch's corner, byte for byte as main does, and is clean at 2.35 mm
+ deep, at 14.075 and 14.125 mm across, at every size from there into the notch, and with
+ no counterbore. A guard out that far would refuse sizes that build clean on both sides
+ of it and still miss the next, 0.1 mm off.
- **A joint's cut is the same lottery, and below 16 mm it comes up often.** The socket's
straight walls run only 2.5 mm either side of a cell's middle at 13.5 mm, so every
housing, notch and clip pocket crosses its corner arcs and cones, at points that move
@@ -782,7 +832,9 @@ currently installed):
nothing cleared (10.1 to 11.1 mm magnets at 47.91 to 50.05 mm, clean on main). And once
the cells are built, if the shells `settle` cut again have more bad edges with those
beside them than they started with, or more open or turned over, they all go back to
- their first cut. Two cups put in
+ their first cut. That check sees only those shells and their neighbours as the cells
+ left them: the dovetail and puzzle tabs are made after it, and the top-insert pass cuts
+ its housings out of shells after it, so neither is judged by it. Two cups put in
from above from each side of a piece one cell deep meet face to face at 14.44 mm (twice a
cup's reach), and there they are built as one solid with `csgUnion`.
- **A face that is nothing but a straight line has no middle.** A weld that closes a
diff --git a/index.html b/index.html
index 8fb1296..20920a6 100644
--- a/index.html
+++ b/index.html
@@ -2744,6 +2744,30 @@ Your drawers
return [s + lt, e + g * dp];
});
}
+/* The notch a tab fits into, cut up into the floor of the piece across the seam from it
+ (pieceConnectors' `notches` or `pnotches`), as one closed solid. buildPiece cuts it, and
+ mountLimits keeps the mounting sites out of it; one shape, so the two cannot drift. */
+function tabNotch(cfg, nb, pad) {
+ if (cfg.connector === 'puzzle')
+ return extrudePoly(puzzleShape(nb.edge, nb.e, nb.s, cfg.puzzle, cfg.puzzle.clr, true),
+ -0.5, pad - 0.4);
+ const t = cfg.tab, H = pad + cfg.plateHeight;
+ const nWr = t.wr + 2*t.clr, nWt = t.wt + 2*t.clr, nDp = t.dp + t.clr;
+ // 4-pt taper: no vertex sits exactly on the region side plane; jitter breaks
+ // residual coincidences with ring geometry
+ const J = 0.0017, BK = 1.0, e = nb.e, s = nb.s + J;
+ let pts;
+ if (nb.edge === '+x' || nb.edge === '-x') {
+ const g = nb.edge === '-x' ? 1 : -1; // cut extends INTO the piece
+ pts = [[e - g*BK, s - nWr/2], [e + g*nDp, s - nWt/2],
+ [e + g*nDp, s + nWt/2], [e - g*BK, s + nWr/2]];
+ } else {
+ const g = nb.edge === '-y' ? 1 : -1;
+ pts = [[s - nWr/2, e - g*BK], [s - nWt/2, e + g*nDp],
+ [s + nWt/2, e + g*nDp], [s + nWr/2, e - g*BK]];
+ }
+ return extrudePoly(pts, -0.503, Math.min(t.h + 0.2, H - 0.8));
+}
// generic underside key halves (recess cut into one piece's edge region)
function keyHalf(type, edge, e, s, prm, grow) {
// returns polygon extending prm depth into the piece, 0.5 past the seam
@@ -3691,6 +3715,43 @@ Your drawers
facets graze the floor's own triangulation — screws at a 36 mm pitch leaked 192 edges
with 0.65 mm to spare. */
const MOUNT_WALL = 1.0;
+/* How near a pocket's ceiling may come to a dovetail notch's before the two count as
+ level, and how near its walls may come to any joint's cut without breaking into it.
+ See mountLimits. */
+const MOUNT_LEVEL = 0.05, MOUNT_SEAM = 0.01;
+/* How far a mounting bore about (x, y) can grow before it meets any of `segs`, as the
+ radius of the circle through its corners: the polygon cylinder() cuts, `sides` flats
+ with a corner at every 2πk/sides from +x. A point is in that polygon when it stands no
+ further out along any flat's normal than R cos(π/sides), so along one segment the
+ least R that takes a point of it in is at an end, or where the segment crosses the
+ line out through a corner, on which a point's R is its distance. */
+function boreReach(sides, segs, x, y) {
+ const step = 2 * Math.PI / sides, h = Math.cos(step / 2);
+ const cx = [], cy = [], nx = [], ny = [];
+ for (let k = 0; k < sides; k++) {
+ cx.push(Math.cos(k * step)); cy.push(Math.sin(k * step));
+ nx.push(Math.cos((k + 0.5) * step)); ny.push(Math.sin((k + 0.5) * step));
+ }
+ const at = (dx, dy) => {
+ let m = -Infinity;
+ for (let k = 0; k < sides; k++) m = Math.max(m, dx * nx[k] + dy * ny[k]);
+ return m / h;
+ };
+ let r = Infinity;
+ for (const [a, b] of segs) {
+ const ax = a[0] - x, ay = a[1] - y, ex = b[0] - a[0], ey = b[1] - a[1];
+ r = Math.min(r, at(ax, ay), at(ax + ex, ay + ey));
+ for (let k = 0; k < sides; k++) {
+ const den = ex * cy[k] - ey * cx[k];
+ if (Math.abs(den) < 1e-12) continue;
+ const t = (ay * cx[k] - ax * cy[k]) / den;
+ if (t < 0 || t > 1) continue;
+ const s = (ax + t * ex) * cx[k] + (ay + t * ey) * cy[k];
+ if (s >= 0) r = Math.min(r, s);
+ }
+ }
+ return r;
+}
/* The largest mounting cuts this configuration has room for, as diameters and depths in
the units the page's fields use. Magnets and screws sit holeOffset (13 mm, the spec's)
from each cell centre at ANY pitch, so the room round them shrinks with the pitch:
@@ -3705,11 +3766,21 @@ Your drawers
* - in a corner boss: it must stay in the boss, which is shorter than the solid floor
* and does not grow with the pocket, so it also caps the depth.
*
+ * And whichever way it opens, it must stay out of a joint's cut in the floor beside it:
+ * a key's recess, or the notch a tab fits into, where a dovetail's lets a pocket from
+ * beneath in only so far as its tab leaves room. That one needs `layout`, which says
+ * where the seams are; without it no joint is counted.
+ *
* These are measurements, not field ranges, and can come out below the field's minimum
* or negative — a screw shank at a 34 mm pitch has −0.1 mm. That means no cut of any size
* fits there; the page turns it into a check on the design rather than a range for the
- * field (src/ui.js readNumber), since no number typed into the field could fix it. */
-function mountLimits(cfg) {
+ * field (src/ui.js readNumber), since no number typed into the field could fix it.
+ *
+ * `known` is the `cuts` of an earlier answer for the same design on the same layout,
+ * with only the mounting sizes changed since: the joint's cuts are not measured again
+ * unless the floor has moved, which moves their ceilings. The page reads the magnet's
+ * size last and asks again for it, after the screws' sizes have settled the floor. */
+function mountLimits(cfg, layout, known) {
const half = cfg.pitch / 2, off = cfg.holeOffset;
const tol = cfg.tolerance === 'tight' ? +0.1 : cfg.tolerance === 'loose' ? -0.1 : 0;
// distance from a point at (s, s) to the edge of a rounded square of half-size h,
@@ -3727,7 +3798,7 @@ Your drawers
const inBoss = Math.min(roomIn(BOSS_W, BOSS_R, s), s) - MOUNT_WALL;
const bosses = cfg.baseMode === 'bosses';
const top = bosses ? inBoss : onFloor, under = bosses ? inBoss : inCell;
- const r10 = (x) => Math.floor(x * 10 + 1e-9) / 10; // the fields step in tenths
+ const r10 = (x) => Math.floor(x * 10 + 1e-9) / 10; // a cap is given in tenths, rounded down
/* A cell's four sites are 2 × holeOffset apart, 26 mm, so past a pitch of about 50 mm
the room above lets a cut reach the one beside it before it reaches anything else:
two 1-inch magnet pockets met at a 55 mm pitch and left 52 open edges. Each cut stops
@@ -3735,18 +3806,237 @@ Your drawers
stop at 12.5 mm and the wall between two pockets is at least MOUNT_WALL, 1 mm. */
const beside = off - MOUNT_WALL / 2;
const fit = (r) => Math.min(r, beside);
- const room = fit(cfg.magnetSide === 'top' ? top : under);
+ /* A joint cut up into the solid floor beside the sites: the recess a key or an H-clip
+ is put into from beneath (keyPlan's 'recess', in the floor or in the wall), or the
+ notch a dovetail or puzzle tab fits into (tabNotch). Each starts under the plate, as
+ a magnet pocket from beneath, a counterbore and a shank do, so any of those that
+ reaches one in plan has broken into it. A magnet from above meets it unless the
+ pocket's floor stands at least MOUNT_SKIN over the cut's ceiling. The housings a key
+ is dropped into from above (keySiteOps' 'cup' and 'snaptop') start 1.3 mm or more
+ over the socket floor: a pocket from above stops under them, and a shank, which
+ stays on the socket floor, is in the socket's open air up there.
+
+ Measured off the solids buildPiece cuts, at the sites it cuts pockets at: whole cells
+ only, so a housing beside a half cell or a margin is measured from the whole cell on
+ the other side of it, which is the only one with pockets. A corner boss is left out:
+ its pocket is cut in the boss, a shell of its own that no joint is cut from.
+
+ Issue #64: a bowtie in the floor at 42 mm, with magnets from beneath, built 12 bad
+ edges at 7.9 mm and 19 at 10, with Download on; puzzle tabs at 36 to 40 mm built 26
+ to 86 with the spec's 6.5 × 2.4 magnet. The pocket had run into the cut with its
+ ceiling level with the cut's: a 2 mm magnet or the default counterbore with a key's
+ 2 mm recess, a 2.4 mm magnet with a tab's notch. The two ceilings then share a face
+ that two subtractions split their own ways. All 86 pockets tried level with a cut
+ went bad; moved 0.001 mm up or down, 3 of them did, and 0.003 mm or more, none.
+ MOUNT_LEVEL counts 0.05 mm as level.
+
+ Off the level, what a pocket may do depends on the cut, measured on random designs
+ past where a pocket first meets one: keys and tabs, magnets from both sides, screw
+ heads and shanks, halves and margins, pitches that are not round numbers.
+ - A key's recess, an H-clip's or a puzzle tab's notch takes no pocket at all ('cut').
+ One a sliver in has gone bad off the level: 0.019 mm into a snap key's recess at
+ 36.52 mm, with a 0.5 mm fit clearance, at four depths on main. Let in wherever
+ the magnet or screw stayed clear of the key or tab, 7 of 2,519 such pockets at
+ the default fit or tighter went bad, 0.02 to 0.14 mm in, and 8 of 1,151 at
+ looser fits, 0.2 to 0.65 mm in.
+ - A dovetail's notch takes a pocket from beneath, a sliver or deep, unless it is
+ level with the notch ('level') or the magnet or screw in it would reach the other
+ piece's tab, which stands the fit clearance inside the notch ('part'). None of
+ 3,699 such designs went bad, 1,086 of them on the page's design at 40.5 to
+ 44.5 mm. So a 12.7 mm magnet at 42 mm, 2 or 3 mm thick, is taken: its pocket is
+ 0.04 to 0.09 mm into the notch and the magnet 0.24 mm clear of the tab.
+ - A pocket from above meets any of them unless its floor stands a layer over the
+ cut's ceiling ('floor').
+ The pocket is measured as fastenerCutter cuts it, as a polygon (boreReach), not by the
+ circle through its corners, which kept sizes out that came a flat's width short.
+
+ A pocket that stops short of a cut stops MOUNT_SEAM short. The weld in healCsgSeams
+ takes points VTOL apart for one, and a thinner wall than a few of those can come out
+ welded through: 4 of 715 pockets less than 0.005 mm short went bad, and none of 1,941
+ from 0.005 to 0.03 mm. Under a dovetail's notch that leaves a gap of refused sizes
+ below the largest (`gaps`), between the one that stops MOUNT_SEAM short and the one
+ that breaks in. Past the weld's reach there is still the lottery the room measured
+ here does not see, about one design in a thousand, single sizes with clean ones on
+ either side, and it needs the pocket and the cut together: a 14.1 mm counterbore 2.4
+ to 3 mm deep, 0.09 mm short of a dovetail's notch at 43.17 mm, loose, folds an edge
+ at the notch's corner, byte for byte as on main, and is clean at 2.35 mm deep, at
+ 14.075 and 14.125 mm across, at every size from there into the notch, and with no
+ counterbore. A guard out that far would refuse sizes that build clean on both sides
+ of it and still miss the next, 0.1 mm off. A wall of 1 mm would refuse the 6 mm
+ magnet from beneath with a bowtie at 42 mm, which has 0.84 mm to spare and always
+ built clean. */
+ const pad = platePad(cfg), again = !!known && known.pad === pad;
+ /* Each cut as { top, sites }: its ceiling, and each site in reach of it as how far a
+ bore's corner circle (`room`) and the bores themselves (`bore`, by their sides) can
+ grow before they meet the cut, and a magnet or screw (`body`) before it meets the
+ part in it. */
+ const jointCuts = again ? known.list : [];
+ /* Room past the most the cell or the floor leaves cannot stop a size, so nothing
+ further off than that is measured, and nothing at all where neither leaves any. A
+ plate the page will build has at most 900 cells; at 30 × 30 with puzzle tabs this
+ is a few milliseconds, on every redraw. */
+ const reach = Math.max(fit(top), fit(under));
+ if (layout && !again && !bosses && cfg.connector !== 'none' && reach > 0) {
+ const plan = keyPlan(cfg), H = pad + cfg.plateHeight;
+ /* A cut's footprint, as the segments its walls stand on, its extent and its ceiling,
+ for each seam it can be cut from, and the part's that goes in it: the key's half,
+ or the tab of the piece across the seam, as buildPiece stands it there, the fit
+ clearance inside the cut. Every cut from one seam is the same solid moved along it
+ (keyHalf, puzzleShape, tabNotch), so it is worked out at the origin once and each
+ site is moved the other way instead. */
+ const shapes = {};
+ const ring = (pts) => pts.map((p, i) => [p, pts[(i + 1) % pts.length]]);
+ const shapeOf = (edge) => {
+ if (shapes[edge]) return shapes[edge];
+ const at = { edge, e: 0, s: 0 };
+ const solid = plan.kind === 'recess'
+ ? keySiteOps(plan.kind, plan.shape, plan.prm, plan.clr, edge, 0, 0, H).cut
+ : tabNotch(cfg, at, pad);
+ const segs = [], bb = [Infinity, Infinity, -Infinity, -Infinity];
+ let ceiling = -Infinity;
+ for (const p of solid) {
+ for (const v of p.verts) {
+ ceiling = Math.max(ceiling, v[2]);
+ bb[0] = Math.min(bb[0], v[0]); bb[1] = Math.min(bb[1], v[1]);
+ bb[2] = Math.max(bb[2], v[0]); bb[3] = Math.max(bb[3], v[1]);
+ }
+ if (Math.abs(p.plane.n[2]) > 1e-9) continue;
+ const a = p.verts[0], b = p.verts.find((v) => Math.hypot(v[0] - a[0], v[1] - a[1]) > 1e-9);
+ if (b) segs.push([a, b]);
+ }
+ const part = plan.kind === 'recess' ? keyHalf(plan.shape, edge, 0, 0, plan.prm, 0)
+ : cfg.connector === 'puzzle' ? puzzleShape(OPP[edge], 0, 0, cfg.puzzle, 0, false)
+ : tabFootprint(OPP[edge], 0, 0, cfg.tab.wr, cfg.tab.wt, cfg.tab.dp, 0.8);
+ // the ceiling to the micron: a notch's is 2.2 + 0.2, 2.4000000000000004 as summed
+ const roof = Math.round(ceiling * 1e6) / 1e6;
+ return (shapes[edge] = { segs, bb, ceiling: roof, part: ring(part) });
+ };
+ // how far a point is from the footprint, less than none inside it
+ const from = (segs, x, y) => {
+ let d = Infinity, inside = false;
+ for (const [a, b] of segs) {
+ const dx = b[0] - a[0], dy = b[1] - a[1];
+ const t = Math.max(0, Math.min(1, ((x - a[0])*dx + (y - a[1])*dy) / (dx*dx + dy*dy)));
+ d = Math.min(d, Math.hypot(a[0] + t*dx - x, a[1] + t*dy - y));
+ if ((a[1] > y) !== (b[1] > y) && x < a[0] + (y - a[1]) * dx / dy) inside = !inside;
+ }
+ return inside ? -d : d;
+ };
+ for (const piece of layout.pieces) {
+ const conn = pieceConnectors(cfg, layout, piece);
+ // the cuts buildPiece makes in this piece: notches for tabs, recesses for keys
+ const cuts = [...conn.notches, ...conn.pnotches, ...(plan.kind !== 'recess' ? []
+ : conn.keyed.filter((bo) => !(plan.junction && offJunction(bo, cfg.pitch, piece))))];
+ for (const bo of cuts) {
+ const { segs, bb, ceiling, part } = shapeOf(bo.edge);
+ const across = bo.edge === '+x' || bo.edge === '-x';
+ const ox = across ? bo.e : bo.s, oy = across ? bo.s : bo.e;
+ // the whole cells with a site in reach of it (a half cell has none; see buildPiece)
+ const cells = (lo, hi, m, n) => [Math.max(0, Math.floor((lo - reach - off - half - m) / cfg.pitch)),
+ Math.min(n - 1, Math.ceil((hi + reach + off - half - m) / cfg.pitch))];
+ const [i0, i1] = cells(bb[0] + ox, bb[2] + ox, piece.mL, piece.nx);
+ const [j0, j1] = cells(bb[1] + oy, bb[3] + oy, piece.mF, piece.ny);
+ const sites = [];
+ for (let i = i0; i <= i1; i++) for (let j = j0; j <= j1; j++)
+ for (const sx of [-1, 1]) for (const sy of [-1, 1]) {
+ const x = piece.mL + i*cfg.pitch + half + sx*off - ox;
+ const y = piece.mF + j*cfg.pitch + half + sy*off - oy;
+ if (x < bb[0] - reach || x > bb[2] + reach || y < bb[1] - reach || y > bb[3] + reach) continue;
+ // the bores and the part stand further off than the corner circle, or as far
+ const room = from(segs, x, y);
+ if (room >= reach) continue;
+ const bore = (n) => room > 0 ? boreReach(n, segs, x, y) : room;
+ sites.push({ room, body: from(part, x, y), bore: { 12: bore(12), 14: bore(14) } });
+ }
+ if (sites.length) jointCuts.push({ top: ceiling, sites });
+ }
+ }
+ }
+ /* The bores as fastenerCutter cuts them, in one place: how many sides, and the largest
+ size whose corners stay inside a radius. A magnet's corners are 0.1 mm over its
+ radius, or out to where its flats stand on that radius if that is further; a screw's
+ bores have their corners on its size. */
+ const BORE = {
+ magnetD: { sides: 14, fits: (r) => 2 * Math.min(r - 0.1, r * Math.cos(Math.PI / 14)) },
+ screwHeadD: { sides: 14, fits: (r) => 2 * r },
+ screwHoleD: { sides: 12, fits: (r) => 2 * r },
+ };
+ // the room the cell, the floor or a boss leaves, and the hole beside
+ const own = { magnetD: fit(cfg.magnetSide === 'top' ? top : under), screwHoleD: fit(top), screwHeadD: fit(under) };
+ // a dovetail's notch takes a pocket from beneath that breaks into it; every other cut does not
+ const notch = cfg.connector === 'dovetail';
+ /* What the joint's cuts leave one size, as { cap, why, near }: the largest size, and what
+ stops it: 'cut', a pocket that would break into a key's recess or a puzzle tab's notch;
+ 'floor', one from above that leaves no layer of floor over a cut; 'level', one from
+ beneath as deep as a dovetail's notch; 'part', a magnet or screw that would reach the
+ tab in one. Each stops MOUNT_SEAM short of the cut. `near` is where that leaves sizes
+ under the cap refused, as [from, to]: a dovetail's notch, which a pocket may break
+ into, but not stop just short of. */
+ const jointFor = (f) => {
+ const { sides, fits } = BORE[f];
+ const above = f === 'magnetD' && cfg.magnetSide === 'top';
+ // how high a pocket from beneath goes; a shank goes through
+ const ceiling = f === 'magnetD' ? cfg.magnetH : f === 'screwHeadD' ? cfg.screwHeadDepth : Infinity;
+ let cap = Infinity, why = false;
+ const near = [];
+ for (const c of jointCuts) {
+ // a pocket from above clears a cut whose ceiling it leaves a layer of floor over
+ if (above && !(c.top + MOUNT_SKIN > pad - cfg.magnetH + 1e-6)) continue;
+ /* Level within MOUNT_LEVEL, measured to the micron, so a pocket that far above the
+ notch's ceiling and one that far below it are taken alike: 2.35 and 2.45 mm deep
+ against a notch 2.4 mm high, which both build clean. Unrounded, 2.45 counted as
+ level, and with the ceiling alone rounded 2.35 would. */
+ const level = Math.round(Math.abs(ceiling - c.top) * 1e6) / 1e6 < MOUNT_LEVEL;
+ const stop = above ? 'floor' : !notch ? 'cut' : level ? 'level' : 'part';
+ for (const s of c.sites) {
+ const short = fits(s.bore[sides] - MOUNT_SEAM);
+ const size = stop === 'part' ? 2 * s.body : short;
+ if (size < cap) { cap = size; why = stop; }
+ if (stop === 'part') near.push([short, fits(s.bore[sides])]);
+ }
+ }
+ return { cap, why, near };
+ };
+ const sizes = {}, joint = {}, gaps = {};
+ for (const f of ['magnetD', 'screwHoleD', 'screwHeadD']) {
+ const cell = BORE[f].fits(own[f]), J = jointFor(f);
+ let size = r10(Math.min(cell, J.cap));
+ joint[f] = J.cap < cell && J.why;
+ /* The sizes `near` refuses, out to the hundredths either side, since the field takes
+ hundredths: each gap is [from, to], both taken. A window is about 0.02 mm wide, so
+ rounded out to the tenths as the cap is, it refused up to a tenth that builds clean
+ (5.51 to 5.69 at 36 mm). One that reaches the cap brings it down to where it starts. */
+ const out = [];
+ for (const [a, b] of J.near.sort((x, y) => x[0] - y[0])) {
+ const from = Math.floor(a * 100 + 1e-9) / 100, to = (Math.floor(b * 100 + 1e-9) + 1) / 100;
+ if (to <= 0) continue;
+ if (out.length && from < out[out.length - 1][1]) out[out.length - 1][1] = Math.max(out[out.length - 1][1], to);
+ else out.push([from, to]);
+ }
+ gaps[f] = [];
+ for (const [from, to] of out) {
+ if (from >= size) break;
+ if (to > size) { size = from; joint[f] = 'near'; break; }
+ gaps[f].push([from, to]);
+ }
+ sizes[f] = size;
+ }
return {
- // a magnet pocket's corners are 0.1 mm over the magnet's radius, or out to where its
- // flats stand on that radius if that is further (fastenerCutter)
- magnetD: r10(2 * Math.min(room - 0.1, room * Math.cos(Math.PI / 14))),
- // a screw's bores have their corners on its size
- screwHoleD: r10(2 * fit(top)),
- screwHeadD: r10(2 * fit(under)),
+ magnetD: sizes.magnetD,
+ screwHoleD: sizes.screwHoleD,
+ screwHeadD: sizes.screwHeadD,
// in the solid floor the pad grows to suit, so only a boss caps the depth
depth: bosses ? r10(BOSS_H - MOUNT_SKIN) : Infinity,
// which of the sizes the cut beside it stops, rather than the floor, cell or boss
- beside: { magnetD: room === beside, screwHoleD: top >= beside, screwHeadD: under >= beside },
+ beside: { magnetD: own.magnetD === beside && !joint.magnetD,
+ screwHoleD: own.screwHoleD === beside && !joint.screwHoleD,
+ screwHeadD: own.screwHeadD === beside && !joint.screwHeadD },
+ // and which a joint's cut stops, before any of those, and how (jointFor)
+ joint,
+ // sizes under the largest refused all the same, as [from, to] with both ends taken
+ gaps,
+ // what was measured of the joint's cuts, for `known`
+ cuts: { pad, list: jointCuts },
};
}
@@ -3964,7 +4254,38 @@ Your drawers
}
return out;
};
- const fastenerFoot = wallsAt(0), fastenerTop = pad > 0.01 ? wallsAt(pad) : [];
+ /* The same, its corners only. Where the walls of two bores were unioned (a counterbore,
+ its screw's shank), the BSP split each wall along the other's planes, and wallsAt
+ hands back those split points as well: two on every flat of the shank, 24 points on
+ the socket floor that are no corner of anything. A 2.4 mm shank under a 4.8 mm head
+ at 44.08 mm, with loose tolerance, had a spoke within FAN_CLEAR of one of them from
+ every point fanCentre tries, so the socket floor's fan never moved and the cell
+ shipped with six open edges. A corner is where two walls that are not in line meet;
+ a split point is where one wall was cut in two. From the corners alone the fan moves
+ 0.2 mm and the floor closes. Only the socket floor's list, which only an open cell's
+ refan reads (buildPiece), so every cell that came out closed is built as before. */
+ const cornersAt = (z) => {
+ const ends = new Map(); // a wall end, to the directions of the walls that end there
+ for (const p of cellFastener || []) {
+ const zs = p.verts.map((v) => v[2]);
+ if (!(Math.min(...zs) < z && Math.max(...zs) > z) || Math.abs(p.plane.n[2]) > 1e-9) continue;
+ const d = [-p.plane.n[1], p.plane.n[0]]; // along the wall
+ let lo = null, hi = null;
+ for (const v of p.verts) {
+ const t = v[0]*d[0] + v[1]*d[1];
+ if (!lo || t < lo[0]) lo = [t, v];
+ if (!hi || t > hi[0]) hi = [t, v];
+ }
+ for (const [, v] of [lo, hi]) {
+ const k = `${v[0].toFixed(6)} ${v[1].toFixed(6)}`;
+ if (!ends.has(k)) ends.set(k, { at: [v[0], v[1]], dirs: [] });
+ ends.get(k).dirs.push(d);
+ }
+ }
+ return [...ends.values()].filter(({ dirs }) =>
+ dirs.some((a) => dirs.some((b) => Math.abs(a[0]*b[1] - a[1]*b[0]) > 1e-6))).map((e) => e.at);
+ };
+ const fastenerFoot = wallsAt(0), fastenerTop = pad > 0.01 ? cornersAt(pad) : [];
// ---- connectors ----
const conn = pieceConnectors(cfg, layout, piece);
@@ -4358,7 +4679,9 @@ Your drawers
* And once every cell is built, the shells settle cut again are checked as a whole, with
* those beside them: if they have more bad edges (checkManifold) than they had before,
* or more open or turned over (healCsgSeams), every one goes back to its first cut. So
- * settle never leaves a piece worse than it found it, whatever order the cells come in.
+ * settle never leaves those shells worse than it found them, whatever order the cells
+ * come in. What is made after the check is not judged by it: the dovetail and puzzle
+ * tabs, and what the top-insert pass cuts again (see the check below).
* `alt` and `pocket` are the cuts a cell was last taken with, so a cell cut again for
* one reason keeps what it was cut again for the other. */
const POCKET_TRIES = 7;
@@ -4531,22 +4854,7 @@ Your drawers
(nb.edge === '+x' ? Math.abs(x1 - W) : Math.abs(x0)) < nDp + 0.2)
: (nb.s > x0 - nWt && nb.s < x1 + nWt &&
(nb.edge === '+y' ? Math.abs(y1 - D) : Math.abs(y0)) < nDp + 0.2);
- if (near) {
- // 4-pt taper: no vertex sits exactly on the region side plane; jitter breaks
- // residual coincidences with ring geometry
- const J = 0.0017, BK = 1.0, e = nb.e, s = nb.s + J;
- let pts;
- if (nb.edge === '+x' || nb.edge === '-x') {
- const g = nb.edge === '-x' ? 1 : -1; // cut extends INTO the piece
- pts = [[e - g*BK, s - nWr/2], [e + g*nDp, s - nWt/2],
- [e + g*nDp, s + nWt/2], [e - g*BK, s + nWr/2]];
- } else {
- const g = nb.edge === '-y' ? 1 : -1;
- pts = [[s - nWr/2, e - g*BK], [s - nWt/2, e + g*nDp],
- [s + nWt/2, e + g*nDp], [s + nWr/2, e - g*BK]];
- }
- cuts.notch.push(...extrudePoly(pts, -0.503, Math.min(t.h + 0.2, H - 0.8)));
- }
+ if (near) cuts.notch.push(...tabNotch(cfg, nb, pad));
}
for (const bo of keyed) {
if (plan.junction && offJunction(bo, pitch, piece))
@@ -4576,9 +4884,7 @@ Your drawers
(pn.edge === '+x' ? Math.abs(x1 - W) : Math.abs(x0)) < reach)
: (pn.s > x0 - cfg.puzzle.lobeR*2 && pn.s < x1 + cfg.puzzle.lobeR*2 &&
(pn.edge === '+y' ? Math.abs(y1 - D) : Math.abs(y0)) < reach);
- if (near) cuts.puzzle.push(
- ...extrudePoly(puzzleShape(pn.edge, pn.e, pn.s, cfg.puzzle, cfg.puzzle.clr, true),
- -0.5, pad - 0.4));
+ if (near) cuts.puzzle.push(...tabNotch(cfg, pn, pad));
}
/* None in a half cell. A half-size bin's quarter feet carry no holes (feetHolesOff
in bins/bin.js), and where a half socket's would go is not settled: a whole
@@ -4702,8 +5008,10 @@ Your drawers
Only here, not on every cell: a 6 mm magnet from above at 42 mm has a spoke 2.3
microns from a corner in every cell and comes out closed, as most do. And only
where the fan moves and the cell is open at the floor's height: a cell open
- somewhere else, as a pocket that meets a joint's housing is, or one whose spokes
- are already clear, would be cut again for the same result. A bowtie plate at
+ somewhere else, as a pocket that meets a joint's housing is, would be cut again
+ for the same result, and so would one whose fan stays where it was, either because
+ its spokes are already clear or because fanCentre finds no point clear of every
+ corner and keeps the centre. A bowtie plate at
45.57 mm with screws, open in every piece on main as well, took twice as long
with every open cell cut again. */
if (region.open && floorAvoid.length && openAt(region, pad)) {
@@ -7211,6 +7519,8 @@ Your drawers
const numIds = ['drawerW','drawerD','bedW','bedD','bedH','mLeft','mRight','mFront','mBack',
'pitch','outerRadius','bottomPad','topCutoff','magnetD','magnetH',
'screwHoleD','screwHeadD','screwHeadDepth','infill'];
+// the ones readControls reads after the rest, in this order (see there)
+const MOUNT_LAST = ['magnetH', 'screwHeadDepth', 'screwHoleD', 'screwHeadD', 'magnetD'];
/* The fields that carry a real-world size, and the range one can be.
*
@@ -7241,19 +7551,53 @@ Your drawers
* off, nor margins outside Custom, because a complaint about a field you cannot see is
* one you cannot act on. `why` finishes the too-big message where "check the figure is
* in millimetres" would be the wrong advice, and `off` names the switch that drops a cut
- * the pitch has no room for. */
+ * the pitch has no room for. `gaps` are sizes under `max` refused all the same, as
+ * [from, to] with both ends taken. */
const RANGES = PLATE_RANGES;
const customMargins = () => state.marginMode === 'custom' && !state.noMargin;
-const mount = () => mountLimits(state);
+/* The sizes a joint's cut in the floor leaves room for depend on where the seams are and
+ on the clearance, so mountLimits takes the layout, and readControls reads the mounting
+ sizes after everything that moves either. The layout is worked out once for a read, the
+ first time a size needs it, and recomputeLayout keeps that one rather than working it
+ out again: none of the mounting sizes moves it. In Fewest plates mode one is a search,
+ about 100 ms, and with magnets on a keystroke ran three. The answer is kept meanwhile,
+ for the range and the reason alike. */
+let mountNow = null, mountLayout = null;
+const mount = () => mountNow ||
+ (mountNow = mountLimits(state, mountLayout || (mountLayout = computeLayout(state))));
+// how deep a pocket goes: only a corner boss caps it, which needs no layout
+const mountDepth = () => mountLimits(state).depth;
// "an 18 mm pitch", "an 80 mm pitch": the article goes by how the number is said
const atPitch = () => `at ${/^(8|1[18](\.|$))/.test(String(state.pitch)) ? 'an' : 'a'} ` +
`${state.pitch} mm pitch`;
-const mountWhy = (opens, field) => `${atPitch()} — mounting holes sit ` +
- `${state.holeOffset} mm from each cell centre, where the Gridfinity spec puts them, and ` +
- (mount().beside[field] ? 'a cell\'s four holes have to stay clear of each other'
- : state.baseMode === 'bosses' ? 'a pocket has to stay inside its corner boss'
- : opens ? 'a cut open to the socket has to stay on the socket floor'
- : 'a pocket under the floor has to stay inside its cell');
+// a joint's cut in the floor, as the messages name it: "the notches the dovetail tabs fit into"
+const cutsNamed = () => `${['dovetail', 'puzzle'].includes(state.connector) ? 'notches' : 'recesses'} the ` +
+ `${CONNECTOR_NAMES[state.connector]} fit into`;
+/* Why `field` stops where it does. A joint's cut stops it in one of the ways mountLimits'
+ `joint` names: a pocket from beneath as deep as a dovetail's notch, a magnet or screw
+ that would reach the tab in one, a pocket any wider coming too near the notch's edge,
+ or any other hole breaking into the cut. */
+const mountWhy = (opens, field) => {
+ const joint = mount().joint[field];
+ const cuts = cutsNamed();
+ return `${atPitch()} — mounting holes sit ` +
+ `${state.holeOffset} mm from each cell centre, where the Gridfinity spec puts them, and ` +
+ (joint === 'level' ? `a pocket ${field === 'magnetD' ? state.magnetH : state.screwHeadDepth} mm deep, ` +
+ `as deep as the ${cuts}, has to stay out of them`
+ : joint === 'part' ? `${{ magnetD: 'a magnet', screwHeadD: 'a screw head', screwHoleD: 'a screw' }[field]} ` +
+ `has to stay clear of the ${CONNECTOR_NAMES[state.connector]} in the notches beside it`
+ : joint === 'near' ? `a pocket any wider would come too near the edge of the ${cuts} to cut cleanly`
+ : joint ? `a hole has to stay out of the ${cuts}`
+ : mount().beside[field] ? 'a cell\'s four holes have to stay clear of each other'
+ : state.baseMode === 'bosses' ? 'a pocket has to stay inside its corner boss'
+ : opens ? 'a cut open to the socket has to stay on the socket floor'
+ : 'a pocket under the floor has to stay inside its cell') +
+ (joint && KEYED.includes(state.connector) && !keyFromTop()
+ ? `; keys ${keyInWall() ? '' : 'housed inside the walls and '}put in from above ` +
+ 'keep out of the solid floor under these pockets' : '');
+};
+// why a size under the largest is refused (mountLimits' `gaps`)
+const nearWhy = () => `${atPitch()} — its pocket would come too near the edge of the ${cutsNamed()} to cut cleanly`;
const bossDepth = () => state.baseMode === 'bosses'
? 'with corner pockets — a boss is 2.6 mm tall, while the solid floor grows to suit' : '';
const LIMITS = {
@@ -7280,14 +7624,17 @@ Your drawers
tooSmall: 'at 0 the rim between sockets is a face with no width, and the plate comes out open',
why: () => '— past that a spec bin rides on the rim instead of seating in its socket' },
magnetD: { ...RANGES.magnetD, max: () => mount().magnetD, label: 'Magnet Ø', when: () => state.magnets,
- why: () => mountWhy(state.magnetSide === 'top', 'magnetD'), off: 'magnet pockets' },
- magnetH: { ...RANGES.magnetH, max: () => Math.min(RANGES.magnetH.max, mount().depth), label: 'Magnet depth',
+ why: () => mountWhy(state.magnetSide === 'top', 'magnetD'), off: 'magnet pockets',
+ gaps: () => mount().gaps.magnetD },
+ magnetH: { ...RANGES.magnetH, max: () => Math.min(RANGES.magnetH.max, mountDepth()), label: 'Magnet depth',
when: () => state.magnets, why: bossDepth },
screwHoleD: { ...RANGES.screwHoleD, max: () => mount().screwHoleD, label: 'Screw hole Ø',
- when: () => state.screws, why: () => mountWhy(true, 'screwHoleD'), off: 'screw holes' },
+ when: () => state.screws, why: () => mountWhy(true, 'screwHoleD'), off: 'screw holes',
+ gaps: () => mount().gaps.screwHoleD },
screwHeadD: { ...RANGES.screwHeadD, max: () => mount().screwHeadD, label: 'Screw head Ø',
- when: () => state.screws, why: () => mountWhy(false, 'screwHeadD'), off: 'screw holes' },
- screwHeadDepth: { ...RANGES.screwHeadDepth, max: () => Math.min(RANGES.screwHeadDepth.max, mount().depth),
+ when: () => state.screws, why: () => mountWhy(false, 'screwHeadD'), off: 'screw holes',
+ gaps: () => mount().gaps.screwHeadD },
+ screwHeadDepth: { ...RANGES.screwHeadDepth, max: () => Math.min(RANGES.screwHeadDepth.max, mountDepth()),
label: 'Screw head depth', when: () => state.screws, why: bossDepth },
// each joint's ceiling is its own, so none is held to another's reason; see clrWhy
connClr: { min: RANGES.connClr.min, max: () => connClrCeiling(state).max, label: 'Fit clearance',
@@ -7393,6 +7740,27 @@ Your drawers
(why ? `${why}.` : `— check the figure is in ${unitName}.`));
return hi;
}
+ /* A size under the largest can be refused as well, where its pocket would come too near
+ the edge of a dovetail's notch (mountLimits' `gaps`); the sizes either side are taken.
+ Two gaps can meet at one taken size, so the advice names the sizes taken round the
+ run of gaps the size is in, inside the field's range: "Use 11.89 mm or less, 11.92 mm,
+ or 11.95 mm or more" at 41.49 mm, never a size in the next gap, under the field's least
+ or over its largest. */
+ const gaps = inPlay && lim.gaps ? lim.gaps() : [];
+ const at = gaps.findIndex(([a, b]) => v > a && v < b);
+ if (at >= 0) {
+ let i = at, j = at;
+ while (i > 0 && gaps[i - 1][1] >= gaps[i][0] - 1e-9) i--;
+ while (j < gaps.length - 1 && gaps[j + 1][0] <= gaps[j][1] + 1e-9) j++;
+ const ok = [];
+ if (gaps[i][0] > lo) ok.push(`${both(gaps[i][0])} or less`);
+ else if (gaps[i][0] === lo) ok.push(both(lo));
+ for (let k = i; k < j; k++) if (gaps[k][1] >= lo) ok.push(both(gaps[k][1]));
+ ok.push(gaps[j][1] < hi ? `${both(gaps[j][1])} or more` : both(gaps[j][1]));
+ say(`${lim.label} of ${both(v)} is refused ${nearWhy()}. Use ` +
+ (ok.length > 1 ? `${ok.slice(0, -1).join(', ')}, or ${ok[ok.length - 1]}` : ok[0]) + '.');
+ return gaps[at][0] >= lo ? gaps[at][0] : gaps[at][1];
+ }
return v;
}
/* The invalid state is set on the element rather than through a class, because the
@@ -7437,7 +7805,7 @@ Your drawers
state.magnets = $('magnets').checked;
state.screws = $('screws').checked;
state.magnetSide = $('magnetSide').value;
- for (const id of numIds) state[id] = readNumber(id);
+ for (const id of numIds) if (!MOUNT_LAST.includes(id)) state[id] = readNumber(id);
if (state.noMargin) { state.marginMode = 'custom'; state.mLeft = state.mRight = state.mFront = state.mBack = 0; }
// the per-corner radii need no range here: buildPiece caps each one at the socket's rim
if ($('perCorner').checked) {
@@ -7457,6 +7825,22 @@ Your drawers
state.key = Object.assign({}, DEFAULTS.key, { clr: fit.key });
state.hclip = Object.assign({}, DEFAULTS.hclip, { clr: fit.hclip });
state.puzzle = Object.assign({}, DEFAULTS.puzzle, { clr: fit.puzzle });
+ /* The mounting sizes last, since a joint's cut beside the sites moves with the margins,
+ the split and the clearance (see mount). The magnet's is the very last, and measured
+ again: a pocket from above meets a cut by how thick the floor is, which the screws
+ and the magnet's own depth set. Only that step is taken again, on the same layout
+ and the cuts already measured, unless the floor has moved (mountLimits' `known`). */
+ mountNow = mountLayout = null;
+ for (const id of MOUNT_LAST) {
+ if (id === 'magnetD' && mountNow) mountNow = mountLimits(state, mountLayout, mountNow.cuts);
+ state[id] = readNumber(id);
+ }
+ // and Checks says what is wrong in the panel's order, not the order it was read in
+ for (const m of [fieldErrors, noRoom]) {
+ const read = new Map(m);
+ m.clear();
+ for (const id of [...numIds, 'connClr']) if (read.has(id)) m.set(id, read.get(id));
+ }
// half cells keep the alignment: it places what is left after them
$('alignRow').style.display = mm === 'auto' || mm === 'half' ? '' : 'none';
$('halfHint').style.display = mm === 'half' ? '' : 'none';
@@ -7523,7 +7907,7 @@ Your drawers
nothing, and each of those is a discrete edit. */
function recomputeLayout(ev) {
readControls();
- layout = computeLayout(state);
+ layout = mountLayout || computeLayout(state); // the one the sizes were read against, if any
// clamp stored manual cuts to the current grid
if (state.splitMode === 'manual') {
state.rowCuts = layout.rowCuts.slice();
diff --git a/src/core.js b/src/core.js
index feee973..944947a 100644
--- a/src/core.js
+++ b/src/core.js
@@ -1351,6 +1351,30 @@ function puzzleShape(edge, e, s, pz, grow, inward) {
return [s + lt, e + g * dp];
});
}
+/* The notch a tab fits into, cut up into the floor of the piece across the seam from it
+ (pieceConnectors' `notches` or `pnotches`), as one closed solid. buildPiece cuts it, and
+ mountLimits keeps the mounting sites out of it; one shape, so the two cannot drift. */
+function tabNotch(cfg, nb, pad) {
+ if (cfg.connector === 'puzzle')
+ return extrudePoly(puzzleShape(nb.edge, nb.e, nb.s, cfg.puzzle, cfg.puzzle.clr, true),
+ -0.5, pad - 0.4);
+ const t = cfg.tab, H = pad + cfg.plateHeight;
+ const nWr = t.wr + 2*t.clr, nWt = t.wt + 2*t.clr, nDp = t.dp + t.clr;
+ // 4-pt taper: no vertex sits exactly on the region side plane; jitter breaks
+ // residual coincidences with ring geometry
+ const J = 0.0017, BK = 1.0, e = nb.e, s = nb.s + J;
+ let pts;
+ if (nb.edge === '+x' || nb.edge === '-x') {
+ const g = nb.edge === '-x' ? 1 : -1; // cut extends INTO the piece
+ pts = [[e - g*BK, s - nWr/2], [e + g*nDp, s - nWt/2],
+ [e + g*nDp, s + nWt/2], [e - g*BK, s + nWr/2]];
+ } else {
+ const g = nb.edge === '-y' ? 1 : -1;
+ pts = [[s - nWr/2, e - g*BK], [s - nWt/2, e + g*nDp],
+ [s + nWt/2, e + g*nDp], [s + nWr/2, e - g*BK]];
+ }
+ return extrudePoly(pts, -0.503, Math.min(t.h + 0.2, H - 0.8));
+}
// generic underside key halves (recess cut into one piece's edge region)
function keyHalf(type, edge, e, s, prm, grow) {
// returns polygon extending prm depth into the piece, 0.5 past the seam
@@ -2298,6 +2322,43 @@ function platePad(cfg) {
facets graze the floor's own triangulation — screws at a 36 mm pitch leaked 192 edges
with 0.65 mm to spare. */
const MOUNT_WALL = 1.0;
+/* How near a pocket's ceiling may come to a dovetail notch's before the two count as
+ level, and how near its walls may come to any joint's cut without breaking into it.
+ See mountLimits. */
+const MOUNT_LEVEL = 0.05, MOUNT_SEAM = 0.01;
+/* How far a mounting bore about (x, y) can grow before it meets any of `segs`, as the
+ radius of the circle through its corners: the polygon cylinder() cuts, `sides` flats
+ with a corner at every 2πk/sides from +x. A point is in that polygon when it stands no
+ further out along any flat's normal than R cos(π/sides), so along one segment the
+ least R that takes a point of it in is at an end, or where the segment crosses the
+ line out through a corner, on which a point's R is its distance. */
+function boreReach(sides, segs, x, y) {
+ const step = 2 * Math.PI / sides, h = Math.cos(step / 2);
+ const cx = [], cy = [], nx = [], ny = [];
+ for (let k = 0; k < sides; k++) {
+ cx.push(Math.cos(k * step)); cy.push(Math.sin(k * step));
+ nx.push(Math.cos((k + 0.5) * step)); ny.push(Math.sin((k + 0.5) * step));
+ }
+ const at = (dx, dy) => {
+ let m = -Infinity;
+ for (let k = 0; k < sides; k++) m = Math.max(m, dx * nx[k] + dy * ny[k]);
+ return m / h;
+ };
+ let r = Infinity;
+ for (const [a, b] of segs) {
+ const ax = a[0] - x, ay = a[1] - y, ex = b[0] - a[0], ey = b[1] - a[1];
+ r = Math.min(r, at(ax, ay), at(ax + ex, ay + ey));
+ for (let k = 0; k < sides; k++) {
+ const den = ex * cy[k] - ey * cx[k];
+ if (Math.abs(den) < 1e-12) continue;
+ const t = (ay * cx[k] - ax * cy[k]) / den;
+ if (t < 0 || t > 1) continue;
+ const s = (ax + t * ex) * cx[k] + (ay + t * ey) * cy[k];
+ if (s >= 0) r = Math.min(r, s);
+ }
+ }
+ return r;
+}
/* The largest mounting cuts this configuration has room for, as diameters and depths in
the units the page's fields use. Magnets and screws sit holeOffset (13 mm, the spec's)
from each cell centre at ANY pitch, so the room round them shrinks with the pitch:
@@ -2312,11 +2373,21 @@ const MOUNT_WALL = 1.0;
* - in a corner boss: it must stay in the boss, which is shorter than the solid floor
* and does not grow with the pocket, so it also caps the depth.
*
+ * And whichever way it opens, it must stay out of a joint's cut in the floor beside it:
+ * a key's recess, or the notch a tab fits into, where a dovetail's lets a pocket from
+ * beneath in only so far as its tab leaves room. That one needs `layout`, which says
+ * where the seams are; without it no joint is counted.
+ *
* These are measurements, not field ranges, and can come out below the field's minimum
* or negative — a screw shank at a 34 mm pitch has −0.1 mm. That means no cut of any size
* fits there; the page turns it into a check on the design rather than a range for the
- * field (src/ui.js readNumber), since no number typed into the field could fix it. */
-function mountLimits(cfg) {
+ * field (src/ui.js readNumber), since no number typed into the field could fix it.
+ *
+ * `known` is the `cuts` of an earlier answer for the same design on the same layout,
+ * with only the mounting sizes changed since: the joint's cuts are not measured again
+ * unless the floor has moved, which moves their ceilings. The page reads the magnet's
+ * size last and asks again for it, after the screws' sizes have settled the floor. */
+function mountLimits(cfg, layout, known) {
const half = cfg.pitch / 2, off = cfg.holeOffset;
const tol = cfg.tolerance === 'tight' ? +0.1 : cfg.tolerance === 'loose' ? -0.1 : 0;
// distance from a point at (s, s) to the edge of a rounded square of half-size h,
@@ -2334,7 +2405,7 @@ function mountLimits(cfg) {
const inBoss = Math.min(roomIn(BOSS_W, BOSS_R, s), s) - MOUNT_WALL;
const bosses = cfg.baseMode === 'bosses';
const top = bosses ? inBoss : onFloor, under = bosses ? inBoss : inCell;
- const r10 = (x) => Math.floor(x * 10 + 1e-9) / 10; // the fields step in tenths
+ const r10 = (x) => Math.floor(x * 10 + 1e-9) / 10; // a cap is given in tenths, rounded down
/* A cell's four sites are 2 × holeOffset apart, 26 mm, so past a pitch of about 50 mm
the room above lets a cut reach the one beside it before it reaches anything else:
two 1-inch magnet pockets met at a 55 mm pitch and left 52 open edges. Each cut stops
@@ -2342,18 +2413,237 @@ function mountLimits(cfg) {
stop at 12.5 mm and the wall between two pockets is at least MOUNT_WALL, 1 mm. */
const beside = off - MOUNT_WALL / 2;
const fit = (r) => Math.min(r, beside);
- const room = fit(cfg.magnetSide === 'top' ? top : under);
+ /* A joint cut up into the solid floor beside the sites: the recess a key or an H-clip
+ is put into from beneath (keyPlan's 'recess', in the floor or in the wall), or the
+ notch a dovetail or puzzle tab fits into (tabNotch). Each starts under the plate, as
+ a magnet pocket from beneath, a counterbore and a shank do, so any of those that
+ reaches one in plan has broken into it. A magnet from above meets it unless the
+ pocket's floor stands at least MOUNT_SKIN over the cut's ceiling. The housings a key
+ is dropped into from above (keySiteOps' 'cup' and 'snaptop') start 1.3 mm or more
+ over the socket floor: a pocket from above stops under them, and a shank, which
+ stays on the socket floor, is in the socket's open air up there.
+
+ Measured off the solids buildPiece cuts, at the sites it cuts pockets at: whole cells
+ only, so a housing beside a half cell or a margin is measured from the whole cell on
+ the other side of it, which is the only one with pockets. A corner boss is left out:
+ its pocket is cut in the boss, a shell of its own that no joint is cut from.
+
+ Issue #64: a bowtie in the floor at 42 mm, with magnets from beneath, built 12 bad
+ edges at 7.9 mm and 19 at 10, with Download on; puzzle tabs at 36 to 40 mm built 26
+ to 86 with the spec's 6.5 × 2.4 magnet. The pocket had run into the cut with its
+ ceiling level with the cut's: a 2 mm magnet or the default counterbore with a key's
+ 2 mm recess, a 2.4 mm magnet with a tab's notch. The two ceilings then share a face
+ that two subtractions split their own ways. All 86 pockets tried level with a cut
+ went bad; moved 0.001 mm up or down, 3 of them did, and 0.003 mm or more, none.
+ MOUNT_LEVEL counts 0.05 mm as level.
+
+ Off the level, what a pocket may do depends on the cut, measured on random designs
+ past where a pocket first meets one: keys and tabs, magnets from both sides, screw
+ heads and shanks, halves and margins, pitches that are not round numbers.
+ - A key's recess, an H-clip's or a puzzle tab's notch takes no pocket at all ('cut').
+ One a sliver in has gone bad off the level: 0.019 mm into a snap key's recess at
+ 36.52 mm, with a 0.5 mm fit clearance, at four depths on main. Let in wherever
+ the magnet or screw stayed clear of the key or tab, 7 of 2,519 such pockets at
+ the default fit or tighter went bad, 0.02 to 0.14 mm in, and 8 of 1,151 at
+ looser fits, 0.2 to 0.65 mm in.
+ - A dovetail's notch takes a pocket from beneath, a sliver or deep, unless it is
+ level with the notch ('level') or the magnet or screw in it would reach the other
+ piece's tab, which stands the fit clearance inside the notch ('part'). None of
+ 3,699 such designs went bad, 1,086 of them on the page's design at 40.5 to
+ 44.5 mm. So a 12.7 mm magnet at 42 mm, 2 or 3 mm thick, is taken: its pocket is
+ 0.04 to 0.09 mm into the notch and the magnet 0.24 mm clear of the tab.
+ - A pocket from above meets any of them unless its floor stands a layer over the
+ cut's ceiling ('floor').
+ The pocket is measured as fastenerCutter cuts it, as a polygon (boreReach), not by the
+ circle through its corners, which kept sizes out that came a flat's width short.
+
+ A pocket that stops short of a cut stops MOUNT_SEAM short. The weld in healCsgSeams
+ takes points VTOL apart for one, and a thinner wall than a few of those can come out
+ welded through: 4 of 715 pockets less than 0.005 mm short went bad, and none of 1,941
+ from 0.005 to 0.03 mm. Under a dovetail's notch that leaves a gap of refused sizes
+ below the largest (`gaps`), between the one that stops MOUNT_SEAM short and the one
+ that breaks in. Past the weld's reach there is still the lottery the room measured
+ here does not see, about one design in a thousand, single sizes with clean ones on
+ either side, and it needs the pocket and the cut together: a 14.1 mm counterbore 2.4
+ to 3 mm deep, 0.09 mm short of a dovetail's notch at 43.17 mm, loose, folds an edge
+ at the notch's corner, byte for byte as on main, and is clean at 2.35 mm deep, at
+ 14.075 and 14.125 mm across, at every size from there into the notch, and with no
+ counterbore. A guard out that far would refuse sizes that build clean on both sides
+ of it and still miss the next, 0.1 mm off. A wall of 1 mm would refuse the 6 mm
+ magnet from beneath with a bowtie at 42 mm, which has 0.84 mm to spare and always
+ built clean. */
+ const pad = platePad(cfg), again = !!known && known.pad === pad;
+ /* Each cut as { top, sites }: its ceiling, and each site in reach of it as how far a
+ bore's corner circle (`room`) and the bores themselves (`bore`, by their sides) can
+ grow before they meet the cut, and a magnet or screw (`body`) before it meets the
+ part in it. */
+ const jointCuts = again ? known.list : [];
+ /* Room past the most the cell or the floor leaves cannot stop a size, so nothing
+ further off than that is measured, and nothing at all where neither leaves any. A
+ plate the page will build has at most 900 cells; at 30 × 30 with puzzle tabs this
+ is a few milliseconds, on every redraw. */
+ const reach = Math.max(fit(top), fit(under));
+ if (layout && !again && !bosses && cfg.connector !== 'none' && reach > 0) {
+ const plan = keyPlan(cfg), H = pad + cfg.plateHeight;
+ /* A cut's footprint, as the segments its walls stand on, its extent and its ceiling,
+ for each seam it can be cut from, and the part's that goes in it: the key's half,
+ or the tab of the piece across the seam, as buildPiece stands it there, the fit
+ clearance inside the cut. Every cut from one seam is the same solid moved along it
+ (keyHalf, puzzleShape, tabNotch), so it is worked out at the origin once and each
+ site is moved the other way instead. */
+ const shapes = {};
+ const ring = (pts) => pts.map((p, i) => [p, pts[(i + 1) % pts.length]]);
+ const shapeOf = (edge) => {
+ if (shapes[edge]) return shapes[edge];
+ const at = { edge, e: 0, s: 0 };
+ const solid = plan.kind === 'recess'
+ ? keySiteOps(plan.kind, plan.shape, plan.prm, plan.clr, edge, 0, 0, H).cut
+ : tabNotch(cfg, at, pad);
+ const segs = [], bb = [Infinity, Infinity, -Infinity, -Infinity];
+ let ceiling = -Infinity;
+ for (const p of solid) {
+ for (const v of p.verts) {
+ ceiling = Math.max(ceiling, v[2]);
+ bb[0] = Math.min(bb[0], v[0]); bb[1] = Math.min(bb[1], v[1]);
+ bb[2] = Math.max(bb[2], v[0]); bb[3] = Math.max(bb[3], v[1]);
+ }
+ if (Math.abs(p.plane.n[2]) > 1e-9) continue;
+ const a = p.verts[0], b = p.verts.find((v) => Math.hypot(v[0] - a[0], v[1] - a[1]) > 1e-9);
+ if (b) segs.push([a, b]);
+ }
+ const part = plan.kind === 'recess' ? keyHalf(plan.shape, edge, 0, 0, plan.prm, 0)
+ : cfg.connector === 'puzzle' ? puzzleShape(OPP[edge], 0, 0, cfg.puzzle, 0, false)
+ : tabFootprint(OPP[edge], 0, 0, cfg.tab.wr, cfg.tab.wt, cfg.tab.dp, 0.8);
+ // the ceiling to the micron: a notch's is 2.2 + 0.2, 2.4000000000000004 as summed
+ const roof = Math.round(ceiling * 1e6) / 1e6;
+ return (shapes[edge] = { segs, bb, ceiling: roof, part: ring(part) });
+ };
+ // how far a point is from the footprint, less than none inside it
+ const from = (segs, x, y) => {
+ let d = Infinity, inside = false;
+ for (const [a, b] of segs) {
+ const dx = b[0] - a[0], dy = b[1] - a[1];
+ const t = Math.max(0, Math.min(1, ((x - a[0])*dx + (y - a[1])*dy) / (dx*dx + dy*dy)));
+ d = Math.min(d, Math.hypot(a[0] + t*dx - x, a[1] + t*dy - y));
+ if ((a[1] > y) !== (b[1] > y) && x < a[0] + (y - a[1]) * dx / dy) inside = !inside;
+ }
+ return inside ? -d : d;
+ };
+ for (const piece of layout.pieces) {
+ const conn = pieceConnectors(cfg, layout, piece);
+ // the cuts buildPiece makes in this piece: notches for tabs, recesses for keys
+ const cuts = [...conn.notches, ...conn.pnotches, ...(plan.kind !== 'recess' ? []
+ : conn.keyed.filter((bo) => !(plan.junction && offJunction(bo, cfg.pitch, piece))))];
+ for (const bo of cuts) {
+ const { segs, bb, ceiling, part } = shapeOf(bo.edge);
+ const across = bo.edge === '+x' || bo.edge === '-x';
+ const ox = across ? bo.e : bo.s, oy = across ? bo.s : bo.e;
+ // the whole cells with a site in reach of it (a half cell has none; see buildPiece)
+ const cells = (lo, hi, m, n) => [Math.max(0, Math.floor((lo - reach - off - half - m) / cfg.pitch)),
+ Math.min(n - 1, Math.ceil((hi + reach + off - half - m) / cfg.pitch))];
+ const [i0, i1] = cells(bb[0] + ox, bb[2] + ox, piece.mL, piece.nx);
+ const [j0, j1] = cells(bb[1] + oy, bb[3] + oy, piece.mF, piece.ny);
+ const sites = [];
+ for (let i = i0; i <= i1; i++) for (let j = j0; j <= j1; j++)
+ for (const sx of [-1, 1]) for (const sy of [-1, 1]) {
+ const x = piece.mL + i*cfg.pitch + half + sx*off - ox;
+ const y = piece.mF + j*cfg.pitch + half + sy*off - oy;
+ if (x < bb[0] - reach || x > bb[2] + reach || y < bb[1] - reach || y > bb[3] + reach) continue;
+ // the bores and the part stand further off than the corner circle, or as far
+ const room = from(segs, x, y);
+ if (room >= reach) continue;
+ const bore = (n) => room > 0 ? boreReach(n, segs, x, y) : room;
+ sites.push({ room, body: from(part, x, y), bore: { 12: bore(12), 14: bore(14) } });
+ }
+ if (sites.length) jointCuts.push({ top: ceiling, sites });
+ }
+ }
+ }
+ /* The bores as fastenerCutter cuts them, in one place: how many sides, and the largest
+ size whose corners stay inside a radius. A magnet's corners are 0.1 mm over its
+ radius, or out to where its flats stand on that radius if that is further; a screw's
+ bores have their corners on its size. */
+ const BORE = {
+ magnetD: { sides: 14, fits: (r) => 2 * Math.min(r - 0.1, r * Math.cos(Math.PI / 14)) },
+ screwHeadD: { sides: 14, fits: (r) => 2 * r },
+ screwHoleD: { sides: 12, fits: (r) => 2 * r },
+ };
+ // the room the cell, the floor or a boss leaves, and the hole beside
+ const own = { magnetD: fit(cfg.magnetSide === 'top' ? top : under), screwHoleD: fit(top), screwHeadD: fit(under) };
+ // a dovetail's notch takes a pocket from beneath that breaks into it; every other cut does not
+ const notch = cfg.connector === 'dovetail';
+ /* What the joint's cuts leave one size, as { cap, why, near }: the largest size, and what
+ stops it: 'cut', a pocket that would break into a key's recess or a puzzle tab's notch;
+ 'floor', one from above that leaves no layer of floor over a cut; 'level', one from
+ beneath as deep as a dovetail's notch; 'part', a magnet or screw that would reach the
+ tab in one. Each stops MOUNT_SEAM short of the cut. `near` is where that leaves sizes
+ under the cap refused, as [from, to]: a dovetail's notch, which a pocket may break
+ into, but not stop just short of. */
+ const jointFor = (f) => {
+ const { sides, fits } = BORE[f];
+ const above = f === 'magnetD' && cfg.magnetSide === 'top';
+ // how high a pocket from beneath goes; a shank goes through
+ const ceiling = f === 'magnetD' ? cfg.magnetH : f === 'screwHeadD' ? cfg.screwHeadDepth : Infinity;
+ let cap = Infinity, why = false;
+ const near = [];
+ for (const c of jointCuts) {
+ // a pocket from above clears a cut whose ceiling it leaves a layer of floor over
+ if (above && !(c.top + MOUNT_SKIN > pad - cfg.magnetH + 1e-6)) continue;
+ /* Level within MOUNT_LEVEL, measured to the micron, so a pocket that far above the
+ notch's ceiling and one that far below it are taken alike: 2.35 and 2.45 mm deep
+ against a notch 2.4 mm high, which both build clean. Unrounded, 2.45 counted as
+ level, and with the ceiling alone rounded 2.35 would. */
+ const level = Math.round(Math.abs(ceiling - c.top) * 1e6) / 1e6 < MOUNT_LEVEL;
+ const stop = above ? 'floor' : !notch ? 'cut' : level ? 'level' : 'part';
+ for (const s of c.sites) {
+ const short = fits(s.bore[sides] - MOUNT_SEAM);
+ const size = stop === 'part' ? 2 * s.body : short;
+ if (size < cap) { cap = size; why = stop; }
+ if (stop === 'part') near.push([short, fits(s.bore[sides])]);
+ }
+ }
+ return { cap, why, near };
+ };
+ const sizes = {}, joint = {}, gaps = {};
+ for (const f of ['magnetD', 'screwHoleD', 'screwHeadD']) {
+ const cell = BORE[f].fits(own[f]), J = jointFor(f);
+ let size = r10(Math.min(cell, J.cap));
+ joint[f] = J.cap < cell && J.why;
+ /* The sizes `near` refuses, out to the hundredths either side, since the field takes
+ hundredths: each gap is [from, to], both taken. A window is about 0.02 mm wide, so
+ rounded out to the tenths as the cap is, it refused up to a tenth that builds clean
+ (5.51 to 5.69 at 36 mm). One that reaches the cap brings it down to where it starts. */
+ const out = [];
+ for (const [a, b] of J.near.sort((x, y) => x[0] - y[0])) {
+ const from = Math.floor(a * 100 + 1e-9) / 100, to = (Math.floor(b * 100 + 1e-9) + 1) / 100;
+ if (to <= 0) continue;
+ if (out.length && from < out[out.length - 1][1]) out[out.length - 1][1] = Math.max(out[out.length - 1][1], to);
+ else out.push([from, to]);
+ }
+ gaps[f] = [];
+ for (const [from, to] of out) {
+ if (from >= size) break;
+ if (to > size) { size = from; joint[f] = 'near'; break; }
+ gaps[f].push([from, to]);
+ }
+ sizes[f] = size;
+ }
return {
- // a magnet pocket's corners are 0.1 mm over the magnet's radius, or out to where its
- // flats stand on that radius if that is further (fastenerCutter)
- magnetD: r10(2 * Math.min(room - 0.1, room * Math.cos(Math.PI / 14))),
- // a screw's bores have their corners on its size
- screwHoleD: r10(2 * fit(top)),
- screwHeadD: r10(2 * fit(under)),
+ magnetD: sizes.magnetD,
+ screwHoleD: sizes.screwHoleD,
+ screwHeadD: sizes.screwHeadD,
// in the solid floor the pad grows to suit, so only a boss caps the depth
depth: bosses ? r10(BOSS_H - MOUNT_SKIN) : Infinity,
// which of the sizes the cut beside it stops, rather than the floor, cell or boss
- beside: { magnetD: room === beside, screwHoleD: top >= beside, screwHeadD: under >= beside },
+ beside: { magnetD: own.magnetD === beside && !joint.magnetD,
+ screwHoleD: own.screwHoleD === beside && !joint.screwHoleD,
+ screwHeadD: own.screwHeadD === beside && !joint.screwHeadD },
+ // and which a joint's cut stops, before any of those, and how (jointFor)
+ joint,
+ // sizes under the largest refused all the same, as [from, to] with both ends taken
+ gaps,
+ // what was measured of the joint's cuts, for `known`
+ cuts: { pad, list: jointCuts },
};
}
@@ -2571,7 +2861,38 @@ function buildPiece(cfg, layout, piece, onStatus) {
}
return out;
};
- const fastenerFoot = wallsAt(0), fastenerTop = pad > 0.01 ? wallsAt(pad) : [];
+ /* The same, its corners only. Where the walls of two bores were unioned (a counterbore,
+ its screw's shank), the BSP split each wall along the other's planes, and wallsAt
+ hands back those split points as well: two on every flat of the shank, 24 points on
+ the socket floor that are no corner of anything. A 2.4 mm shank under a 4.8 mm head
+ at 44.08 mm, with loose tolerance, had a spoke within FAN_CLEAR of one of them from
+ every point fanCentre tries, so the socket floor's fan never moved and the cell
+ shipped with six open edges. A corner is where two walls that are not in line meet;
+ a split point is where one wall was cut in two. From the corners alone the fan moves
+ 0.2 mm and the floor closes. Only the socket floor's list, which only an open cell's
+ refan reads (buildPiece), so every cell that came out closed is built as before. */
+ const cornersAt = (z) => {
+ const ends = new Map(); // a wall end, to the directions of the walls that end there
+ for (const p of cellFastener || []) {
+ const zs = p.verts.map((v) => v[2]);
+ if (!(Math.min(...zs) < z && Math.max(...zs) > z) || Math.abs(p.plane.n[2]) > 1e-9) continue;
+ const d = [-p.plane.n[1], p.plane.n[0]]; // along the wall
+ let lo = null, hi = null;
+ for (const v of p.verts) {
+ const t = v[0]*d[0] + v[1]*d[1];
+ if (!lo || t < lo[0]) lo = [t, v];
+ if (!hi || t > hi[0]) hi = [t, v];
+ }
+ for (const [, v] of [lo, hi]) {
+ const k = `${v[0].toFixed(6)} ${v[1].toFixed(6)}`;
+ if (!ends.has(k)) ends.set(k, { at: [v[0], v[1]], dirs: [] });
+ ends.get(k).dirs.push(d);
+ }
+ }
+ return [...ends.values()].filter(({ dirs }) =>
+ dirs.some((a) => dirs.some((b) => Math.abs(a[0]*b[1] - a[1]*b[0]) > 1e-6))).map((e) => e.at);
+ };
+ const fastenerFoot = wallsAt(0), fastenerTop = pad > 0.01 ? cornersAt(pad) : [];
// ---- connectors ----
const conn = pieceConnectors(cfg, layout, piece);
@@ -2965,7 +3286,9 @@ function buildPiece(cfg, layout, piece, onStatus) {
* And once every cell is built, the shells settle cut again are checked as a whole, with
* those beside them: if they have more bad edges (checkManifold) than they had before,
* or more open or turned over (healCsgSeams), every one goes back to its first cut. So
- * settle never leaves a piece worse than it found it, whatever order the cells come in.
+ * settle never leaves those shells worse than it found them, whatever order the cells
+ * come in. What is made after the check is not judged by it: the dovetail and puzzle
+ * tabs, and what the top-insert pass cuts again (see the check below).
* `alt` and `pocket` are the cuts a cell was last taken with, so a cell cut again for
* one reason keeps what it was cut again for the other. */
const POCKET_TRIES = 7;
@@ -3138,22 +3461,7 @@ function buildPiece(cfg, layout, piece, onStatus) {
(nb.edge === '+x' ? Math.abs(x1 - W) : Math.abs(x0)) < nDp + 0.2)
: (nb.s > x0 - nWt && nb.s < x1 + nWt &&
(nb.edge === '+y' ? Math.abs(y1 - D) : Math.abs(y0)) < nDp + 0.2);
- if (near) {
- // 4-pt taper: no vertex sits exactly on the region side plane; jitter breaks
- // residual coincidences with ring geometry
- const J = 0.0017, BK = 1.0, e = nb.e, s = nb.s + J;
- let pts;
- if (nb.edge === '+x' || nb.edge === '-x') {
- const g = nb.edge === '-x' ? 1 : -1; // cut extends INTO the piece
- pts = [[e - g*BK, s - nWr/2], [e + g*nDp, s - nWt/2],
- [e + g*nDp, s + nWt/2], [e - g*BK, s + nWr/2]];
- } else {
- const g = nb.edge === '-y' ? 1 : -1;
- pts = [[s - nWr/2, e - g*BK], [s - nWt/2, e + g*nDp],
- [s + nWt/2, e + g*nDp], [s + nWr/2, e - g*BK]];
- }
- cuts.notch.push(...extrudePoly(pts, -0.503, Math.min(t.h + 0.2, H - 0.8)));
- }
+ if (near) cuts.notch.push(...tabNotch(cfg, nb, pad));
}
for (const bo of keyed) {
if (plan.junction && offJunction(bo, pitch, piece))
@@ -3183,9 +3491,7 @@ function buildPiece(cfg, layout, piece, onStatus) {
(pn.edge === '+x' ? Math.abs(x1 - W) : Math.abs(x0)) < reach)
: (pn.s > x0 - cfg.puzzle.lobeR*2 && pn.s < x1 + cfg.puzzle.lobeR*2 &&
(pn.edge === '+y' ? Math.abs(y1 - D) : Math.abs(y0)) < reach);
- if (near) cuts.puzzle.push(
- ...extrudePoly(puzzleShape(pn.edge, pn.e, pn.s, cfg.puzzle, cfg.puzzle.clr, true),
- -0.5, pad - 0.4));
+ if (near) cuts.puzzle.push(...tabNotch(cfg, pn, pad));
}
/* None in a half cell. A half-size bin's quarter feet carry no holes (feetHolesOff
in bins/bin.js), and where a half socket's would go is not settled: a whole
@@ -3309,8 +3615,10 @@ function buildPiece(cfg, layout, piece, onStatus) {
Only here, not on every cell: a 6 mm magnet from above at 42 mm has a spoke 2.3
microns from a corner in every cell and comes out closed, as most do. And only
where the fan moves and the cell is open at the floor's height: a cell open
- somewhere else, as a pocket that meets a joint's housing is, or one whose spokes
- are already clear, would be cut again for the same result. A bowtie plate at
+ somewhere else, as a pocket that meets a joint's housing is, would be cut again
+ for the same result, and so would one whose fan stays where it was, either because
+ its spokes are already clear or because fanCentre finds no point clear of every
+ corner and keeps the centre. A bowtie plate at
45.57 mm with screws, open in every piece on main as well, took twice as long
with every open cell cut again. */
if (region.open && floorAvoid.length && openAt(region, pad)) {
diff --git a/src/ui.js b/src/ui.js
index ac56878..21d5ab1 100644
--- a/src/ui.js
+++ b/src/ui.js
@@ -44,6 +44,8 @@ const PIECE_COLORS = ['#4fc3e8','#e8b34f','#7fd8a5','#e88a8a','#b18ae8','#7fb5e8
const numIds = ['drawerW','drawerD','bedW','bedD','bedH','mLeft','mRight','mFront','mBack',
'pitch','outerRadius','bottomPad','topCutoff','magnetD','magnetH',
'screwHoleD','screwHeadD','screwHeadDepth','infill'];
+// the ones readControls reads after the rest, in this order (see there)
+const MOUNT_LAST = ['magnetH', 'screwHeadDepth', 'screwHoleD', 'screwHeadD', 'magnetD'];
/* The fields that carry a real-world size, and the range one can be.
*
@@ -74,19 +76,53 @@ const numIds = ['drawerW','drawerD','bedW','bedD','bedH','mLeft','mRight','mFron
* off, nor margins outside Custom, because a complaint about a field you cannot see is
* one you cannot act on. `why` finishes the too-big message where "check the figure is
* in millimetres" would be the wrong advice, and `off` names the switch that drops a cut
- * the pitch has no room for. */
+ * the pitch has no room for. `gaps` are sizes under `max` refused all the same, as
+ * [from, to] with both ends taken. */
const RANGES = PLATE_RANGES;
const customMargins = () => state.marginMode === 'custom' && !state.noMargin;
-const mount = () => mountLimits(state);
+/* The sizes a joint's cut in the floor leaves room for depend on where the seams are and
+ on the clearance, so mountLimits takes the layout, and readControls reads the mounting
+ sizes after everything that moves either. The layout is worked out once for a read, the
+ first time a size needs it, and recomputeLayout keeps that one rather than working it
+ out again: none of the mounting sizes moves it. In Fewest plates mode one is a search,
+ about 100 ms, and with magnets on a keystroke ran three. The answer is kept meanwhile,
+ for the range and the reason alike. */
+let mountNow = null, mountLayout = null;
+const mount = () => mountNow ||
+ (mountNow = mountLimits(state, mountLayout || (mountLayout = computeLayout(state))));
+// how deep a pocket goes: only a corner boss caps it, which needs no layout
+const mountDepth = () => mountLimits(state).depth;
// "an 18 mm pitch", "an 80 mm pitch": the article goes by how the number is said
const atPitch = () => `at ${/^(8|1[18](\.|$))/.test(String(state.pitch)) ? 'an' : 'a'} ` +
`${state.pitch} mm pitch`;
-const mountWhy = (opens, field) => `${atPitch()} — mounting holes sit ` +
- `${state.holeOffset} mm from each cell centre, where the Gridfinity spec puts them, and ` +
- (mount().beside[field] ? 'a cell\'s four holes have to stay clear of each other'
- : state.baseMode === 'bosses' ? 'a pocket has to stay inside its corner boss'
- : opens ? 'a cut open to the socket has to stay on the socket floor'
- : 'a pocket under the floor has to stay inside its cell');
+// a joint's cut in the floor, as the messages name it: "the notches the dovetail tabs fit into"
+const cutsNamed = () => `${['dovetail', 'puzzle'].includes(state.connector) ? 'notches' : 'recesses'} the ` +
+ `${CONNECTOR_NAMES[state.connector]} fit into`;
+/* Why `field` stops where it does. A joint's cut stops it in one of the ways mountLimits'
+ `joint` names: a pocket from beneath as deep as a dovetail's notch, a magnet or screw
+ that would reach the tab in one, a pocket any wider coming too near the notch's edge,
+ or any other hole breaking into the cut. */
+const mountWhy = (opens, field) => {
+ const joint = mount().joint[field];
+ const cuts = cutsNamed();
+ return `${atPitch()} — mounting holes sit ` +
+ `${state.holeOffset} mm from each cell centre, where the Gridfinity spec puts them, and ` +
+ (joint === 'level' ? `a pocket ${field === 'magnetD' ? state.magnetH : state.screwHeadDepth} mm deep, ` +
+ `as deep as the ${cuts}, has to stay out of them`
+ : joint === 'part' ? `${{ magnetD: 'a magnet', screwHeadD: 'a screw head', screwHoleD: 'a screw' }[field]} ` +
+ `has to stay clear of the ${CONNECTOR_NAMES[state.connector]} in the notches beside it`
+ : joint === 'near' ? `a pocket any wider would come too near the edge of the ${cuts} to cut cleanly`
+ : joint ? `a hole has to stay out of the ${cuts}`
+ : mount().beside[field] ? 'a cell\'s four holes have to stay clear of each other'
+ : state.baseMode === 'bosses' ? 'a pocket has to stay inside its corner boss'
+ : opens ? 'a cut open to the socket has to stay on the socket floor'
+ : 'a pocket under the floor has to stay inside its cell') +
+ (joint && KEYED.includes(state.connector) && !keyFromTop()
+ ? `; keys ${keyInWall() ? '' : 'housed inside the walls and '}put in from above ` +
+ 'keep out of the solid floor under these pockets' : '');
+};
+// why a size under the largest is refused (mountLimits' `gaps`)
+const nearWhy = () => `${atPitch()} — its pocket would come too near the edge of the ${cutsNamed()} to cut cleanly`;
const bossDepth = () => state.baseMode === 'bosses'
? 'with corner pockets — a boss is 2.6 mm tall, while the solid floor grows to suit' : '';
const LIMITS = {
@@ -113,14 +149,17 @@ const LIMITS = {
tooSmall: 'at 0 the rim between sockets is a face with no width, and the plate comes out open',
why: () => '— past that a spec bin rides on the rim instead of seating in its socket' },
magnetD: { ...RANGES.magnetD, max: () => mount().magnetD, label: 'Magnet Ø', when: () => state.magnets,
- why: () => mountWhy(state.magnetSide === 'top', 'magnetD'), off: 'magnet pockets' },
- magnetH: { ...RANGES.magnetH, max: () => Math.min(RANGES.magnetH.max, mount().depth), label: 'Magnet depth',
+ why: () => mountWhy(state.magnetSide === 'top', 'magnetD'), off: 'magnet pockets',
+ gaps: () => mount().gaps.magnetD },
+ magnetH: { ...RANGES.magnetH, max: () => Math.min(RANGES.magnetH.max, mountDepth()), label: 'Magnet depth',
when: () => state.magnets, why: bossDepth },
screwHoleD: { ...RANGES.screwHoleD, max: () => mount().screwHoleD, label: 'Screw hole Ø',
- when: () => state.screws, why: () => mountWhy(true, 'screwHoleD'), off: 'screw holes' },
+ when: () => state.screws, why: () => mountWhy(true, 'screwHoleD'), off: 'screw holes',
+ gaps: () => mount().gaps.screwHoleD },
screwHeadD: { ...RANGES.screwHeadD, max: () => mount().screwHeadD, label: 'Screw head Ø',
- when: () => state.screws, why: () => mountWhy(false, 'screwHeadD'), off: 'screw holes' },
- screwHeadDepth: { ...RANGES.screwHeadDepth, max: () => Math.min(RANGES.screwHeadDepth.max, mount().depth),
+ when: () => state.screws, why: () => mountWhy(false, 'screwHeadD'), off: 'screw holes',
+ gaps: () => mount().gaps.screwHeadD },
+ screwHeadDepth: { ...RANGES.screwHeadDepth, max: () => Math.min(RANGES.screwHeadDepth.max, mountDepth()),
label: 'Screw head depth', when: () => state.screws, why: bossDepth },
// each joint's ceiling is its own, so none is held to another's reason; see clrWhy
connClr: { min: RANGES.connClr.min, max: () => connClrCeiling(state).max, label: 'Fit clearance',
@@ -226,6 +265,27 @@ function readNumber(id) {
(why ? `${why}.` : `— check the figure is in ${unitName}.`));
return hi;
}
+ /* A size under the largest can be refused as well, where its pocket would come too near
+ the edge of a dovetail's notch (mountLimits' `gaps`); the sizes either side are taken.
+ Two gaps can meet at one taken size, so the advice names the sizes taken round the
+ run of gaps the size is in, inside the field's range: "Use 11.89 mm or less, 11.92 mm,
+ or 11.95 mm or more" at 41.49 mm, never a size in the next gap, under the field's least
+ or over its largest. */
+ const gaps = inPlay && lim.gaps ? lim.gaps() : [];
+ const at = gaps.findIndex(([a, b]) => v > a && v < b);
+ if (at >= 0) {
+ let i = at, j = at;
+ while (i > 0 && gaps[i - 1][1] >= gaps[i][0] - 1e-9) i--;
+ while (j < gaps.length - 1 && gaps[j + 1][0] <= gaps[j][1] + 1e-9) j++;
+ const ok = [];
+ if (gaps[i][0] > lo) ok.push(`${both(gaps[i][0])} or less`);
+ else if (gaps[i][0] === lo) ok.push(both(lo));
+ for (let k = i; k < j; k++) if (gaps[k][1] >= lo) ok.push(both(gaps[k][1]));
+ ok.push(gaps[j][1] < hi ? `${both(gaps[j][1])} or more` : both(gaps[j][1]));
+ say(`${lim.label} of ${both(v)} is refused ${nearWhy()}. Use ` +
+ (ok.length > 1 ? `${ok.slice(0, -1).join(', ')}, or ${ok[ok.length - 1]}` : ok[0]) + '.');
+ return gaps[at][0] >= lo ? gaps[at][0] : gaps[at][1];
+ }
return v;
}
/* The invalid state is set on the element rather than through a class, because the
@@ -270,7 +330,7 @@ function readControls() {
state.magnets = $('magnets').checked;
state.screws = $('screws').checked;
state.magnetSide = $('magnetSide').value;
- for (const id of numIds) state[id] = readNumber(id);
+ for (const id of numIds) if (!MOUNT_LAST.includes(id)) state[id] = readNumber(id);
if (state.noMargin) { state.marginMode = 'custom'; state.mLeft = state.mRight = state.mFront = state.mBack = 0; }
// the per-corner radii need no range here: buildPiece caps each one at the socket's rim
if ($('perCorner').checked) {
@@ -290,6 +350,22 @@ function readControls() {
state.key = Object.assign({}, DEFAULTS.key, { clr: fit.key });
state.hclip = Object.assign({}, DEFAULTS.hclip, { clr: fit.hclip });
state.puzzle = Object.assign({}, DEFAULTS.puzzle, { clr: fit.puzzle });
+ /* The mounting sizes last, since a joint's cut beside the sites moves with the margins,
+ the split and the clearance (see mount). The magnet's is the very last, and measured
+ again: a pocket from above meets a cut by how thick the floor is, which the screws
+ and the magnet's own depth set. Only that step is taken again, on the same layout
+ and the cuts already measured, unless the floor has moved (mountLimits' `known`). */
+ mountNow = mountLayout = null;
+ for (const id of MOUNT_LAST) {
+ if (id === 'magnetD' && mountNow) mountNow = mountLimits(state, mountLayout, mountNow.cuts);
+ state[id] = readNumber(id);
+ }
+ // and Checks says what is wrong in the panel's order, not the order it was read in
+ for (const m of [fieldErrors, noRoom]) {
+ const read = new Map(m);
+ m.clear();
+ for (const id of [...numIds, 'connClr']) if (read.has(id)) m.set(id, read.get(id));
+ }
// half cells keep the alignment: it places what is left after them
$('alignRow').style.display = mm === 'auto' || mm === 'half' ? '' : 'none';
$('halfHint').style.display = mm === 'half' ? '' : 'none';
@@ -356,7 +432,7 @@ function plateStyleHint() {
nothing, and each of those is a discrete edit. */
function recomputeLayout(ev) {
readControls();
- layout = computeLayout(state);
+ layout = mountLayout || computeLayout(state); // the one the sizes were read against, if any
// clamp stored manual cuts to the current grid
if (state.splitMode === 'manual') {
state.rowCuts = layout.rowCuts.slice();
diff --git a/sw.js b/sw.js
index 5eab1c9..3af8f97 100644
--- a/sw.js
+++ b/sw.js
@@ -52,7 +52,7 @@
load from this site, and the app's icons and manifest, as paths from the root. VERSION
is a hash of all of those files, names and bytes, and of this script as it is served,
FILES filled in and everything else but VERSION itself. */
-const VERSION = "adc911090779";
+const VERSION = "d4d7bc3b8d8c";
const FILES = [
"./",
"bins/",
diff --git a/test/plate-audit.js b/test/plate-audit.js
index 279a6fe..ba25df4 100644
--- a/test/plate-audit.js
+++ b/test/plate-audit.js
@@ -1998,6 +1998,101 @@ console.log('\nthe other limits, built at their ends:');
console.log(` ${nm.padEnd(28)} ${leakText(r)}`);
if (r.bad) bad++;
}
+ /* A pocket against a joint's cut in the floor (#64). A bowtie housed in the floor at
+ 42 mm, with magnets from beneath, built 12 bad edges at 7.9 mm and 19 at 10 with
+ Download on: the pocket reached the key's recess, and with both ceilings 2 mm up the
+ two shared a face. mountLimits keeps every mounting cut out of a joint's cut now,
+ measured on the layout, so each case is built at the widest the page takes, which
+ has to come out watertight, and the first tenth past it, and a size main took that
+ reaches the cut (the first that leaked, where one did), have to be refused. Two
+ pieces side by side, so the seam between them is cut. The bands are #61's, where its
+ wider pocket brought the leak 0.1 to 0.4 mm lower. From above, an 8 mm magnet's
+ pocket breaks into the recess under it without a bad edge, the magnet itself about
+ 0.13 mm clear of the key: refused all the same, as every pocket that breaks into a
+ key's recess is (see mountLimits). In the wall, main's widest leaked. The 38.13 mm link is
+ the one #61 left for later: its 6.5 mm counterbore stood 0.7 mm into a puzzle key's
+ recess. The last two are the spec's 6.5 × 2.4 magnet beside a tab, whose notch stops
+ 2.4 mm up as well. And the same bowtie in four pieces with strips of half cells and
+ margins round them, whose whole cells are the ones measured. */
+ const pair = (p, o) => ({ pitch: p, drawerW: 4 * p, drawerD: 2 * p, bedW: 2 * p + 16, bedD: 400, ...o });
+ const JOINTED = [ // [what, design, field, a size main took into the cut]
+ ['bowtie, magnet below, 42', pair(42, { connector: 'bowtie', magnets: true }), 'magnetD', 7.9],
+ ['bowtie, magnet above, 42', pair(42, { connector: 'bowtie', magnets: true, magnetSide: 'top' }), 'magnetD', 8],
+ ['bowtie, screw head, 42', pair(42, { connector: 'bowtie', screws: true }), 'screwHeadD', 8.2],
+ ['snap, magnet below, 49.02', pair(49.02, { connector: 'snap', magnets: true }), 'magnetD', 17.2],
+ ['puzzle key, below, 46', pair(46, { connector: 'puzzlekey', magnets: true }), 'magnetD', 16],
+ ['puzzle key, below, 49.02', pair(49.02, { connector: 'puzzlekey', magnets: true }), 'magnetD', 20.2],
+ ['bowtie in the wall, 44.17', pair(44.17, { connector: 'bowtie', keyMount: 'wall', magnets: true }), 'magnetD', 15.7],
+ ['38.13 mm link, counterbore', { drawerW: 134.56, drawerD: 120.48, mLeft: 11.96, mRight: 8.21, mFront: 5.39,
+ mBack: 0.7, bedW: 67.2, bedD: 86.26, connector: 'puzzlekey', clr: 0.2, screws: true, screwHoleD: 3,
+ screwHeadD: 6.5, pitch: 38.13, outerRadius: 3.49, topCutoff: 1 }, 'screwHeadD', 6.5],
+ ['puzzle tabs, 2.4 deep, 38', pair(38, { connector: 'puzzle', magnets: true, magnetH: 2.4 }), 'magnetD', 6.5],
+ ['dovetail, 2.4 deep, 36', pair(36, { connector: 'dovetail', magnets: true, magnetH: 2.4 }), 'magnetD', 6.5],
+ ['bowtie, half cells, 42', { pitch: 42, drawerW: 199, drawerD: 199, marginMode: 'half', bedW: 120, bedD: 120,
+ connector: 'bowtie', magnets: true }, 'magnetD', 7.9],
+ ];
+ for (const [nm, o, f, into] of JOINTED) {
+ const cfg = designCfg(o);
+ const lims = G.mountLimits(cfg, G.computeLayout(cfg)), lim = lims[f];
+ const takes = (d) => d <= lim + 1e-9;
+ const widest = buildAll(sized(o, f, lim));
+ const past = Math.round(lim * 10 + 1) / 10;
+ const taken = [past, into].filter(takes)
+ .map((d) => `${d} mm TAKEN, and ${leakText(buildAll(sized(o, f, d)))}`);
+ console.log(` ${nm.padEnd(28)} widest ${lim} mm ${leakText(widest)}; ` +
+ (taken.join('; ') || `${past} and ${into} mm refused`));
+ if (widest.bad) bad++;
+ bad += taken.length;
+ }
+ /* What a pocket may and may not do in a joint's cut, by size, each with the reason
+ mountLimits gives (false where it takes the size). A dovetail's notch takes a pocket
+ from beneath that breaks into it, unless the two ceilings are level or the magnet
+ reaches the tab: the half-inch magnet on the page's default design at 42 mm, 2 and
+ 3 mm thick, has to be taken and come out watertight; 2.4 thick, level with the
+ notch, it built 96 bad edges and has to be refused, but 2.45 thick, as far off level
+ as 2.35, is taken; and 13.2 mm, 2 thick, builds clean but would touch the tab. At
+ 36 mm a 5.6 mm magnet's pocket would stand right on the notch's wall, under
+ MOUNT_SEAM from it, so it is refused there (a gap), and 5.65 and 5.7, which break in,
+ are taken. Any other cut takes none: the snap clip at 36.52 mm
+ is the review's, a 1.5 mm magnet at a fit clearance of 0.5 whose pocket is only
+ 0.019 mm into the recess, and main built it with 6 bad edges at 2.5 mm deep (and at
+ 1.9, 2.1 and 2.4). The refused ones are built too, to show what main would have, but
+ only the reason is held to. */
+ const PAGE = { marginMode: 'auto', connector: 'dovetail', magnets: true };
+ const SNAP = { pitch: 36.52, drawerW: 73.04, drawerD: 73.04, bedW: 52.52, bedD: 400, splitMode: 'balanced',
+ connector: 'snap', keyMount: 'floor', keyInsert: 'bottom', tolerance: 'tight', clr: 0.5,
+ magnets: true, magnetH: 2.5, screws: true, screwHoleD: 1.6, screwHeadD: 1.6, screwHeadDepth: 2 };
+ for (const [nm, o, f, d, why] of [
+ ['dovetail, 12.7 x 2, page', { ...PAGE, magnetH: 2 }, 'magnetD', 12.7, false],
+ ['dovetail, 12.7 x 3, page', { ...PAGE, magnetH: 3 }, 'magnetD', 12.7, false],
+ ['dovetail, 12.7 x 2.4, page', { ...PAGE, magnetH: 2.4 }, 'magnetD', 12.7, 'level'],
+ ['dovetail, 12.7 x 2.45, page', { ...PAGE, magnetH: 2.45 }, 'magnetD', 12.7, false],
+ ['dovetail, 13.2 x 2, page', { ...PAGE, magnetH: 2 }, 'magnetD', 13.2, 'part'],
+ ['dovetail, 5.6 x 2, page, 36', { ...PAGE, pitch: 36, magnetH: 2 }, 'magnetD', 5.6, 'gap'],
+ ['dovetail, 5.65 x 2, page, 36', { ...PAGE, pitch: 36, magnetH: 2 }, 'magnetD', 5.65, false],
+ ['dovetail, 5.7 x 2, page, 36', { ...PAGE, pitch: 36, magnetH: 2 }, 'magnetD', 5.7, false],
+ ['snap, 1.5 x 2.5, 36.52', SNAP, 'magnetD', 1.5, 'cut']]) {
+ const cfg = designCfg(sized(o, f, d));
+ const lims = G.mountLimits(cfg, G.computeLayout(cfg));
+ const r = buildAll(sized(o, f, d));
+ const refused = d > lims[f] ? lims.joint[f] : lims.gaps[f].some(([a, b]) => d > a && d < b) && 'gap';
+ const holds = why ? refused === why : !refused && !r.bad;
+ console.log(` ${nm.padEnd(28)} ${refused ? `refused (${refused}), would build` : 'taken,'} ` +
+ `${leakText(r)}${holds ? '' : ` FAIL: ${why ? `has to be refused as ${why}` : 'has to be taken watertight'}`}`);
+ if (!holds) bad++;
+ }
+ /* A counterbore's floor fan (#61's round 4). Where a 4.8 mm head was unioned with its
+ 2.4 mm shank, the shank's flats came back split at the head's planes, and the socket
+ floor's fan was held clear of those split points as well as the corners: no point
+ fanCentre tried was clear of all of them, so the fan stayed put and the cell shipped
+ with 6 open edges, no warning. Only the corners count now. */
+ {
+ const r = buildAll({ pitch: 44.08, drawerW: 137.49, drawerD: 91.53, mLeft: 1.96, mRight: 3.29, mFront: 0.58,
+ mBack: 2.79, bedW: 400, bedD: 400, connector: 'none', tolerance: 'loose',
+ screws: true, screwHoleD: 2.4, screwHeadD: 4.8, screwHeadDepth: 2 });
+ console.log(` ${'counterbore at 44.08 mm'.padEnd(28)} ${leakText(r)}`);
+ if (r.bad) bad++;
+ }
/* The clearance one step past its end, which leaked, and that was why the end is where
it is. It no longer does: the joint's cut taken again when it comes out open
(cutAgain in core.js) closes it, as it closes the steps past the ceilings below. So it
diff --git a/test/ui/plates-robustness.spec.js b/test/ui/plates-robustness.spec.js
index 4edf962..0e8ea58 100644
--- a/test/ui/plates-robustness.spec.js
+++ b/test/ui/plates-robustness.spec.js
@@ -76,7 +76,10 @@ test.describe('Fewest plates on a big grid', () => {
test.describe('ranges on the geometry fields', () => {
/* [link, the line under the field, what it has to say]. The magnet and screw maxima
are the standard 42 mm pitch's, from mountLimits; the pitch cases show the same
- limit moving with the cell, down to no room at all. */
+ limit moving with the cell, down to no room at all. Those take no joint (cn=none):
+ the default dovetail's tabs stop a magnet from beneath first, at 13.1 mm, and the
+ joint cases at the end of the list say so. */
+ const BOWTIE_42 = '#pi=42&w=168&d=84&mm=custom&ml=0&mr=0&mf=0&mb=0&bw=100&bd=400&cn=bowtie&km=floor&ki=bottom';
const CASES = [
['#tc=0', 'errFloor', /Rim cutoff must be at least 0\.1 mm/],
['#tc=5', 'errFloor', /Rim cutoff must be 1 mm or less — past that a spec bin rides on the rim/],
@@ -87,9 +90,9 @@ test.describe('ranges on the geometry fields', () => {
['#mg=1&md=0', 'errMagnet', /Magnet Ø must be at least 1 mm/],
['#mg=1&mh=0', 'errMagnet', /Magnet depth must be at least 0\.5 mm/],
['#mg=1&ms=top&mh=-5', 'errMagnet', /Magnet depth must be at least 0\.5 mm/],
- ['#mg=1&md=20', 'errMagnet', /Magnet Ø must be 13\.6 mm or less at a 42 mm pitch/],
+ ['#cn=none&mg=1&md=20', 'errMagnet', /Magnet Ø must be 13\.6 mm or less at a 42 mm pitch/],
['#mg=1&ms=top&md=10', 'errMagnet', /Magnet Ø must be 8 mm or less at a 42 mm pitch/],
- ['#mg=1&pi=30', 'errMagnet', /Magnet Ø must be 1\.8 mm or less at a 30 mm pitch/],
+ ['#cn=none&mg=1&pi=30', 'errMagnet', /Magnet Ø must be 1\.8 mm or less at a 30 mm pitch/],
// past about 50 mm it is the hole beside a pocket that stops it: a 1-inch magnet met it
['#pi=55&w=110&d=110&mm=custom&ml=0&mr=0&mf=0&mb=0&bw=400&bd=400&mg=1&md=25.4', 'errMagnet',
/Magnet Ø must be 24\.3 mm or less at a 55 mm pitch — mounting holes sit 13 mm from each cell centre, where the Gridfinity spec puts them, and a cell's four holes have to stay clear of each other/],
@@ -97,12 +100,36 @@ test.describe('ranges on the geometry fields', () => {
/Screw head Ø must be 25 mm or less at a 60 mm pitch — .* a cell's four holes have to stay clear of each other/],
['#mg=1&bm=bosses&mh=3', 'errMagnet', /Magnet depth must be 2\.4 mm or less with corner pockets/],
['#sc=1&sh=20', 'errScrew', /Screw hole Ø must be 8\.3 mm or less/],
- ['#sc=1&sd=30', 'errScrew', /Screw head Ø must be 14 mm or less/],
+ ['#cn=none&sc=1&sd=30', 'errScrew', /Screw head Ø must be 14 mm or less/],
['#sc=1&se=50', 'errScrew', /Screw head depth must be 10 mm or less/],
['#cl=1', 'errConnClr', /Fit clearance must be 0\.3 mm or less — any looser and a dovetail pocket/],
['#cn=bowtie&cl=5', 'errConnClr', /Fit clearance must be 1 mm or less — check the figure is in millimetres/],
['#cl=-1', 'errConnClr', /Fit clearance must be at least 0 mm/],
['#pi=10', 'errPitch', /Grid pitch must be at least 13\.5 mm/],
+ /* #64: a hole has to stay out of a joint's cut in the floor. A 10 mm magnet from
+ beneath reached a bowtie's recess at 42 mm, and the plate built with 19 bad edges a
+ piece and Download on; from above, an 8 mm one stood over the key. */
+ [`${BOWTIE_42}&mg=1&md=10`, 'errMagnet',
+ /Magnet Ø must be 7\.6 mm or less at a 42 mm pitch — mounting holes sit 13 mm from each cell centre, where the Gridfinity spec puts them, and a hole has to stay out of the recesses the bowtie keys fit into; keys housed inside the walls and put in from above keep out of the solid floor under these pockets\./],
+ [`${BOWTIE_42}&mg=1&ms=top&md=8`, 'errMagnet',
+ /Magnet Ø must be 7\.6 mm or less at a 42 mm pitch — .* the recesses the bowtie keys fit into/],
+ [`${BOWTIE_42.replace('cn=bowtie', 'cn=snap')}&sc=1&sd=10`, 'errScrew',
+ /Screw head Ø must be 7\.8 mm or less at a 42 mm pitch — .* the recesses the snap clips fit into/],
+ /* A dovetail's notch lets a pocket from beneath in (#69's review, option c), so long
+ as the magnet stays clear of the tab and the pocket is not as deep as the notch,
+ and does not stop just short of its edge; each refusal says which it is. */
+ ['#mg=1&md=20', 'errMagnet',
+ /Magnet Ø must be 13\.1 mm or less at a 42 mm pitch — .* a magnet has to stay clear of the dovetail tabs in the notches beside it\./],
+ ['#mg=1&mh=2.4&md=13', 'errMagnet',
+ /Magnet Ø must be 12\.5 mm or less at a 42 mm pitch — .* a pocket 2\.4 mm deep, as deep as the notches the dovetail tabs fit into, has to stay out of them\./],
+ ['#pi=36&mg=1&md=5.6', 'errMagnet',
+ /Magnet Ø of 5\.6 mm is refused at a 36 mm pitch — its pocket would come too near the edge of the notches the dovetail tabs fit into to cut cleanly\. Use 5\.58 mm or less, or 5\.61 mm or more\./],
+ /* Two gaps can meet at one size, taken between them, and the advice names it rather
+ than pointing into the next gap; nor does it name a size under the field's least. */
+ ['#pi=41.49&mg=1&md=11.93', 'errMagnet',
+ /Magnet Ø of 11\.93 mm is refused at a 41\.49 mm pitch — .* Use 11\.89 mm or less, 11\.92 mm, or 11\.95 mm or more\./],
+ ['#pi=31&cl=0&mg=1&md=1', 'errMagnet',
+ /Magnet Ø of 1 mm is refused at a 31 mm pitch — .* Use 1\.01 mm, or 1\.04 mm or more\./],
];
for (const [hash, errId, msg] of CASES) {
test(`${hash} is refused at the field`, async ({ page }) => {
@@ -118,6 +145,44 @@ test.describe('ranges on the geometry fields', () => {
});
}
+ /* The range moves with the joint. With a bowtie in the floor at 42 mm a magnet from
+ beneath goes up to 7.6 mm, where the cell alone takes 13.6: at 7.6 it builds with
+ Download on, a tenth past is refused with Download off, and with no joint the field
+ takes the cell's size again. */
+ test('a magnet pocket is held out of a joint\'s recess, and the field says how far',
+ async ({ page }) => {
+ const errors = await openAt(page, `${BOWTIE_42}&mg=1&md=7.6`);
+ const max = () => page.evaluate(() => document.getElementById('magnetD').max);
+ expect(await max()).toBe('7.6');
+ expect(await shown(page, 'errMagnet')).toBe(false);
+ expect(await text(page, 'pieceTail')).toMatch(/ready/);
+ expect(await exportOff(page)).toBe(false);
+ await H.setField(page, 'magnetD', '7.7');
+ expect(await text(page, 'errMagnet'))
+ .toMatch(/Magnet Ø must be 7\.6 mm or less .* the recesses the bowtie keys fit into/);
+ expect(await text(page, 'pieceTail')).toMatch(/not building/);
+ expect(await exportOff(page)).toBe(true);
+ await page.selectOption('#connector', 'none');
+ await page.waitForFunction(() => /ready/.test(document.getElementById('pieceTail').textContent),
+ null, { timeout: 30000 });
+ expect(await max()).toBe('13.6');
+ expect(await shown(page, 'errMagnet')).toBe(false);
+ expect(await exportOff(page)).toBe(false);
+ expect(errors).toEqual([]);
+ });
+
+ /* The half-inch magnet on the default dovetail at 42 mm: its pocket breaks 0.04 to
+ 0.09 mm into the notches, the magnet 0.24 mm clear of the tabs, and it builds clean,
+ so the field takes it; 2.4 mm deep, level with the notch, it would not. */
+ test('a half-inch magnet beside the default dovetail is taken', async ({ page }) => {
+ const errors = await openAt(page, '#mg=1&md=12.7&mh=2');
+ expect(await page.evaluate(() => document.getElementById('magnetD').max)).toBe('13.1');
+ expect(await shown(page, 'errMagnet')).toBe(false);
+ expect(await text(page, 'pieceTail')).toMatch(/ready/);
+ expect(await exportOff(page)).toBe(false);
+ expect(errors).toEqual([]);
+ });
+
test('a typed value is held to the same range, and a good one clears it', async ({ page }) => {
await H.openPlates(page);
await H.setField(page, 'topCutoff', '0');
@@ -345,11 +410,16 @@ test.describe('limits no tighter than the geometry', () => {
expect(s.built).toBeCloseTo(7.05, 9);
});
+ /* The 34 mm case takes no joint: the default dovetail's tabs hold its 6 mm screw head
+ to 4.2 mm there, which is a field error of its own. The puzzle tabs' are what leave
+ a magnet no room at 36 mm, where the cell alone would take 7.7. */
for (const [hash, id, errId, carried, msg] of [
- ['#sc=1&pi=34', 'screwHoleD', 'errScrew', 3,
+ ['#cn=none&sc=1&pi=34', 'screwHoleD', 'errScrew', 3,
/Screw hole Ø: there is no room for one at a 34 mm pitch.*Use a larger pitch, or turn off screw holes\./],
['#mg=1&pi=20', 'magnetD', 'errMagnet', 6,
- /Magnet Ø: there is no room for one at a 20 mm pitch.*Use a larger pitch, or turn off magnet pockets\./]])
+ /Magnet Ø: there is no room for one at a 20 mm pitch.*Use a larger pitch, or turn off magnet pockets\./],
+ ['#cn=puzzle&mg=1&pi=36', 'magnetD', 'errMagnet', 6,
+ /Magnet Ø: there is no room for one at a 36 mm pitch — .* the notches the puzzle tabs fit into\. Use a larger pitch, or turn off magnet pockets\./]])
test(`${hash}: no room at all is a check on the design, not a field nothing satisfies`,
async ({ page }) => {
const errors = await openAt(page, hash);