Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 74 additions & 10 deletions bins/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ <h2 id="drawersTitle">Your drawers</h2>
instrument, not a correctness one, and it was choosing the worse number. */
const VTOL = 2e-3;

function healCsgSeams(polys) {
function healCsgSeams(polys, again) {
if (!polys.length) return polys;

/* ---- one vertex table for the whole soup, bucketed as it is built ----
Expand Down Expand Up @@ -1908,16 +1908,18 @@ <h2 id="drawersTitle">Your drawers</h2>
*
* Inserting can expose a further T-junction on a longer edge, hence the loop. Two
* passes is the most anything here has needed; the cap is headroom, and it THROWS if
* it is ever reached with work still to do rather than quietly returning a mesh with
* holes in it. Silent partial success is the failure this project keeps rediscovering
* — earTriangulate does it, and it shipped bins with 218 boundary edges.
* it is ever reached with work still to do (after the one more go described where it
* is reached) rather than quietly returning a mesh with holes in it. Silent partial
* success is the failure this project keeps rediscovering — earTriangulate does it,
* and it shipped bins with 218 boundary edges.
*
* The distance tolerance is VTOL and not something tighter: the collapse above may
* just have moved a vertex that far, and a weld that cannot reach it would leave the
* T-junction it was meant to close. */
const PASSES = 6;
let pass = 0;
let pass = 0, put = []; // the points this pass put into edges, and the edges' ends
for (; pass < PASSES; pass++) {
put = [];
/* Count polygon edges, not triangle edges — a fan's diagonals always pair up inside
the fan, so the two counts differ only by matched pairs. */
const use = new Map();
Expand Down Expand Up @@ -1976,15 +1978,72 @@ <h2 id="drawersTitle">Your drawers</h2>
}
if (!hits.length) continue;
hits.sort((x, y) => x[0] - y[0]);
for (const [, q] of hits) grown.push(q);
for (const [, q] of hits) { grown.push(q); put.push(q); }
put.push(ia, ib);
touched = true;
}
if (!touched) continue;
faces[fi] = grown; dirty[fi] = true; changed = true;
}
if (!changed) break;
}
if (pass === PASSES) throw new Error('healCsgSeams: T-junctions still appearing after ' + PASSES + ' passes');
/* Out of passes with the same few points still going into each other's edges. Three cut
lines that cross a face within a couple of microns of one point leave a triangle a
couple of microns on a side there. Each corner is just over VTOL from the other two,
so the collapse keeps all three, and each is within VTOL of the line through the other
two, so this loop puts one corner into the edge between the others, then a second
corner back into the edge that made, and so on for as many passes as it is given.
That was #76, a dovetail plate at 39.07 mm with a 2.34 mm counterbore: two facets of
the socket's sloped wall at the cell's corner, carried down from 5.3 mm by the cell's
tree, cross the counterbore's ceiling 2 microns from an edge of the ceiling's own, and
40 passes do not settle it any more than 6 do.

At that size the three corners are one point, and the collapse would have said so
had they been a hair closer: it already makes one point of two that are each within
VTOL of a third, up to two VTOL apart. So the points the last pass was still putting
in, and the ends of the edges it put them in, that lie within two VTOL of each other
become one; every vertex of the input that collapsed onto one of them goes with it;
and the repair runs once more from the start. Only here: a soup that settles inside
the passes never comes this way and is repaired exactly as before. That is nearly
every soup, but not every one. None of 1,100 random plates of every joint and mount
ran out; the turned cutters of a cell cut again do on a few engine-only cells (see
the fastener cut in buildPiece), and so does a jigsaw plate at 41.24 mm with magnets
from above and a 3.126 mm counterbore, on the first cut of both its pieces.

The second run is kept only if it comes out closed, and that jigsaw plate is why.
The merge lets its repair settle, but open, and returned that was 55 bad edges on
each piece with Download on, where before the same pieces failed to build and the
page said so; with a 2.264 mm magnet the cut was open by four edges and the piece
came out closed but folded. So a second run that does not settle throws, as does one
that settles open, or one with nothing close enough to merge. Faces it turned over
are no reason to throw: #76 with an 8.3 mm head turns six and builds watertight,
every shell facing outwards. */
if (pass === PASSES) {
if (!again) {
const ids = [...new Set(put)], up = new Map(ids.map((i) => [i, i]));
const top = (i) => { while (up.get(i) !== i) i = up.get(i); return i; };
for (let x = 0; x < ids.length; x++)
for (let y = x + 1; y < ids.length; y++) {
const v = verts[ids[x]], w = verts[ids[y]];
if (Math.hypot(v[0] - w[0], v[1] - w[1], v[2] - w[2]) > 2 * VTOL) continue;
const ra = top(ids[x]), rb = top(ids[y]);
if (ra !== rb) up.set(ra, rb);
}
const size = new Map();
for (const i of ids) size.set(top(i), (size.get(top(i)) || 0) + 1);
const onto = new Map(); // an input vertex's id -> where it goes
for (let i = 0; i < verts.length; i++) {
const r = find(i);
if (up.has(r) && size.get(top(r)) > 1 && top(r) !== i) onto.set(i, verts[top(r)]);
}
if (onto.size) {
const res = healCsgSeams(polys.map((p) => ({ verts: p.verts.map((v) => onto.get(idOf(v)) || v),
plane: p.plane })), true);
if (!res.open) return res; // open, it fails as it did before the merge
}
}
throw new Error('healCsgSeams: T-junctions still appearing after ' + PASSES + ' passes');
}

