@floless/app 0.131.1 → 0.132.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/floless-server.cjs +2374 -1901
  2. package/dist/schemas/steel.model.v2.schema.json +3 -1
  3. package/dist/skills/floless-app-onboarding/SKILL.md +12 -2
  4. package/dist/skills/floless-app-queue/SKILL.md +2 -2
  5. package/dist/web/app.css +359 -0
  6. package/dist/web/app.js +22 -0
  7. package/dist/web/aware.js +121 -13
  8. package/dist/web/commands-filter.js +157 -0
  9. package/dist/web/commands-shell.js +1316 -0
  10. package/dist/web/commands-steel.js +1829 -0
  11. package/dist/web/commands-vector.js +154 -0
  12. package/dist/web/commands-vector3d.js +96 -0
  13. package/dist/web/commands.js +316 -0
  14. package/dist/web/grid-core.js +124 -23
  15. package/dist/web/index.html +269 -164
  16. package/dist/web/instructor-reporter.js +201 -0
  17. package/dist/web/instructor.js +1178 -0
  18. package/dist/web/reference-geometry-worker.js +194 -0
  19. package/dist/web/steel-3d-core.js +486 -107
  20. package/dist/web/steel-3d-view.js +847 -204
  21. package/dist/web/steel-canvas-guidance.js +7 -4
  22. package/dist/web/steel-editor.html +1620 -1799
  23. package/dist/web/steel-filter-core.js +13 -5
  24. package/dist/web/steel-filter.html +36 -22
  25. package/dist/web/steel-model-adapter.js +17 -22
  26. package/dist/web/steel-model-commands.js +23 -10
  27. package/dist/web/steel-model-v2-client-validation.js +20 -3
  28. package/dist/web/steel-model-v2-commands.js +91 -3
  29. package/dist/web/steel-model-v2-projection.js +4 -5
  30. package/dist/web/steel-plan-transform.js +4 -8
  31. package/dist/web/steel-split-view.js +33 -0
  32. package/dist/web/vector-3d.html +19 -7
  33. package/dist/web/vector-editor.html +21 -8
  34. package/dist/web/workspaces.js +12 -25
  35. package/package.json +10 -1
@@ -1,9 +1,8 @@
1
1
  /*
2
2
  * steel-3d-core.js — PURE, framework-free core for the steel 3D editor (no Three.js, no DOM, no
3
3
  * window). Unit-tested in node (server/steel-3d-core.test.ts) AND loaded by web/steel-3d-view.js.
4
- * This is the extraction-ready unit: the generic snap engine + the typed-candidate model are what
5
- * later lift into AWARE viewer-3d; only `snapCandidates` (beam top-flange centerline, column
6
- * plan-center) is steel-specific.
4
+ * This is the extraction-ready unit: the generic snap engine and typed-candidate model can later
5
+ * lift into AWARE viewer-3d, while the native model geometry remains Steel-specific.
7
6
  *
8
7
  * Coordinate map MUST match server/contract-to-scene.ts (the bake) so editing-space == render-space:
9
8
  * scene is mm, Z-up. mmX = dispX·k, mmY = -dispY·k (k = FT_TO_MM / pt_per_ft, Y flipped),
@@ -215,6 +214,140 @@ export function dispToMm(pt, ptPerFt) { const k = mmPerPx(ptPerFt); return [nz(p
215
214
  /** scene mm point [x,y,…] → display-space wp [px,py] (inverse of dispToMm). */
216
215
  export function planPointToWp(p, ptPerFt) { const k = mmPerPx(ptPerFt); return [nz(p[0] / k), nz(-p[1] / k)]; }
217
216
 
