mirror of
https://github.com/gittrahan/support-fins.git
synced 2026-10-19 02:10:52 -05:00
sway: give each auto brace a fin record so the per-fin filter keeps it
Per-fin removal (#15) makes the Auto view draw and export only the triangles a built.fins record claims. Sway braces were appended to built.triangles with no record, so after rebasing onto main they were counted in the readout but never shown or exported. Each brace now carries its triRange and a kind:'sway' record, which also makes it removable like any other Auto fin.
This commit is contained in:
1 parent
e619cf54ed
commit
859d7c89e8
3 files changed
+32
-3
No files matched your search
@@ -172,3 +172,17 @@ Deno.test('sway: auto never stands two braces into each other', () => {
|
||||
assert(s.count >= 2, `expected braces, got ${s.count}`);
|
||||
assert(isClosed(s.triangles), 'not closed');
|
||||
});
|
||||
|
||||
Deno.test('sway: auto braces carry fin records, so the per-fin filter keeps them', () => {
|
||||
// The Auto view draws and exports only triangles some built.fins record claims
|
||||
// (per-fin removal). A brace appended without a record vanished from both.
|
||||
const { topo, res } = post(150);
|
||||
const b = fins.buildFins(topo, res, ID, { mode: 'auto', bedPad: true, tines: true,
|
||||
layerHeight: LAYER, sway: { on: true } });
|
||||
const recs = b.fins.filter((f) => f.kind === 'sway');
|
||||
assert(recs.length === b.sway.count && recs.length > 0, `${recs.length} sway records for ${b.sway.count} braces`);
|
||||
const claimed = new Set();
|
||||
for (const f of b.fins) for (const [lo, hi] of f.triRanges) for (let t = lo; t < hi; t++) claimed.add(t);
|
||||
assert(claimed.size === b.triangles.length, `${b.triangles.length - claimed.size} vertices claimed by no fin`);
|
||||
assert(new Set(b.fins.map((f) => f.id)).size === b.fins.length, 'fin ids collide');
|
||||
});
|
||||
+13
@@ -1314,9 +1314,22 @@ export function buildFins(topo, result, rot, opts = {}) {
|
||||
if (!opts.sway?.on) return built;
|
||||
const sw = buildSwayBraces(topo, result, rot,
|
||||
{ ...opts.sway, tines: opts.tines, layerHeight: opts.layerHeight });
|
||||
// Each brace also gets a fin record: the Auto view draws and exports only the
|
||||
// triangles some record claims (per-fin removal), so an unrecorded brace would
|
||||
// be counted in the readout but never shown or written out.
|
||||
const base = built.triangles.length;
|
||||
const fins = built.fins ?? [];
|
||||
let id = fins.reduce((m, f) => Math.max(m, (f.id ?? -1) + 1), fins.length);
|
||||
const braces = sw.ribs.map((r) => ({
|
||||
height: r.height, length: r.depth, tines: r.tines, rows: 0, stilt: 0, lean: 0, bearing: 0, site: null,
|
||||
id: id++, kind: 'sway',
|
||||
triRanges: [[r.triRange[0] + base, r.triRange[1] + base]],
|
||||
line: r.foot, span: r.depth,
|
||||
}));
|
||||
return {
|
||||
...built,
|
||||
triangles: [...built.triangles, ...sw.triangles],
|
||||
fins: [...fins, ...braces],
|
||||
sway: { count: sw.count, tines: sw.tines, skipped: sw.skipped, reason: sw.reason },
|
||||
};
|
||||
}
|
||||
|
||||
+5
-3
@@ -431,8 +431,9 @@ function columnsFor(p) {
|
||||
* different ways so it is held in both directions (FIN-SPEC's "two fins,
|
||||
* opposite sides", extended to both axes of a tall part).
|
||||
*
|
||||
* Returns { triangles, count, tines, skipped, reason } -- `reason` set when
|
||||
* nothing was placed, so the readout can say why.
|
||||
* Returns { triangles, count, tines, skipped, ribs, reason } -- `reason` set when
|
||||
* nothing was placed, so the readout can say why. Each rib carries `triRange`,
|
||||
* its vertex range into `triangles`, so the UI can remove one brace by itself.
|
||||
*/
|
||||
export function buildSwayBraces(topo, result, rot, opts = {}) {
|
||||
const none = (reason) => ({ triangles: [], count: 0, tines: 0, skipped: 0, reason });
|
||||
@@ -473,12 +474,13 @@ export function buildSwayBraces(topo, result, rot, opts = {}) {
|
||||
}
|
||||
if (!placed) { skipped++; continue; }
|
||||
ribs.push(placed);
|
||||
placed.triRange = [out.length, out.length + placed.tris.length];
|
||||
for (const v of placed.tris) out.push(v);
|
||||
tines += placed.tines;
|
||||
}
|
||||
}
|
||||
return {
|
||||
triangles: out, count: ribs.length, tines, skipped,
|
||||
triangles: out, count: ribs.length, tines, skipped, ribs,
|
||||
reason: ribs.length ? null : 'the upright sides are blocked by other parts of the model in this pose',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user