/* Welding creates the other kind of fold. A sliver triangle D-C-B whose corners are
nearly collinear really does have its third corner sitting on the opposite edge, so
Expand Down Expand Up @@ -5155,9 +5214,14 @@ <h2 id="drawersTitle">Your drawers</h2>
screw head to sit against; a nudge moves every plane off the crossing that lost
the sliver. The first closed result is
kept; a cell that comes out closed first time, which is nearly every one, is
built exactly as before. A try that throws (healCsgSeams' T-junction pass limit,
which the turned cutters reach on a few engine-only cells) is passed over and
the first cut stands, open as it was rather than a failed build.
built exactly as before. A try that throws is passed over and the first cut
stands, open as it was rather than a failed build. The turned cutters reach
healCsgSeams' T-junction pass limit on a few engine-only cells, and they threw
there until #76; now the repair makes one point of the few it was still
putting into edges and runs once more, so such a try can come back closed and
be kept where the nudged one after it used to be (the audit's "a retry that
throws": every piece's bytes change, and every piece is still watertight). One
whose second run comes out open still throws, and is passed over.

Only a cell open by a sliver or a few is cut again, at most 24 edges: six at
each of its four pockets. Cells cut again have been open by anything from 1 to
Expand Down
15 changes: 15 additions & 0 deletions docs/ENGINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -842,3 +842,18 @@ currently installed):
a fraction of a micron from a corner and read, to `checkManifold`'s thousandths, as the
face's own edges a second time (a puzzle key in the wall from beneath with magnets from
above at 42 mm: four edges used four times). Such a face goes out as it is.
- **A weld that never settles is three points, not a loop.** Three cut lines that cross a
face within a couple of microns of one point leave a triangle a couple of microns on a
side there. Each corner is just over `VTOL` from the other two, so the collapse keeps all
three, and each is within `VTOL` of the line through the other two, so the T-junction
pass puts them into each other's edges in turn and never finishes: it threw at six
passes, and forty do no better. When the passes run out, `healCsgSeams` makes one point
of those the last pass was still putting in that lie within two `VTOL` of each other,
and repairs once more from the start; a soup that settles inside the passes never comes
that way. #76 was this: a dovetail plate at 39.07 mm with a 3 mm shank and a 2.34 mm
counterbore, where two facets of the socket's sloped wall at the cell's corner cross the
counterbore's ceiling 2 microns from an edge of its own. Every piece with a seam on its
left failed to build, for heads from 7.3 mm to the cap; 2.339 and 2.341 mm built. The
second run is kept only if it comes out closed: a jigsaw plate at 41.24 mm with magnets
from above settles open after the merge, and fails to build as it did before rather
than going out with holes.
99 changes: 88 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ <h2 id="drawersTitle">Your drawers</h2>
instrument, not a correctness one, and it was choosing the worse number. */
const VTOL = 2e-3;