217
+ /**
218
+ * The section outline itself: local points centred on the origin, x = width, y = depth, closed, plus an
219
+ * optional inner path for a hollow section. THE one outline — the 2D plan and the 3D extrusion both build
220
+ * from this, so a section whose real thickness is known cannot be given two different OUTLINES.
221
+ *
222
+ * That qualifier is exact, not hedging: the ESTIMATE fallback below has absolute floors (6, 5, 4) in the
223
+ * CALLER's unit — millimetres in 3D, sheet pixels in 2D — so a section with no thickness source anywhere
224
+ * (a tee, an imported UC) still estimates differently in the two views. Removing that would mean giving the
225
+ * floors a shared unit, which is a legibility decision, not this function's to make.
226
+ *
227
+ * They used to be hand-kept twins, and that is exactly how #647 happened (a bare `M` in the I-branch made
228
+ * the `MC` branch unreachable, so every MC channel extruded as a wide flange while the plan drew a channel).
229
+ * The twins also drifted on THICKNESS, which is worse because it looks fine: the 3D branch learned to read
230
+ * the real web/flange/leg off the AISC table, the 2D branch never did, and went on estimating them off the
231
+ * envelope. A W12X65 plan footprint carried a 1.2" web against a real 0.39", and an L4X4X3/8 a 0.72" leg
232
+ * against a real 0.375" — a plan drawing showing a member about twice as thick as the one being fabricated,
233
+ * on a tool whose whole job is detailing.
234
+ *
235
+ * `thk` is `{tw, tf, t}` in the SAME UNIT as `w`/`d` — mm in 3D, sheet px in 2D — because the unit belongs
236
+ * to the caller's space, not to this function. Anything missing or unusable falls back to the estimate that
237
+ * has always been here, which is what still lets an untabulated or imported section be drawn at all.
238
+ *
239
+ * A **ROUND** section additionally returns `round` and its exact `r` — see that branch for why the radius
240
+ * cannot be recovered from the points.
241
+ *
242
+ * @param {string} kind a `sectionKindOf` result, or 'ROUND'
243
+ * @param {number} w
244
+ * @param {number} d
245
+ * @param {{tw?:number|null,tf?:number|null,t?:number|null}|null|undefined} thk
246
+ * @returns {{outer:[number,number][], hole?:[number,number][]|null, round?:boolean, r?:number}}
247
+ */
248
+ export function sectionOutlinePts(kind, w, d, thk) {
249
+ const hw = w / 2, hd = d / 2;
250
+ // A thickness only counts if it FITS: a metric designation's token parsed as inches would otherwise draw
251
+ // a leg thicker than the whole angle. Same test the 3D renderer has always applied (`realThk`).
252
+ const real = (key, half) => {
253
+ const t = thk && typeof thk[key] === 'number' ? thk[key] : null;
254
+ return t != null && t > 0 && t < 2 * half ? t : null;
255
+ };
256
+ if (kind === 'I') {
257
+ // The `Math.min(…*0.5, …)` clamps are not decoration — the floors (6, 5) are FLAT minimums so an
258
+ // ESTIMATED section still reads at small zoom, and on a small section at a coarse scale the floor
259
+ // exceeds the section itself. Unclamped, the inner corner runs past the outline and the drawn footprint
260
+ // comes out BIGGER than the member: an L4X4X3/8 at pt_per_ft 12 measured 5"x5" instead of 4"x4".
261
+ const tf = real('tf', hd) ?? Math.min(d * 0.5, Math.max(d * 0.10, 6));
262
+ const tw = real('tw', hw) ?? Math.min(w * 0.5, Math.max(w * 0.10, 5));
263
+ return { outer: [[-hw, -hd], [hw, -hd], [hw, -hd + tf], [tw / 2, -hd + tf], [tw / 2, hd - tf], [hw, hd - tf],
264
+ [hw, hd], [-hw, hd], [-hw, hd - tf], [-tw / 2, hd - tf], [-tw / 2, -hd + tf], [-hw, -hd + tf]] };
265
+ }
266
+ if (kind === 'C') {
267
+ const tf = real('tf', hd) ?? Math.min(d * 0.5, Math.max(d * 0.10, 5));
268
+ const tw = real('tw', hw) ?? Math.min(w * 0.5, Math.max(w * 0.12, 5));
269
+ return { outer: [[-hw, -hd], [hw, -hd], [hw, -hd + tf], [-hw + tw, -hd + tf], [-hw + tw, hd - tf],
270
+ [hw, hd - tf], [hw, hd], [-hw, hd]] };
271
+ }
272
+ if (kind === 'L') {
273
+ const mn = Math.min(w, d);
274
+ const t = real('t', Math.min(hw, hd)) ?? Math.min(mn * 0.5, Math.max(mn * 0.18, 5));
275
+ return { outer: [[-hw, -hd], [hw, -hd], [hw, -hd + t], [-hw + t, -hd + t], [-hw + t, hd], [-hw, hd]] };
276
+ }
277
+ const outer = [[-hw, -hd], [hw, -hd], [hw, hd], [-hw, hd]];
278
+ if (kind === 'TUBE') {
279
+ const t = real('t', Math.min(hw, hd)) ?? Math.max(Math.min(w, d) * 0.12, 4);
280
+ // The 2D plan draws a tube SOLID (no hole) and always has; 3D punches the wall. Callers choose.
281
+ return { outer, hole: [[-hw + t, -hd + t], [hw - t, -hd + t], [hw - t, hd - t], [-hw + t, hd - t]] };
282
+ }
283
+ if (kind === 'ROUND') {
284
+ // A round section is a CIRCLE, not the w × d rectangle those two numbers imply. `profileDims` squares a
285
+ // pipe into `w = d = OD`, and every consumer that took the rectangle at face value drew and measured the
286
+ // square: the 3D solid put a rolled PIPE4STD's flush face 23.7 mm off its reference line, and the
287
+ // base-plate weld traced square corners around a circular column, while the IFC/Tekla writers built the
288
+ // real circle all along.
289
+ //
290
+ // `r` is returned ALONGSIDE the points and is not redundant: the polygon is INSCRIBED, so its widest
291
+ // point between two vertices is `r·cos(π/ROUND_SEGMENTS)`. Measuring the points would put a pipe's flush
292
+ // face a fraction inside its own steel, silently, at exactly the rolls where no vertex lines up with the
293
+ // axis being measured. `sectionExtents` and `rolledExtent` read `r`; anything that DRAWS reads the points.
294
+ //
295
+ // `kind` cannot be derived from the designation: `sectionKindOf` matches a literal prefix and answers
296
+ // TUBE for `HSS6X6X3/8` (rectangular) and `HSS6.625X0.280` (round) alike — only the numerics separate
297
+ // them, which is why callers pass 'ROUND' in from `profileDims`/`profileDimsIn`'s own `round`.
298
+ const r = Math.min(hw, hd);
299
+ const t = real('t', r) ?? Math.max(r * 0.12, 4);
300
+ const ring = (rad) => {
301
+ const pts = [];
302
+ for (let i = 0; i < ROUND_SEGMENTS; i++) {
303
+ const a = (i / ROUND_SEGMENTS) * Math.PI * 2;
304
+ pts.push([rad * Math.cos(a), rad * Math.sin(a)]);
305
+ }
306
+ return pts;
307
+ };
308
+ // Hollow like a TUBE, and for the same reason the tube branch gives: 3D punches the bore, the 2D plan
309
+ // draws it solid, and each caller takes what it needs.
310
+ return { outer: ring(r), hole: r - t > 0 ? ring(r - t) : null, round: true, r };
311
+ }
312
+ return { outer }; // BOX / unclassified → rectangle
313
+ }
314
+
315
+ /** How many segments approximate a circle for the consumers that need a polygon. */
316
+ export const ROUND_SEGMENTS = 48;
317
+
318
+ /**
319
+ * Place a section outline (local px, centred on the origin, section x = width / y = depth) into a plan
320
+ * sheet's display px, for a member rolled `rotDeg`.
321
+ *
322
+ * `rot` is a WORLD rotation — right-handed about world +Z, which is what the 3D renderer's `orientMember`
323
+ * applies on every branch and what the bake passes through unaltered (`contract-to-scene.ts`: v2 endpoints
324
+ * are already right-handed world mm, so `rot` is NOT negated there). Sheet px is not that space: it is
325
+ * world turned by MINUS the sheet's registration angle and then Y-FLIPPED (`worldToSheetPx` in
326
+ * steel-plan-transform.js — the same flip `planPointToWp` above does). Rotating in a reflected space turns
327
+ * the other way AND carries the outline's own reflection with it, which is how the plan drew every section
328
+ * as the mirror of the 3D solid and the exported geometry — a rolled column appeared to turn the wrong way,
329
+ * and an angle came out mirrored even at rot 0, where there is no rotation to blame. Registration was
330
+ * ignored on top of that, so a rotated sheet turned the footprint by its registration angle as well.
331
+ *
332
+ * So: rotate by `rot - sheetRotRad` (the registration part commutes out of the roll and only re-aims the
333
+ * section's own axes), then divide by `fitScale` and flip Y into px. Offsets only — the caller adds the
334
+ * member's centre.
335
+ *
336
+ * `fitScale` is the THIRD thing `worldToSheetPx` does and the easiest to forget, because it is 1 on every
337
+ * well-registered sheet: it is the ratio between the distance the sheet's two controls actually span in
338
+ * world and the distance their pixels imply at the sheet's stated `pt_per_ft`. A sheet registered at twice
339
+ * its declared scale carries every work point at half the pixels — and an outline sized from `pt_per_ft`
340
+ * alone, as this one is, then draws the section at twice the size of the member it belongs to. (Found by
341
+ * adversarial review; the first cut of this function dismissed it as a pre-existing sizing question, which
342
+ * it was — right up until this became the one place that claims to map world into sheet px.)
343
+ */
344
+ export function sectionOutlinePx(pts, rotDeg, sheetRotRad = 0, fitScale = 1) {
345
+ const a = (Number(rotDeg) || 0) * Math.PI / 180 - (Number(sheetRotRad) || 0);
346
+ const k = Number(fitScale) > 0 && Number.isFinite(Number(fitScale)) ? Number(fitScale) : 1;
347
+ const cs = Math.cos(a) / k, sn = Math.sin(a) / k;
348
+ return pts.map(([x, y]) => [nz(x * cs - y * sn), nz(-(x * sn + y * cs))]);
349
+ }
350
+
218
351
  /**
219
352
  * The px→ft scale and default T.O.S of the plan that OWNS a member, resolved from the SAME per-plan
220
353
  * list that feeds 3D snap candidates (`api.membersByPlan()`).
@@ -315,55 +448,9 @@ function segXY(a, b, c, d) {
315
448
  return [a[0] + rx * t, a[1] + ry * t];
316
449
  }
317
450
 
318
- /**
319
- * Snap targets from the other members (the dragged one excluded). Beam → its top-flange centerline
320
- * (the work-line at T.O.S) + endpoint vertices + a midpoint. Column → a vertical axis at its plan
321
- * point + endpoint vertices. Plus member-member centerline INTERSECTIONS (Tekla-standard). Each
322
- * tagged `fromId`. Generic `grid-line` targets (from plan grids) plug in here too.
323
- */
324
- export function snapCandidates(members, ptPerFt, defaultTosMm, excludeId) {
325
- const out = [];
326
- const lines = []; // beam centerlines, for pairwise intersections
327
- for (const m of members || []) {
328
- if (!m || m.id === excludeId || !Array.isArray(m.wp) || m.wp.length < 2) continue;
329
- const { kind, line } = memberGeometry(m, ptPerFt, defaultTosMm);
330
- const [p0, p1] = line;
331
- if (kind === 'column') { out.push({ type: 'vertical-axis', p: p0, fromId: m.id }); }
332
- else {
333
- out.push({ type: 'centerline', a: p0, b: p1, fromId: m.id });
334
- out.push({ type: 'midpoint', p: [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2, (p0[2] + p1[2]) / 2], fromId: m.id });
335
- lines.push({ id: m.id, p0, p1 });
336
- }
337
- out.push({ type: 'vertex', p: p0, fromId: m.id });
338
- out.push({ type: 'vertex', p: p1, fromId: m.id });
339
- }
340
- for (let i = 0; i < lines.length; i++) {
341
- for (let j = i + 1; j < lines.length; j++) {
342
- const x = segXY(lines[i].p0, lines[i].p1, lines[j].p0, lines[j].p1);
343
- if (x) out.push({ type: 'intersection', p: [x[0], x[1], (lines[i].p0[2] + lines[j].p0[2]) / 2], fromIds: [lines[i].id, lines[j].id] });
344
- }
345
- }
346
- return out;
347
- }
348
-
349
- /**
350
- * Distinct elevation levels (mm, sorted) among the OTHER members' endpoints — the snap targets for a
351
- * vertical (Alt) drag, so a member can be raised/lowered onto another's T.O.S level. The caller turns
352
- * each level into a point candidate at the dragged member's plan X/Y and reuses snapPoint().
353
- */
354
- export function elevationLevels(members, ptPerFt, defaultTosMm, excludeId) {
355
- const set = new Set();
356
- for (const m of members || []) {
357
- if (!m || m.id === excludeId || !Array.isArray(m.wp) || m.wp.length < 2) continue;
358
- const { line } = memberGeometry(m, ptPerFt, defaultTosMm);
359
- set.add(Math.round(line[0][2])); set.add(Math.round(line[1][2]));
360
- }
361
- return [...set].sort((a, b) => a - b);
362
- }
363
-
364
451
  // Snap a raw elevation (mm) to the nearest level datum { z, label } within `tol`, returning the snapped