function healCsgSeams(polys) {
function healCsgSeams(polys, again) {
if (!polys.length) return polys;

/* ---- one vertex table for the whole soup, bucketed as it is built ----
Expand Down Expand Up @@ -1695,16 +1695,18 @@ <h2 id="drawersTitle">Your drawers</h2>
*
* Inserting can expose a further T-junction on a longer edge, hence the loop. Two
* passes is the most anything here has needed; the cap is headroom, and it THROWS if
* it is ever reached with work still to do rather than quietly returning a mesh with
* holes in it. Silent partial success is the failure this project keeps rediscovering
* — earTriangulate does it, and it shipped bins with 218 boundary edges.
* it is ever reached with work still to do (after the one more go described where it
* is reached) rather than quietly returning a mesh with holes in it. Silent partial
* success is the failure this project keeps rediscovering — earTriangulate does it,
* and it shipped bins with 218 boundary edges.
*
* The distance tolerance is VTOL and not something tighter: the collapse above may
* just have moved a vertex that far, and a weld that cannot reach it would leave the
* T-junction it was meant to close. */
const PASSES = 6;
let pass = 0;
let pass = 0, put = []; // the points this pass put into edges, and the edges' ends
for (; pass < PASSES; pass++) {
put = [];
/* Count polygon edges, not triangle edges — a fan's diagonals always pair up inside
the fan, so the two counts differ only by matched pairs. */
const use = new Map();
Expand Down Expand Up @@ -1763,15 +1765,72 @@ <h2 id="drawersTitle">Your drawers</h2>
}
if (!hits.length) continue;
hits.sort((x, y) => x[0] - y[0]);
for (const [, q] of hits) grown.push(q);
for (const [, q] of hits) { grown.push(q); put.push(q); }
put.push(ia, ib);
touched = true;
}
if (!touched) continue;
faces[fi] = grown; dirty[fi] = true; changed = true;
}
if (!changed) break;
}
if (pass === PASSES) throw new Error('healCsgSeams: T-junctions still appearing after ' + PASSES + ' passes');
/* Out of passes with the same few points still going into each other's edges. Three cut
lines that cross a face within a couple of microns of one point leave a triangle a
couple of microns on a side there. Each corner is just over VTOL from the other two,
so the collapse keeps all three, and each is within VTOL of the line through the other
two, so this loop puts one corner into the edge between the others, then a second
corner back into the edge that made, and so on for as many passes as it is given.
That was #76, a dovetail plate at 39.07 mm with a 2.34 mm counterbore: two facets of
the socket's sloped wall at the cell's corner, carried down from 5.3 mm by the cell's
tree, cross the counterbore's ceiling 2 microns from an edge of the ceiling's own, and
40 passes do not settle it any more than 6 do.

At that size the three corners are one point, and the collapse would have said so
had they been a hair closer: it already makes one point of two that are each within
VTOL of a third, up to two VTOL apart. So the points the last pass was still putting
in, and the ends of the edges it put them in, that lie within two VTOL of each other
become one; every vertex of the input that collapsed onto one of them goes with it;
and the repair runs once more from the start. Only here: a soup that settles inside
the passes never comes this way and is repaired exactly as before. That is nearly
every soup, but not every one. None of 1,100 random plates of every joint and mount
ran out; the turned cutters of a cell cut again do on a few engine-only cells (see
the fastener cut in buildPiece), and so does a jigsaw plate at 41.24 mm with magnets
from above and a 3.126 mm counterbore, on the first cut of both its pieces.

The second run is kept only if it comes out closed, and that jigsaw plate is why.
The merge lets its repair settle, but open, and returned that was 55 bad edges on
each piece with Download on, where before the same pieces failed to build and the
page said so; with a 2.264 mm magnet the cut was open by four edges and the piece
came out closed but folded. So a second run that does not settle throws, as does one
that settles open, or one with nothing close enough to merge. Faces it turned over
are no reason to throw: #76 with an 8.3 mm head turns six and builds watertight,
every shell facing outwards. */
if (pass === PASSES) {
if (!again) {
const ids = [...new Set(put)], up = new Map(ids.map((i) => [i, i]));
const top = (i) => { while (up.get(i) !== i) i = up.get(i); return i; };
for (let x = 0; x < ids.length; x++)
for (let y = x + 1; y < ids.length; y++) {
const v = verts[ids[x]], w = verts[ids[y]];
if (Math.hypot(v[0] - w[0], v[1] - w[1], v[2] - w[2]) > 2 * VTOL) continue;
const ra = top(ids[x]), rb = top(ids[y]);
if (ra !== rb) up.set(ra, rb);
}
const size = new Map();
for (const i of ids) size.set(top(i), (size.get(top(i)) || 0) + 1);
const onto = new Map(); // an input vertex's id -> where it goes
for (let i = 0; i < verts.length; i++) {
const r = find(i);
if (up.has(r) && size.get(top(r)) > 1 && top(r) !== i) onto.set(i, verts[top(r)]);
}
if (onto.size) {
const res = healCsgSeams(polys.map((p) => ({ verts: p.verts.map((v) => onto.get(idOf(v)) || v),
plane: p.plane })), true);
if (!res.open) return res; // open, it fails as it did before the merge
}
}
throw new Error('healCsgSeams: T-junctions still appearing after ' + PASSES + ' passes');
}

/* Welding creates the other kind of fold. A sliver triangle D-C-B whose corners are
nearly collinear really does have its third corner sitting on the opposite edge, so
Expand Down Expand Up @@ -4942,9 +5001,14 @@ <h2 id="drawersTitle">Your drawers</h2>
screw head to sit against; a nudge moves every plane off the crossing that lost
the sliver. The first closed result is
kept; a cell that comes out closed first time, which is nearly every one, is
built exactly as before. A try that throws (healCsgSeams' T-junction pass limit,
which the turned cutters reach on a few engine-only cells) is passed over and
the first cut stands, open as it was rather than a failed build.
built exactly as before. A try that throws is passed over and the first cut
stands, open as it was rather than a failed build. The turned cutters reach
healCsgSeams' T-junction pass limit on a few engine-only cells, and they threw
there until #76; now the repair makes one point of the few it was still
putting into edges and runs once more, so such a try can come back closed and
be kept where the nudged one after it used to be (the audit's "a retry that
throws": every piece's bytes change, and every piece is still watertight). One
whose second run comes out open still throws, and is passed over.

Only a cell open by a sliver or a few is cut again, at most 24 edges: six at
each of its four pockets. Cells cut again have been open by anything from 1 to
Expand Down Expand Up @@ -7993,6 +8057,19 @@ <h2 id="drawersTitle">Your drawers</h2>
// nothing below can — every check after this one is reasoning about the clamped value
for (const msg of fieldErrors.values()) out.push({ err: true, stop: true, t: msg });
for (const msg of noRoom.values()) out.push({ err: true, stop: true, t: msg });
/* A piece the engine threw on. runBuild stops there, and the piece table, the preview and
the Download button's tooltip said so, but the checks, which are where a design is read
for what is wrong with it, said nothing: #76's B1 left Download off with no reason
under the cut map. Drawn as an error but not flagged `err`, which would stop the next
build as well, and the next build, on any change, is what clears it. It says Download
is off, not that nothing can be downloaded: the pieces built before it keep their own
STL buttons in the piece table. And it promises no size that gets past it: the 41.24 mm
jigsaw plate in plate-audit.js fails with a 7.504 mm head and builds with holes at
7.502 mm, on main as well. */
if (buildFailed)
out.push({ failed: true, t: `Piece ${buildFailed} could not be built, so the build stopped ` +
'there and Download is off. That is a fault in this tool, not in the design; moving a cut ' +
'through the piece or picking another joint may get past it.' });
if (layout.nx * layout.ny > MAX_CELLS)
out.push({ err: true, stop: true, t: `A ${layout.nx} × ${layout.ny} grid is ` +
`${layout.nx * layout.ny} cells, past the ${MAX_CELLS} this tool will build in one ` +
Expand Down Expand Up @@ -8144,7 +8221,7 @@ <h2 id="drawersTitle">Your drawers</h2>
const hasErrors = () => warningsList().some(w => w.err);
function drawWarnings() {
const ws = warningsList();
$('warnings').innerHTML = ws.map(w => `<div class="w${w.err ? ' err' : ''}">${w.t}</div>`).join('');
$('warnings').innerHTML = ws.map(w => `<div class="w${w.err || w.failed ? ' err' : ''}">${w.t}</div>`).join('');
/* The Download button stops being the primary action when there is nothing behind it.
It was enabled through all of this: type -50 into the drawer width and the page
said "resolve the errors above to generate" and offered you the download in the
Expand Down
Loading
Loading