365
452
  // value + its source, or the raw value when nothing is in range. Nearest wins. Pure — backs the Mode B
366
- // column-base pick (the levels come from elevationLevels()). Malformed datums are skipped.
453
+ // column-base pick. Malformed datums are skipped.
367
454
  export function snapElevation(z, levels, tol) {
368
455
  let best = null, bestD = tol;
369
456
  for (const lv of levels || []) {
@@ -694,7 +781,7 @@ export function sanitizeDims3d(arr) {
694
781
  * 3D dimension geometry (pure). a,b are scene mm [x,y,z]. axis ∈ free|x|y|z.
695
782
  * free → the straight segment a→b (valueMm = full 3D distance); z → the world-Z (elevation)
696
783
  * component; x|y → the component along `axisDir` (a world unit direction from the active local
697
- * frame, normalized on read) when supplied & usable, else the world X/Y axis (legacy / global).
784
+ * frame, normalized on read) when supplied and usable, else the global world X/Y axis.
698
785
  * valueMm = that component's length. Returns the drawn endpoints, the midpoint (where the label
699
786
  * sits), and the measured length in mm.
700
787
  */
@@ -713,19 +800,13 @@ export function dominantAxis3d(a, b, axesMap) {
713
800
  return best;
714
801
  }
715
802
 
716
- // ---- steel.model/v2 foundation (model-level epic, units 2 + 5) — INACTIVE -------------------------
717
- // Pure primitives for the model-level contract. Nothing IN THIS SECTION is wired into the editor or the
718
- // 3D view: unit 2 ships the v2 contract inactive, so these exist to be unit-tested and consumed by
719
- // unit 3's migration preview and unit 5's read boundary. (The section is bounded — `dim3dGeom` below it
720
- // was appended later and IS live in the 3D view; keep new v2 primitives above it.) Kept here because
721
- // they are the same KIND of thing as the rest of this module (framework-free scene-space math,
722
- // node-tested from server/steel-3d-core.test.ts) and server code already imports web/*-core.js —
723
- // contract-to-scene.ts pulls in grid-core, and steel-model-read.ts pulls in knownZ/isUnknownElev from
724
- // right here, which is why unit 5's v2 primitives are SHARED from this file rather than mirrored.
803
+ // ---- steel.model/v2 model-space primitives -------------------------------------------------------
804
+ // Framework-free scene-space math shared by the editor and server consumers. Keeping it here avoids
805
+ // parallel coordinate implementations drifting between rendering, scoring, and export.
725
806
 
726
807
  /**
727
808
  * The pinned tolerances from epic §5.2b. These are CONTRACT SEMANTICS — they decide what displays,
728
- * merges, or blocks a migration — not implementation tuning. Revisit with data; never widen one to
809
+ * merges, or refuses inconsistent registration — not implementation tuning. Revisit with data; never widen one to
729
810
  * make a demo pass.
730
811
  *
731
812
  * The cut-plane quantum is the existing authoring quantum (grid-core's gridLevelKey rounds to 1/16").
@@ -897,8 +978,7 @@ export function registerSheet(input) {
897
978
  // difference between two sheets' grid strings leaves `residualMm` at zero by construction — a
898
979
  // similarity absorbs a uniform scale exactly — so induced displacement is the only guard there, and
899
980
  // relaxing it let one physical column land 8.3 mm apart when read on two sheets, past DEDUP_MM, and be
900
- // emitted TWICE with a clean `ok` and no reasons. The migration's per-axis extent collapse also cites
901
- // this bound by name and would have been silently invalidated with it.
981
+ // emitted twice with a clean `ok` and no reasons.
902
982
  const induced = (Math.abs(transform.rotationRad) + Math.abs(transform.scale - 1)) * extentMm;
903
983
  let verdict = 'ok';
904
984
  const report = (why) => { reasons.push(why); if (verdict === 'ok') verdict = 'report'; };
@@ -916,21 +996,15 @@ export function registerSheet(input) {
916
996
  }
917
997
 
918
998
  /**
919
- * A steel.model/v2 member's centreline in WORLD MM — the v2 sibling of `memberGeometry`, and unit 5 P5's
920
- * core primitive. Returns the SAME shape `{ kind, line:[[x,y,z],[x,y,z]] }`, so every consumer of the v1
921
- * function (the snap picker, the elevation snapper, the 3D view's overlays) works unchanged.
999
+ * A steel.model/v2 member's centreline in world mm. Returns the shared
1000
+ * `{ kind, line:[[x,y,z],[x,y,z]] }` geometry shape used by snapping and 3D overlays.
922
1001
  *
923
- * FOUR THINGS THE v1 SIBLING DOES THAT THIS MUST NOT — each one a silent wrong answer if copied:
1002
+ * Native model geometry has four non-negotiable rules:
924
1003
  *
925
1004
  * * NO px SCALE. v2 work points are world mm already (schema `$defs.workPoint`).
926
1005
  * * NO Y NEGATION. `contract-to-scene` flips display Y on the way in; v2 stores the flipped value.
927
- * * NO `default_tos` FALLBACK. v2 has no such field: migration MATERIALIZES v1's defaults, which is the
928
- * whole reason the `{known} | {unknown}` union exists (`$defs.elevation`).
929
- * * NO PLUMB. v1's column is a POINT SYMBOL — one plan point plus `col.bos`/`col.tos` — so the v1
930
- * function puts the top at the base's X/Y. A v2 column carries two REAL work points stored base→top,
931
- * and `contract-to-scene`'s v2 path says why in as many words: "a battered column keeps its lean
932
- * instead of being re-plumbed onto a single plan point the way v1's point-symbol column was". Copying
933
- * v1's line here would snap a leaning column's top onto its base and report it confidently.
1006
+ * * NO default elevation fallback. Unknown elevation remains unknown.
1007
+ * * NO PLUMB. A column carries two real work points stored base→top, so a battered column keeps its lean.
934
1008
  *
935
1009
  * `kind` follows the AUTHORED `role` and is never derived from geometry (epic §15.2: vertical braces and
936
1010
  * near-vertical members make "column = vertical" unsafe). An absent role is a beam, per the schema.
@@ -956,8 +1030,8 @@ export function memberGeometryV2(m) {
956
1030
  /**
957
1031
  * Resolve the selected-member length labels to finite world-space midpoint anchors.
958
1032
  *
959
- * The editor owns each label's text while the 3D view owns projection. Keeping the format-aware
960
- * geometry lookup injectable lets this one seam serve both v1 (`wp`) and v2 (`from`/`to`) members,
1033
+ * The editor owns each label's text while the 3D view owns projection. Keeping the native geometry
1034
+ * lookup injectable lets this seam consume canonical members without duplicating the adapter,
961
1035
  * and makes the exact production validation executable without loading Three.js in a unit test.
962
1036
  * The returned array stays index-aligned with `labels`; an unusable row is `null` so the DOM pool
963
1037
  * can hide that slot rather than accidentally pairing a later label with the wrong member.
@@ -985,54 +1059,43 @@ export function selectedLengthLabelAnchors(labels, members, geometryOf) {
985
1059
  }
986
1060
 
987
1061
  /**
988
- * Snap targets from v2 members — the v2 sibling of `snapCandidates`, emitting the identical record shapes
989
- * so `snapPoint`'s precedence table and `candidatePoint` need no v2 case.
990
- *
991
- * WHY THIS IS NOT `snapCandidates(members, 304.8, 0, excludeId)`. That nearly works — `mmPerPx(304.8)` is 1 —
992
- * and is wrong twice: it would still negate Y (v2 coordinates are already world), and it would still read
993
- * `m.wp`/`m.col`/`m.ends`, which a v2 member does not have. A v2 member routed through the v1 function
994
- * does not throw; it yields NaN candidates that snap silently to nowhere. Silence is the failure mode.
1062
+ * Snap targets from native members, emitting the record shapes consumed by `snapPoint`'s precedence table.
1063
+ * Coordinates are already world millimetres and member geometry comes from canonical `from`/`to` fields.
995
1064
  *
996
1065
  * THE CANDIDATE TYPE takes TWO conjuncts, and both matter: a member gets a `vertical-axis` (which
997
1066
  * `candidatePoint` reads as "lock plan X/Y, keep the dragged Z") only when it is an authored COLUMN
998
1067
  * **and** its plan footprint is a point. Everything else is a line and gets `centerline` + `midpoint`.
999
1068
  * The role half is not redundant — a role-less member with a coincident footprint (a vertical brace, a
1000
- * degenerate beam) is NOT given an axis, exactly as in v1, whose `memberGeometry` likewise reports
1001
- * `kind:'column'` only for an authored `role === 'column'`. Stated because the first draft of this
1069
+ * degenerate beam) is NOT given an axis. `memberGeometry` reports `kind:'column'` only for an authored
1070
+ * `role === 'column'`. Stated because the first draft of this
1002
1071
  * paragraph claimed footprint alone, and deleting the role conjunct left the whole file green.
1003
1072
  *
1004
1073
  * Equality of the footprint is exact rather than toleranced on purpose: the pinned `MODEL_V2_TOL` values
1005
1074
  * are contract semantics with stated meanings (de-dup candidacy, cut-plane inclusion), and borrowing one
1006
1075
  * here would be inventing a tolerance for a question neither answers. What makes exact equality SOUND is
1007
- * narrower than an earlier version of this comment claimed: migration transforms a column's two work
1008
- * points INDEPENDENTLY (`steel-model-migrate.ts` runs `toLocalMm` then `applySimilarity` on each of
1009
- * `wp[0]` and `wp[1]`), so the guarantee is only that COINCIDENT v1 work points — what the editor writes
1010
- * for an ordinary column — map to bitwise-equal v2 points, both functions being pure. A v1 column
1011
- * authored with a plan lean is a real thing (`steel-editor.html`'s `_lenFt` test pins that its length
1012
- * "includes the plan lean", and migration tolerances `coincidentXY` rather than assuming it), and it
1013
- * migrates battered and is treated as a line here — which is the intended v2 rule, not a failure of it.
1076
+ * that coincident authored work points remain bitwise equal. A column authored with a plan lean is
1077
+ * battered and is treated as a line here, which is the intended native-model rule.
1014
1078
  *
1015
1079
  * PAIRWISE INTERSECTIONS ARE A SEPARATE RULE, and it is keyed on the ROLE, not the footprint: no column
1016
- * ever joins the list, exactly as in v1. Review found the alternative to be a real defect. The inherited
1017
- * intersection elevation is `(A.p0.z + B.p0.z) / 2` — an approximation v1 only ever applies to two beams,
1080
+ * ever joins the list. Review found the alternative to be a real defect. The inherited intersection
1081
+ * elevation is `(A.p0.z + B.p0.z) / 2` — an approximation only suitable for two beams,
1018
1082
  * whose ends sit near one level. A column's `p0` is its BASE, so a column based at 0 crossing a beam at
1019
1083
  * 5000 in plan would emit a snap target at 2500: a point on NEITHER member, and off by half a storey.
1020
1084
  * A battered column keeps its centreline, midpoint and vertices, which are real points on it; only the
1021
1085
  * fabricated crossing is withheld. Interpolating the true crossing elevation would be better than both,
1022
- * and is deliberately not invented here — it would change v1's rule too, which P5 must not do.
1086
+ * and is deliberately not invented here without a separate geometry contract.
1023
1087
  *
1024
1088
  * WHICH LEAVES A STEEP BRACE, and it is inherited rather than endorsed. A brace is `memberType:'brace'`
1025
1089
  * with `role` absent or 'beam', so it reads as a beam here and joins the list — carrying exactly the
1026
1090
  * approximation described above, for the same reason (a near-vertical brace's `p0` is its lower end).
1027
- * v1 does the identical thing, so tightening it here would be a v1 behaviour change wearing a v2 label,
1028
- * and it belongs with whoever owns that rule. Named so the next reader knows the column exclusion is the
1091
+ * The projected helper does the identical thing, so tightening only this path would make the two geometry
1092
+ * boundaries disagree. Named so the next reader knows the column exclusion is the
1029
1093
  * boundary of a fix, not a complete account of the hazard. Asserted, not just stated: the tests pin that
1030
1094
  * a steep brace still intersects.
1031
1095
  *
1032
- * `excludeId` IS MATCHED BY ID, and what makes that sound is the DOCUMENT, not this function: v2 ids are
1033
- * model-global and `checkModelReferences` refuses a duplicate, so the sheet-scoped collision that forces
1034
- * `elevationLevelsByPlan` to exclude by object cannot arrive through a validated path. This function runs
1035
- * no such check itself. Were a duplicate to reach it anyway, BOTH copies drop out — fewer snap targets,
1096
+ * `excludeId` IS MATCHED BY ID, and what makes that sound is the DOCUMENT, not this function: ids are
1097
+ * model-global and `checkModelReferences` refuses a duplicate. This function runs no such check itself.
1098
+ * Were a duplicate to reach it anyway, BOTH copies drop out — fewer snap targets,
1036
1099
  * never a wrong position — while `memberById` would answer with the first. Conservative, and stated
1037
1100
  * because the asymmetry is real rather than because it is reachable.
1038
1101
  */
@@ -1064,12 +1127,8 @@ export function snapCandidatesV2(members, excludeId) {
1064
1127
  }
1065
1128
 
1066
1129
  /**
1067
- * Distinct endpoint elevation levels (mm, sorted) among v2 members — the v2 sibling of `elevationLevels`,
1068
- * feeding the same Alt-drag vertical snap.
1069
- *
1070
- * There is no `elevationLevelsByPlan` sibling and there should not be: that function exists ONLY because
1071
- * v1 resolves each sheet in its own `default_tos`, and v2 has neither per-sheet defaults nor per-sheet
1072
- * scales. One world model means one level set.
1130
+ * Distinct endpoint elevation levels (mm, sorted) among native members, feeding Alt-drag vertical snap.
1131
+ * One world model means one level set; sheets do not own model elevations or coordinate scales.
1073
1132
  */
1074
1133
  export function elevationLevelsV2(members, excludeId) {
1075
1134
  const set = new Set();
@@ -1098,3 +1157,323 @@ export function dim3dGeom(a, b, axis, axisDir) {
1098
1157
  const mid = [(p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2, (p1[2] + p2[2]) / 2];
1099
1158
  return { p1, p2, mid, valueMm };
1100
1159
  }
1160
+
1161
+ // ---- section outline, part frame, flush offsets --------------------------------------------------
1162
+ // The ONE definition of a member's cross-section outline, of the frame that outline is placed in, and of
1163
+ // where a named face puts the reference line. Everything that draws or places a member reads these: the
1164
+ // bake (`server/contract-to-scene.ts`), the 3D solid (`web/steel-3d-view.js` profileShape) and the 2D
1165
+ // plan footprint (`web/steel-editor.html` sectionShapePts). They used to be three hand-kept copies of
1166
+ // the same maths, which is how #647 (an MC channel drawn as a wide flange) survived; `sectionKindOf`
1167
+ // above already ended the CLASSIFIER's copies, and these end the OUTLINE's.
1168
+
1169
+ /**
1170
+ * AWARE's inclusive squared near-vertical predicate, `1 − dot(axis, up)² ≤ 1e−6`. Keeping the squared
1171
+ * form—not an independently rounded `sin θ` comparison—makes the branch and its floating boundary match
1172
+ * the released scene contract. Its visible `sin θ` boundary is 1e−3.
1173
+ */
1174
+ export const FRAME_DEGENERATE_SQ = 1e-6;
1175
+ export const FRAME_DEGENERATE = Math.sqrt(FRAME_DEGENERATE_SQ);
1176
+ const FRAME_SEED_EPS = 1e-9; // AWARE render::geom::EPS: reject a projected fallback made only of float dust.
1177
+
1178
+
1179
+ /**
1180
+ * The outline for a MEMBER — the entry point the bake, the joints engine and the flush maths share, so the
1181
+ * kind is resolved in one place rather than three. Delegates to `sectionOutlinePts`, which the 3D solid and
1182
+ * the 2D plan footprint already build from.
1183
+ *
1184
+ * `round` cannot be derived from the designation here and must be passed in. `sectionKindOf` matches a
1185
+ * literal PREFIX, which cannot tell `HSS6X6X3/8` (rectangular) from `HSS6.625X0.280` (round) — that needs
1186
+ * the designation's numerics. `profileDims` already parses them and reports `round`; every caller has that
1187
+ * answer to hand (the bake from `profileDims`, the joints engine from `MemberGeo.dims.round`, the 2D editor
1188
+ * from its own `profileDimsIn` mirror). One parse, one answer — and note `xsectionFor` is NOT that answer:
1189
+ * it documents "PIPE is NPS (no OD/wall in the name) → rect fallback" and has no `CHS` branch at all, so it
1190
+ * calls a pipe `rect` while `profileDims` calls it round.
1191
+ *
1192
+ * `xs` is passed straight through as the thickness source: an `XSection` carries `tw`/`tf`/`t` under exactly
1193
+ * those keys, and `sectionOutlinePts` applies its own fit test, so no unit conversion or pre-validation
1194
+ * belongs here. Thickness is in the same unit as `w`/`d` — mm on this path.
1195
+ *
1196
+ * @param {string} profile
1197
+ * @param {number} w
1198
+ * @param {number} d
1199
+ * @param {object|null|undefined} xs the member's AISC `xsection`, for real thicknesses
1200
+ * @param {boolean} [round]
1201
+ */
1202
+ export function outlineFor(profile, w, d, xs, round) {
1203
+ return sectionOutlinePts(round === true ? 'ROUND' : sectionKindOf(profile), w, d, xs || null);
1204
+ }
1205
+
1206
+ /**
1207
+ * How far the section reaches along its OWN axes — the bounding box of the UNROTATED outline.
1208
+ *
1209
+ * Read off the outline, never from `|w/2·cos θ| + |d/2·sin θ|`. That support function is the half-extent
1210
+ * of the rolled BOUNDING BOX, exact only where the outline reaches all four box corners: a W, a channel,
1211
+ * a WT and a rectangular tube do, and an **angle does not** — its open corner is empty. It put a rolled
1212
+ * L4X4X3/8 65.1 mm off its flush face and an L4X4X1/4 67.4 mm off, in the shipped bake, while every
1213
+ * symmetric section passed — which is exactly why looking at a render never found it.
1214
+ *
1215
+ * @param {{outer:[number,number][], round?:boolean, r?:number}} outline
1216
+ * @returns {{lo:[number,number], hi:[number,number]}} [width, depth]
1217
+ */
1218
+ export function sectionExtents(outline) {
1219
+ if (outline.round) return { lo: [-outline.r, -outline.r], hi: [outline.r, outline.r] };
1220
+ let loX = Infinity, loY = Infinity, hiX = -Infinity, hiY = -Infinity;
1221
+ for (const [x, y] of outline.outer) {
1222
+ if (x < loX) loX = x;
1223
+ if (x > hiX) hiX = x;
1224
+ if (y < loY) loY = y;
1225
+ if (y > hiY) hiY = y;
1226
+ }
1227
+ return { lo: [loX, loY], hi: [hiX, hiY] };
1228
+ }
1229
+
1230
+ /**
1231
+ * How far the ROLLED section reaches along one world axis — the outline's support function at `rotDeg`.
1232
+ *
1233
+ * This is what a flush face needs while the composition still measures against the WORLD axes (slice 1a):
1234
+ * the section is rolled about the reference line, so `top` has to hold the rolled steel's topmost fibre
1235
+ * on the line, and the topmost fibre moves with the angle. Slice 1b replaces the whole question with
1236
+ * `positionOffsetVector`, which measures on the section's own axes and needs no angle at all.
1237
+ *
1238
+ * `axis` picks which world direction to measure: 'depth' is the one the section's local +y rolls into
1239
+ * (world up for a beam), 'width' the one local +x rolls into.
1240
+ *
1241
+ * A ROUND section is pinned to its exact radius at every roll — its support function genuinely is `r` in
1242
+ * every direction, and measuring the inscribed polygon instead would report `r·cos(π/48)`.
1243
+ *
1244
+ * @param {{outer:[number,number][], round?:boolean, r?:number}} outline
1245
+ * @param {number|undefined} rotDeg
1246
+ * @param {'depth'|'width'} axis
1247
+ * @returns {{lo:number, hi:number}} signed extremes along that axis
1248
+ */
1249
+ export function rolledExtent(outline, rotDeg, axis) {
1250
+ if (outline.round) return { lo: -outline.r, hi: outline.r };
1251
+ // A non-finite rot reads as 0. This value moves a member's COORDINATES, not just its facing, so an
1252
+ // Infinity would reach Math.cos → NaN → NaN endpoints — which the degeneracy guard cannot catch
1253
+ // (`NaN < 1` is false) and which serialize to `null` for the viewer and both native writers alike.
1254
+ const th = ((typeof rotDeg === 'number' && isFinite(rotDeg) ? rotDeg : 0) * Math.PI) / 180;
1255
+ const c = Math.cos(th), s = Math.sin(th);
1256
+ let lo = Infinity, hi = -Infinity;
1257
+ for (const [x, y] of outline.outer) {
1258
+ const v = axis === 'width' ? x * c - y * s : x * s + y * c;
1259
+ if (v < lo) lo = v;
1260
+ if (v > hi) hi = v;
1261
+ }
1262
+ return { lo, hi };
1263
+ }
1264
+
1265
+ /**
1266
+ * Where a named face puts the section relative to the reference line, on ONE axis, in section
1267
+ * coordinates. `top`/`left` put that face ON the line, so the steel hangs off the other side — the
1268
+ * inverse of Tekla's on-plane naming, and the existing floless convention.
1269
+ *
1270
+ * `middle` is the middle of the ENVELOPE, not the material centroid, matching how the viewer centres an
1271
+ * open profile. And every one of these is an envelope PLANE, not a bearing face: name `top` and `left`
1272
+ * on an angle and the line lands in the section's EMPTY corner, touching no steel — measured at 92.075 mm
1273
+ * of air to the nearest steel on an L4X4X3/8 (measured with the designation's own 3/8" thickness — the
1274
+ * untyped fallback is a different shape and measures 83.3), where `top`+`right` bears on the leg tip at
1275
+ * 0.000 mm. (`top`/`left` each put the section's HIGH extreme on the line, and the L branch of
1276
+ * `sectionOutlinePts` is precisely the shape missing its `(+hw, +hd)` corner.) Nothing downstream may
1277
+ * read these as "the line touches material".
1278
+ *
1279
+ * @param {string|undefined} named 'top'|'bottom'|'left'|'right'|'middle'|undefined
1280
+ * @param {number} lo the axis's low extent
1281
+ * @param {number} hi the axis's high extent
1282
+ */
1283
+ export function faceOffset(named, lo, hi) {
1284
+ if (named === 'top' || named === 'left') return -hi;
1285
+ if (named === 'bottom' || named === 'right') return -lo;
1286
+ return -(lo + hi) / 2; // middle, and every unrecognised value
1287
+ }
1288
+
1289
+ /**
1290
+ * The member's own frame: `x` along the reference line, `y` the WIDTH axis, `z` the DEPTH axis.
1291
+ *
1292
+ * x = normalize(to − from)
1293
+ * y = normalize(up × x)
1294
+ * z = x × y
1295
+ *
1296
+ * `up` is the CURRENT coordinate system's normal, not world Z — that single substitution is what lets a
1297
+ * turned system turn every member's section axes with it. Slice 1a always passes world Z.
1298
+ *
1299
+ * DEGENERATE when the member is parallel OR ANTIPARALLEL to `up` (a plumb column, and the same column
1300
+ * with its endpoints stored top→base): there is no unique perpendicular, so fall back to the frame's own
1301
+ * axes. `y` comes from `upX` (the frame's X axis) and `z` is ALWAYS the cross product — writing
1302
+ * `z = frame.yAxis` literally, as an earlier draft did, builds a LEFT-handed frame for the antiparallel
1303
+ * case, in which `rot` turns the wrong way for a column whose ends happen to be stored top→base.
1304
+ *
1305
+ * THE RENDERER READS THIS FRAME (#770). `orientMember` (`web/steel-3d-view.js`) used to derive its own
1306
+ * basis from `setFromUnitVectors(+Z, dir)` plus a corrective roll; it now builds its quaternion from
1307
+ * `memberMeshAxes` below, which is this frame with the axes reordered into the geometry's local order. It
1308
+ * agreed with this rule for every ordinary member — which is why the divergence shipped unnoticed — and
1309
+ * differed by a full 180° for a member stored top→base, where three.js's arbitrary antiparallel tie-break
1310
+ * yielded (−x̂, +ŷ) against this rule's (+x̂, −ŷ). (A second band, at the near-plumb cut, closed earlier
1311
+ * when #786 gave both the same `1 − dot² ≤ 1e−6` predicate.)
1312
+ *
1313
+ * WHAT THAT COST WHILE IT LASTED, since it bounds what the fix can change. The renderer centres the mesh
1314
+ * on the line the BAKE already offset (`placeMember`: `mesh.position` is the midpoint of `el.from`/
1315
+ * `el.to`), so it chooses orientation only, never position. `sectionExtents` is the outline's bounding box
1316
+ * and is symmetric (±w/2, ±d/2) for every shipped shape, so a flipped axis landed the ENVELOPE on the same
1317
+ * world line either way: no steel moved, and the export was unaffected. What differed was an ASYMMETRIC
1318
+ * section's internal facing — which leg of an L, which side a C's web falls on — drawn turned about the
1319
+ * reference line for top→base members only. That is exactly what unifying the frames corrects.
1320
+ *
1321
+ * @param {number[]} from
1322
+ * @param {number[]} to
1323
+ * @param {number[]} [up] the coordinate system's normal (default world Z)
1324
+ * @param {number[]} [upX] the frame's X axis, used only in the degenerate case (default world X)
1325
+ * @returns {{x:[number,number,number], y:[number,number,number], z:[number,number,number], degenerate:boolean}|null} null if the member has no length
1326
+ */
1327
+ export function partFrame(from, to, up = [0, 0, 1], upX = [1, 0, 0]) {
1328
+ const d = [to[0] - from[0], to[1] - from[1], to[2] - from[2]];
1329
+ // Match AWARE `normalized3`: `sqrt(dot(v, v))`, deliberately not `Math.hypot`. They round an exact
1330
+ // 1e-3 near-vertical boundary differently, which would otherwise defeat the inclusive predicate below.
1331
+ const len = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
1332
+ if (!(len > 0) || !isFinite(len)) return null;
1333
+ const x = [d[0] / len, d[1] / len, d[2] / len];
1334
+ const unit = (v, label, min = 0) => {
1335
+ const l = Math.hypot(v[0], v[1], v[2]);
1336
+ if (!(l > min) || !isFinite(l)) throw new Error(`partFrame ${label} must be finite and non-degenerate`);
1337
+ return [v[0] / l, v[1] / l, v[2] / l];
1338
+ };
1339
+ const u = unit(up, 'up');
1340
+ const upDot = u[0] * x[0] + u[1] * x[1] + u[2] * x[2];
1341
+ const perpendicularSq = Math.max(0, 1 - upDot * upDot);
1342
+ const degenerate = perpendicularSq <= FRAME_DEGENERATE_SQ;
1343
+ if (degenerate) {
1344
+ // Same projected +X seed rule as AWARE's scene_roll::member_frame. `upX` is intentionally validated
1345
+ // only here: an ordinary +X beam legitimately has an unused +X seed with a zero member-plane projection.
1346
+ const seedDot = upX[0] * x[0] + upX[1] * x[1] + upX[2] * x[2];
1347
+ const y = unit([upX[0] - seedDot * x[0], upX[1] - seedDot * x[1], upX[2] - seedDot * x[2]], 'seed', FRAME_SEED_EPS);
1348
+ return { x, y, z: cross3(x, y), degenerate };
1349
+ }
1350
+ // Canonical ordinary branch: depth is projected up; width is depth × member axis (not its sign reverse).
1351
+ const z = unit([u[0] - upDot * x[0], u[1] - upDot * x[1], u[2] - upDot * x[2]], 'up projection');
1352
+ return { x, y: cross3(z, x), z, degenerate };
1353
+ }
1354
+
1355
+ function cross3(a, b) {
1356
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
1357
+ }
1358
+
1359
+ /**
1360
+ * `partFrame` with its axes reordered into the MESH's local order — the one place that says which frame
1361
+ * axis each of a member geometry's local axes becomes. `orientMember` (`web/steel-3d-view.js`) feeds the
1362
+ * returned triple straight to `Matrix4.makeBasis`, so this function IS the renderer's basis; deriving a
1363
+ * second one next to it is what put a top→base member's section 180° out for #770.
1364
+ *
1365
+ * The two geometries lay their axes out differently, and the difference is not cosmetic:
1366
+ *
1367
+ * - EXTRUDED profile (`profileShape` → `ExtrudeGeometry`). `sectionOutlinePts` draws width on local X and
1368
+ * depth on local Y, and the extrusion runs along local Z, so the local triple is literally
1369
+ * (width, depth, axis) = (`frame.y`, `frame.z`, `frame.x`) — right-handed, because `frame.y × frame.z`
1370
+ * is `frame.x` for both of `partFrame`'s branches.
1371
+ * - BOX (`BoxGeometry(w, len, d)`) puts the LENGTH on local Y instead, giving (width, axis, depth). That
1372
+ * ordering is LEFT-handed — `frame.y × frame.x` is `−frame.z` — and feeding a left-handed triple to
1373
+ * `makeBasis` yields a determinant −1 matrix that `setFromRotationMatrix` cannot represent, so it
1374
+ * silently returns a wrong rotation. Negating the WIDTH restores the handedness, and width is the only
1375
+ * one of the three that may be flipped for free: a box is symmetric across it, while flipping depth or
1376
+ * the axis would point real geometry somewhere else.
1377
+ *
1378
+ * The caller applies the authored `rot` roll about `frame.x` on top; that is a rotation about an axis this
1379
+ * basis already fixes, so it composes without disturbing anything here.
1380
+ *
1381
+ * @param {number[]} from
1382
+ * @param {number[]} to
1383
+ * @param {boolean} [boxLike] true for a member rendered as a traced `BoxGeometry` rather than a profile
1384
+ * @param {number[]} [up] the coordinate system's normal, passed through to `partFrame`
1385
+ * @param {number[]} [upX] the frame's X axis, passed through to `partFrame`
1386
+ * @returns {{x:number[], y:number[], z:number[], degenerate:boolean}|null} what mesh-local +X/+Y/+Z become
1387
+ * in world, in `makeBasis` order; null if the member has no length
1388
+ */
1389
+ export function memberMeshAxes(from, to, boxLike = false, up = [0, 0, 1], upX = [1, 0, 0]) {
1390
+ const f = partFrame(from, to, up, upX);
1391
+ if (!f) return null;
1392
+ if (!boxLike) return { x: f.y, y: f.z, z: f.x, degenerate: f.degenerate };
1393
+ return { x: [-f.y[0], -f.y[1], -f.y[2]], y: f.x, z: f.z, degenerate: f.degenerate };
1394
+ }
1395
+
1396
+ /**
1397
+ * The offset from the reference line to the section's centroid, in WORLD mm — position first, then swing
1398
+ * about the line.
1399
+ *
1400
+ * 1. position against the line: oy = faceOffset(width), oz = faceOffset(depth)
1401
+ * 2. swing about the line: [oy·cos − oz·sin, oy·sin + oz·cos]
1402
+ *
1403
+ * The pivot is THE REFERENCE LINE, not the section's centre. Rotating about the centre and re-flushing
1404
+ * afterwards makes the steel wander off the line as the angle changes; this order carries the profile's
1405
+ * relationship to the line around with it, like a pendulum hung from the line. Because position is
1406
+ * defined on the UNROTATED profile, the extents are angle-independent — which is what makes a flush face
1407
+ * survive any rotation.
1408
+ *
1409
+ * @param {{x:number[],y:number[],z:number[]}} frame
1410
+ * @param {{lo:[number,number], hi:[number,number]}} ex
1411
+ * @param {string|undefined} depthFace 'top'|'middle'|'bottom'
1412
+ * @param {string|undefined} widthFace 'left'|'middle'|'right'
1413
+ * @param {number|undefined} rotDeg right-hand rule about the reference line
1414
+ * @returns {[number,number,number]} the world offset to ADD to both work points
1415
+ */
1416
+ export function positionOffsetVector(frame, ex, depthFace, widthFace, rotDeg, widthOffMm = 0, depthOffMm = 0) {
1417
+ // The numeric offsets are added to the NAMED face's offset BEFORE the swing — §1.3's step 1 is
1418
+ // `y = u + oy, z = v + oz`, one number per axis — so the pair stays measured on the section's own axes at
1419
+ // every angle rather than becoming a world-space nudge that a roll would send somewhere else.
1420
+ //
1421
+ // POSITIVE MOVES ALONG THE SECTION'S OWN POSITIVE AXIS. `+width` is `frame.y = normalize(up × x)`, which
1422
+ // for a level member is its LEFT looking start→end; `+depth` is `frame.z = x × y`, which is UP. So "past
1423
+ // that face" means the reference line ends up INSIDE the steel rather than on the named face.
1424
+ //
1425
+ // A non-finite offset reads as 0, for the same reason `rot` does: these move a member's COORDINATES, so a
1426
+ // NaN would reach the endpoints and serialize to `null` for the viewer and both native writers alike.
1427
+ const fin = (v) => (typeof v === 'number' && isFinite(v) ? v : 0);
1428
+ const oy0 = faceOffset(widthFace, ex.lo[0], ex.hi[0]) + fin(widthOffMm);
1429
+ const oz0 = faceOffset(depthFace, ex.lo[1], ex.hi[1]) + fin(depthOffMm);
1430
+ // A non-finite rot reads as 0. This is the value that moves a member's COORDINATES rather than just its
1431
+ // facing, so an Infinity would reach Math.cos → NaN → NaN endpoints — which the degeneracy guard cannot
1432
+ // catch (`NaN < 1` is false) and which serialize to `null` for the viewer and both native writers alike.
1433
+ const th = ((typeof rotDeg === 'number' && isFinite(rotDeg) ? rotDeg : 0) * Math.PI) / 180;
1434
+ const c = Math.cos(th), s = Math.sin(th);
1435
+ const oy = oy0 * c - oz0 * s, oz = oy0 * s + oz0 * c;
1436
+ return [
1437
+ oy * frame.y[0] + oz * frame.z[0],
1438
+ oy * frame.y[1] + oz * frame.z[1],
1439
+ oy * frame.y[2] + oz * frame.z[2],
1440
+ ];
1441
+ }
1442
+
1443
+ /**
1444
+ * Reversing a member's two work points must leave the STEEL exactly where it is — and it takes TWO
1445
+ * transforms, one per branch of `partFrame`. An earlier draft had one rule and it was wrong for a column.
1446
+ *
1447
+ * | non-degenerate | degenerate (member parallel to the normal)
1448
+ * axes under x→−x | y = norm(up × x) → −y, z unchanged | y = the frame's own X is FIXED, so z = x × y → −z
1449
+ * rot | → −rot | → −rot
1450
+ * width | mirrored, offset negated | UNCHANGED
1451
+ * depth | UNCHANGED | mirrored, offset negated
1452
+ *
1453
+ * Both branches are involutions and both leave the composed offset identical — worked through and then
1454
+ * measured, not assumed. The ENVELOPE is what the world-space test asserts, not every point: the frame is
1455
+ * derived from the member's DIRECTION, so reversing the work points mirrors an asymmetric L or C across the
1456
+ * width axis. There is no stored chirality for a transform to carry, so it is asserted as the mirror it is
1457
+ * rather than papered over. Note this is a property of THIS frame, not of any renderer disagreeing with it:
1458
+ * since #770 the 3D solid is built on this same frame (`memberMeshAxes`), and unifying them did not and
1459
+ * could not remove the mirror.
1460
+ *
1461
+ * `-0` is normalised back to `0`, so reversing twice restores the document BYTE-for-byte rather than merely
1462
+ * numerically: `JSON.stringify(-0)` is `"0"`, but an in-memory `-0` would still fail a `deepStrictEqual`.
1463
+ *
1464
+ * @param {{position?:string, positionOffset?:number, positionH?:string, positionHOffset?:number, rot?:number}} p
1465
+ * @param {boolean} degenerate `partFrame(...).degenerate` for THIS member — never a plan-length guess
1466
+ */
1467
+ export function reversePlacement(p, degenerate) {
1468
+ const neg = (v) => (typeof v === 'number' && isFinite(v) && v !== 0 ? -v : v);
1469
+ const flip = (v, a, b) => (v === a ? b : v === b ? a : v);
1470
+ const out = { ...p, rot: neg(p.rot) };
1471
+ if (degenerate) {
1472
+ out.position = flip(p.position, 'top', 'bottom');
1473
+ out.positionOffset = neg(p.positionOffset);
1474
+ } else {
1475
+ out.positionH = flip(p.positionH, 'left', 'right');
1476
+ out.positionHOffset = neg(p.positionHOffset);
1477
+ }
1478
+ return out;
1479
+ }