@floless/app 0.134.0 → 0.134.2
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.
- package/dist/floless-server.cjs +6129 -2881
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +310 -9
- package/dist/skills/steel-drawing-abbreviations/SKILL.md +18 -1
- package/dist/web/app.css +34 -8
- package/dist/web/aware.js +590 -102
- package/dist/web/commands-filter.js +82 -5
- package/dist/web/commands-shell.js +98 -11
- package/dist/web/commands-steel.js +37 -9
- package/dist/web/commands.js +4 -0
- package/dist/web/connection-review-client.js +120 -0
- package/dist/web/index.html +23 -16
- package/dist/web/instructor.js +109 -40
- package/dist/web/steel-3d-core.js +336 -3
- package/dist/web/steel-3d-view.js +923 -160
- package/dist/web/steel-canvas-guidance.js +9 -1
- package/dist/web/steel-editor.html +1408 -68
- package/dist/web/steel-filter-core.js +220 -16
- package/dist/web/steel-filter.html +1261 -50
- package/dist/web/steel-model-commands.js +23 -2
- package/dist/web/steel-model-v2-client-validation.js +6 -0
- package/dist/web/steel-model-v2-commands.js +124 -0
- package/dist/web/workspaces.js +456 -81
- package/package.json +2 -1
|
@@ -55,9 +55,9 @@ export function canonicalPositionBasis(x, y) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** One production folding rule shared by scene reading, editor display and basis re-expression. */
|
|
58
|
-
export function effectiveDepthPosition(explicit, role, dzMm, horizMm,
|
|
58
|
+
export function effectiveDepthPosition(explicit, role, dzMm, horizMm, verticalBrace = false) {
|
|
59
59
|
if (explicit === 'top' || explicit === 'middle' || explicit === 'bottom') return explicit;
|
|
60
|
-
if (role === 'column' ||
|
|
60
|
+
if (role === 'column' || verticalBrace) return 'middle'; // param renamed off `isVerticalBrace`, which is now a module-level predicate this would shadow
|
|
61
61
|
return dzMm > horizMm * 0.5774 ? 'middle' : 'top';
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -99,7 +99,7 @@ export function reexpressMemberPlacement(member, refFrom, refTo, target, extents
|
|
|
99
99
|
if (!a0 || !a1) return { ok: false, code: 'position-rebase-degenerate', message: 'A zero-length member has no Profile Position frame.' };
|
|
100
100
|
const dz = Math.abs(refTo[2] - refFrom[2]), horiz = Math.hypot(refTo[0] - refFrom[0], refTo[1] - refFrom[1]);
|
|
101
101
|
const depthFace = effectiveDepthPosition(member.position, member.role === 'column' ? 'column' : 'beam', dz, horiz,
|
|
102
|
-
member
|
|
102
|
+
isVerticalBrace(member)); // one shared predicate — this was a bare `=== 'brace'`, a THIRD spelling of a test the scene reader already normalises (slice 3b.1)
|
|
103
103
|
const widthFace = effectiveWidthPosition(member.positionH);
|
|
104
104
|
let oy0, oz0;
|
|
105
105
|
if (extents && extents.lo && extents.hi) {
|
|
@@ -1750,3 +1750,336 @@ export function reversePlacement(p, degenerate) {
|
|
|
1750
1750
|
}
|
|
1751
1751
|
return out;
|
|
1752
1752
|
}
|
|
1753
|
+
|
|
1754
|
+
// ---- Reference-line handles: pure geometry (Profile Position gizmo, slice 3b.1) ------------------
|
|
1755
|
+
/*
|
|
1756
|
+
* The shipped gizmo handles (depth / width / roll) move the PROFILE within a fixed reference line. Slice
|
|
1757
|
+
* 3b.1 adds three that move the reference LINE itself — a rigid slide along the member axis and two swings
|
|
1758
|
+
* about the start work point. The math lives HERE, not in steel-3d-view.js, because the view imports
|
|
1759
|
+
* `three` and cannot be unit-tested in node; steel-position-core.test.ts already imports this module.
|
|
1760
|
+
*/
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* The quantisation the v2 store applies to a stored world coordinate — the same `round(v * 1e9) / 1e9`
|
|
1764
|
+
* rule `elev()` uses, so a world-point write and an elevation write agree bit-for-bit on the same number.
|
|
1765
|
+
* Exported because the depth-face pin MUST be decided on the QUANTISED endpoints: an unquantised preview
|
|
1766
|
+
* can disagree with what is actually stored, right at the fold threshold.
|
|
1767
|
+
*/
|
|
1768
|
+
export function quantizeMm(v) {
|
|
1769
|
+
return typeof v === 'number' && isFinite(v) ? Math.round(v * 1e9) / 1e9 : NaN;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
/**
|
|
1773
|
+
* ONE canonical "is this a vertical brace", matching the durable scene reader's normalisation
|
|
1774
|
+
* (`contract-to-scene.ts` `memberIsBrace`, which trims and lowercases). The repo had THREE spellings of
|
|
1775
|
+
* this test, and the scene reader's own comment records that two of them "are not interchangeable"; the
|
|
1776
|
+
* depth-face pin must not add a fourth, so this helper serves the pin AND replaces
|
|
1777
|
+
* `reexpressMemberPlacement`'s bare `=== 'brace'`. The editor's registry path (memberTypeOf /
|
|
1778
|
+
* normMemberTypeKey) stays a third, more permissive answer — recorded here rather than silently widened.
|
|
1779
|
+
*/
|
|
1780
|
+
export function isVerticalBrace(member) {
|
|
1781
|
+
return !!member
|
|
1782
|
+
&& typeof member.memberType === 'string'
|
|
1783
|
+
&& member.memberType.trim().toLowerCase() === 'brace'
|
|
1784
|
+
&& member.brace?.type === 'vertical';
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
/**
|
|
1788
|
+
* The effective depth face before and after a move, and the pin the commit must carry.
|
|
1789
|
+
*
|
|
1790
|
+
* `effectiveDepthPosition` folds an UNSET depth face at `dz > horiz * 0.5774`, so a move that tips a member
|
|
1791
|
+
* past ~30 degrees silently flips which face the profile hangs from and the steel jumps away from where the
|
|
1792
|
+
* user just put it. The fix is to pin the drag-start face explicitly when — and only when — the move would
|
|
1793
|
+
* change it. Deciding that in ONE place, from canonical state and the quantised endpoints, is what stops
|
|
1794
|
+
* the editor's prediction and the model command's verification from ever disagreeing.
|
|
1795
|
+
*
|
|
1796
|
+
* @param {{position?:string, role?:string, memberType?:string, brace?:{type?:string}}} member
|
|
1797
|
+
* @param {{from:number[], to:number[]}} before the stored endpoints
|
|
1798
|
+
* @param {{from:number[], to:number[]}} after the QUANTISED candidate endpoints
|
|
1799
|
+
* @returns {{before:string, after:string, pin:string|undefined}} `pin` is the face to store, or undefined
|
|
1800
|
+
* when the fold does not change. A member with an explicit face never changes, so never pins.
|
|
1801
|
+
*/
|
|
1802
|
+
export function requiredDepthPin(member, before, after) {
|
|
1803
|
+
const role = member && member.role === 'column' ? 'column' : 'beam';
|
|
1804
|
+
const vb = isVerticalBrace(member);
|
|
1805
|
+
const faceOf = (a, b) => effectiveDepthPosition(
|
|
1806
|
+
member ? member.position : undefined, role,
|
|
1807
|
+
Math.abs(b[2] - a[2]), Math.hypot(b[0] - a[0], b[1] - a[1]), vb,
|
|
1808
|
+
);
|
|
1809
|
+
const f0 = faceOf(before.from, before.to);
|
|
1810
|
+
const f1 = faceOf(after.from, after.to);
|
|
1811
|
+
return { before: f0, after: f1, pin: f0 === f1 ? undefined : f0 };
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
/**
|
|
1815
|
+
* A rigid translation of BOTH work points along a unit `axis` by `deltaMm`: the reference line keeps its
|
|
1816
|
+
* direction and its length and simply moves. This is the shared primitive behind all three translate
|
|
1817
|
+
* handles — the member-axis slide (`axis = xAxis`) and, since the gizmo redesign, the depth and width
|
|
1818
|
+
* arrows, which move the LINE sideways rather than sliding the profile off it.
|
|
1819
|
+
*
|
|
1820
|
+
* It is NOT frame-preserving to the bit — the caller quantises each endpoint independently, which perturbs
|
|
1821
|
+
* the direction by ~1e-9 — so a commit must assert that `partFrame`'s BRANCH is stable, never that the
|
|
1822
|
+
* frame is unchanged. Near the degeneracy cone that perturbation can move a member OUT of the seeded
|
|
1823
|
+
* branch as easily as into it, and leaving the cone rebuilds a different section frame than the rigid
|
|
1824
|
+
* preview showed. That is why `commitMemberEndpoints` gives every translate gesture the same
|
|
1825
|
+
* branch-stability policy, not just the axial one.
|
|
1826
|
+
*
|
|
1827
|
+
* @returns {{from:number[], to:number[]}|null} null on a non-finite input or a zero-length axis.
|
|
1828
|
+
*/
|
|
1829
|
+
export function translateEndpoints(from0, to0, axis, deltaMm) {
|
|
1830
|
+
if (!finiteVec3(from0) || !finiteVec3(to0) || !finiteVec3(axis)) return null;
|
|
1831
|
+
if (typeof deltaMm !== 'number' || !isFinite(deltaMm)) return null;
|
|
1832
|
+
const l = len3(axis);
|
|
1833
|
+
if (!(l > 0)) return null;
|
|
1834
|
+
const d = [(axis[0] / l) * deltaMm, (axis[1] / l) * deltaMm, (axis[2] / l) * deltaMm];
|
|
1835
|
+
return {
|
|
1836
|
+
from: [from0[0] + d[0], from0[1] + d[1], from0[2] + d[2]],
|
|
1837
|
+
to: [to0[0] + d[0], to0[1] + d[1], to0[2] + d[2]],
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
/**
|
|
1842
|
+
* The member-axis special case of `translateEndpoints`, kept as its own name because "slide" is the
|
|
1843
|
+
* gesture the tooltip, the readout and the commit's `gesture` field all say.
|
|
1844
|
+
*/
|
|
1845
|
+
export function slideEndpoints(from0, to0, xAxis, deltaMm) {
|
|
1846
|
+
return translateEndpoints(from0, to0, xAxis, deltaMm);
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
/**
|
|
1850
|
+
* A gesture that moves the reference line rigidly, so `partFrame`'s BRANCH must merely be KEPT rather
|
|
1851
|
+
* than required to be non-degenerate. Both translate gestures qualify — a translation changes neither the
|
|
1852
|
+
* member's direction nor its length, so a plumb column stays exactly as plumb as it started — while a
|
|
1853
|
+
* swing re-aims the member and must land on the ordinary branch. One predicate, so the editor's commit
|
|
1854
|
+
* policy and the tests can never spell the set two different ways.
|
|
1855
|
+
*/
|
|
1856
|
+
export function directionPreservingGesture(gesture) {
|
|
1857
|
+
return gesture === 'slide' || gesture === 'translate';
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* The three handles that move the reference line WITHOUT re-aiming it: the member-axis slide and, since
|
|
1862
|
+
* the redesign, the depth and width arrows. `directionPreservingGesture` names the same property for the
|
|
1863
|
+
* COMMIT (`spec.gesture` is what reaches `commitMemberEndpoints`, and there a lateral move is spelled
|
|
1864
|
+
* 'translate'); this one names it for the DRAG, where the handle is still called by its own axis.
|
|
1865
|
+
*/
|
|
1866
|
+
export function isTranslateGesture(gesture) {
|
|
1867
|
+
return gesture === 'depth' || gesture === 'width' || directionPreservingGesture(gesture);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
/**
|
|
1871
|
+
* The member's PROFILE axes: the part frame's width/depth turned by the authored roll about the member
|
|
1872
|
+
* axis. `rot` is measured +y toward +z (the same sense `positionSwingDelta` and the mesh preview use), so
|
|
1873
|
+
*
|
|
1874
|
+
* yRolled = y·cos r + z·sin r zRolled = −y·sin r + z·cos r
|
|
1875
|
+
*
|
|
1876
|
+
* The gizmo draws depth/width/roll on THESE, and the member-axis arrow plus both swing arcs on the
|
|
1877
|
+
* UNROLLED frame — because an elevation swing about a rolled y is not a tilt. Two frames, each carrying
|
|
1878
|
+
* the handles that are actually defined in it.
|
|
1879
|
+
*/
|
|
1880
|
+
export function rolledProfileAxes(frame, rotDeg) {
|
|
1881
|
+
if (!frame || !finiteVec3(frame.y) || !finiteVec3(frame.z)) return null;
|
|
1882
|
+
const th = ((typeof rotDeg === 'number' && isFinite(rotDeg) ? rotDeg : 0) * Math.PI) / 180;
|
|
1883
|
+
const c = Math.cos(th), s = Math.sin(th);
|
|
1884
|
+
return {
|
|
1885
|
+
y: [frame.y[0] * c + frame.z[0] * s, frame.y[1] * c + frame.z[1] * s, frame.y[2] * c + frame.z[2] * s],
|
|
1886
|
+
z: [-frame.y[0] * s + frame.z[0] * c, -frame.y[1] * s + frame.z[1] * c, -frame.y[2] * s + frame.z[2] * c],
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
/**
|
|
1891
|
+
* The gizmo state as it stands PART-WAY THROUGH a gesture — the whole of "the gizmo tracks the member
|
|
1892
|
+
* while you drag it", in one pure function so it can be pinned in node rather than only in a browser.
|
|
1893
|
+
*
|
|
1894
|
+
* Before this existed neither drag handler touched the gizmo group at all: the handles re-anchored only
|
|
1895
|
+
* after the commit rebuilt the scene, so every gesture visibly left its own manipulator behind.
|
|
1896
|
+
*
|
|
1897
|
+
* translate (`depth` / `width` / `slide`) both work points move by `axis·value`; the axes are unchanged.
|
|
1898
|
+
* `rot` only the authored roll changes; the reference line does not move.
|
|
1899
|
+
* swings the far point and the whole part frame turn by `R(axis, value)`
|
|
1900
|
+
* about the anchor. `up` does NOT turn: it belongs to the
|
|
1901
|
+
* authoring basis, not to the member, so a tilt must not swing
|
|
1902
|
+
* the plan-swing arc's plane with it.
|
|
1903
|
+
*
|
|
1904
|
+
* @param {object} st the DRAG-START gizmo state (`memberPositionGizmoState`)
|
|
1905
|
+
* @param {string} gesture 'depth' | 'width' | 'slide' | 'rot' | 'swingPlan' | 'swingElev'
|
|
1906
|
+
* @param {number} value mm for a translate, degrees for `rot`, radians for a swing
|
|
1907
|
+
* @param {number[]} [axis] the translate axis / swing axis, when it is not derivable from `st` alone
|
|
1908
|
+
* @returns {object|null} a new state (never a mutation of `st`), or null when the input cannot be used
|
|
1909
|
+
*/
|
|
1910
|
+
export function livePositionState(st, gesture, value, axis) {
|
|
1911
|
+
if (!st || !finiteVec3(st.anchor) || !finiteVec3(st.end)) return null;
|
|
1912
|
+
if (typeof value !== 'number' || !isFinite(value)) return null;
|
|
1913
|
+
// A roll turns the PROFILE frame and nothing else: the reference line is exactly where it was, which is
|
|
1914
|
+
// the whole point of rolling about it. `profile` is recomputed from the UNROLLED part axes, never
|
|
1915
|
+
// composed onto the previous profile, so a drag that sweeps back to zero lands back on the part frame.
|
|
1916
|
+
if (gesture === 'rot') return { ...st, rot: value, profile: rolledProfileAxes({ y: st.yAxis, z: st.zAxis }, value) };
|
|
1917
|
+
if (isTranslateGesture(gesture)) {
|
|
1918
|
+
const t = translateEndpoints(st.anchor, st.end, axis, value);
|
|
1919
|
+
return t ? { ...st, anchor: t.from, end: t.to } : null;
|
|
1920
|
+
}
|
|
1921
|
+
if (gesture !== 'swingPlan' && gesture !== 'swingElev') return null;
|
|
1922
|
+
const end = swingEndpoint(st.anchor, st.end, axis, value);
|
|
1923
|
+
if (!end) return null;
|
|
1924
|
+
const turn = (v) => (finiteVec3(v) ? swingEndpoint([0, 0, 0], v, axis, value) : v);
|
|
1925
|
+
const profile = st.profile && finiteVec3(st.profile.y) && finiteVec3(st.profile.z)
|
|
1926
|
+
? { y: turn(st.profile.y), z: turn(st.profile.z) } : st.profile;
|
|
1927
|
+
// `up` is deliberately NOT turned — see the doc comment.
|
|
1928
|
+
return { ...st, end, xAxis: turn(st.xAxis), yAxis: turn(st.yAxis), zAxis: turn(st.zAxis), profile };
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
|
|
1932
|
+
/**
|
|
1933
|
+
* The right-handed in-plane basis a swing measures its angle in: `e1` is the drag-start radius with the
|
|
1934
|
+
* rotation axis projected out, `e2 = axis x e1`, so `e1 x e2 = axis`. Measuring `atan2(d.e2, d.e1)` in THIS
|
|
1935
|
+
* basis gives the same sign from either side of the screen — which a screen-pixel delta cannot — and it is
|
|
1936
|
+
* the same basis the arc is DRAWN in, so the lobe the user grabs sweeps the way they expect.
|
|
1937
|
+
*
|
|
1938
|
+
* null when the radius is parallel to the axis: there is no swing plane, and the handle must be refused
|
|
1939
|
+
* rather than drawn inert.
|
|
1940
|
+
*/
|
|
1941
|
+
export function swingBasis(from, to0, axis) {
|
|
1942
|
+
if (!finiteVec3(from) || !finiteVec3(to0) || !finiteVec3(axis)) return null;
|
|
1943
|
+
const al = len3(axis);
|
|
1944
|
+
if (!(al > 0)) return null;
|
|
1945
|
+
const A = [axis[0] / al, axis[1] / al, axis[2] / al];
|
|
1946
|
+
const r = [to0[0] - from[0], to0[1] - from[1], to0[2] - from[2]];
|
|
1947
|
+
const rl = len3(r);
|
|
1948
|
+
if (!(rl > 0)) return null;
|
|
1949
|
+
const p = dot3(r, A);
|
|
1950
|
+
const perp = [r[0] - p * A[0], r[1] - p * A[1], r[2] - p * A[2]];
|
|
1951
|
+
const pl = len3(perp);
|
|
1952
|
+
if (!(pl > FRAME_DEGENERATE * rl)) return null;
|
|
1953
|
+
const e1 = [perp[0] / pl, perp[1] / pl, perp[2] / pl];
|
|
1954
|
+
return { e1, e2: cross3(A, e1) };
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
/**
|
|
1958
|
+
* Rodrigues rotation of the FAR work point about `axis` through the anchor:
|
|
1959
|
+
* to(theta) = O + R(A,theta)(E0 - O). Always evaluated from the DRAG-START endpoint and the frozen axis,
|
|
1960
|
+
* never accumulated per tick — a per-tick composition drifts and makes the 5-degree snap chatter.
|
|
1961
|
+
*/
|
|
1962
|
+
export function swingEndpoint(from, to0, axis, theta) {
|
|
1963
|
+
if (!finiteVec3(from) || !finiteVec3(to0) || !finiteVec3(axis)) return null;
|
|
1964
|
+
if (typeof theta !== 'number' || !isFinite(theta)) return null;
|
|
1965
|
+
const al = len3(axis);
|
|
1966
|
+
if (!(al > 0)) return null;
|
|
1967
|
+
const A = [axis[0] / al, axis[1] / al, axis[2] / al];
|
|
1968
|
+
const r = [to0[0] - from[0], to0[1] - from[1], to0[2] - from[2]];
|
|
1969
|
+
const c = Math.cos(theta), s = Math.sin(theta), k = dot3(A, r) * (1 - c);
|
|
1970
|
+
const x = cross3(A, r);
|
|
1971
|
+
return [
|
|
1972
|
+
from[0] + r[0] * c + x[0] * s + A[0] * k,
|
|
1973
|
+
from[1] + r[1] * c + x[1] * s + A[1] * k,
|
|
1974
|
+
from[2] + r[2] * c + x[2] * s + A[2] * k,
|
|
1975
|
+
];
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
/**
|
|
1979
|
+
* The two angles at which an elevation swing would drive the member through plumb — the signed pair
|
|
1980
|
+
* `{negative, positive}`, already backed off by the degeneracy cone and `marginRad`, in radians.
|
|
1981
|
+
*
|
|
1982
|
+
* WHY NOT SAMPLED. `partFrame` calls a frame degenerate at `qSq <= FRAME_DEGENERATE_SQ * dSq`, a half-cone
|
|
1983
|
+
* of 0.0573 degrees — far too thin to find by probing (a 1-degree walk steps over it 17 times).
|
|
1984
|
+
*
|
|
1985
|
+
* WHY IT IS EXACT. With the rotation axis perpendicular to `up` AND to the member radius — which is
|
|
1986
|
+
* precisely `partFrame`'s ordinary branch — the projection of the swept direction onto the plane
|
|
1987
|
+
* perpendicular to `up` stays COLLINEAR with one fixed vector. The whole question then reduces to one
|
|
1988
|
+
* sinusoid, s(theta) = R*cos(theta - phi), whose two roots are phi +/- pi/2. No bisection, no sampling.
|
|
1989
|
+
*
|
|
1990
|
+
* WHY A PAIR. Those roots are ASYMMETRIC about zero whenever phi is nonzero, i.e. for any sloped member —
|
|
1991
|
+
* measured -81 and +99 degrees on the test beam, not +/-90. The drag angle is signed and the pointer can
|
|
1992
|
+
* reverse mid-gesture and cross back through zero, so a single cached barrier would apply the positive
|
|
1993
|
+
* limit to a negative sweep. Cache the pair once per drag; every tick is then an O(1) comparison.
|
|
1994
|
+
*
|
|
1995
|
+
* Returns null when the premise does not hold (the axis is not perpendicular to `up`, or not perpendicular
|
|
1996
|
+
* to the member). The caller must then REFUSE the swing rather than clamp it on a formula that does not
|
|
1997
|
+
* apply — which is exactly why the swing handles are unavailable on a degenerate start frame, where
|
|
1998
|
+
* `yAxis` is seeded from `upX` and need not be perpendicular to `up`.
|
|
1999
|
+
*/
|
|
2000
|
+
export function swingBarriers(from, to0, axis, up, marginRad = 0) {
|
|
2001
|
+
if (!finiteVec3(from) || !finiteVec3(to0) || !finiteVec3(axis) || !finiteVec3(up)) return null;
|
|
2002
|
+
const al = len3(axis), ul = len3(up);
|
|
2003
|
+
if (!(al > 0) || !(ul > 0)) return null;
|
|
2004
|
+
const A = [axis[0] / al, axis[1] / al, axis[2] / al];
|
|
2005
|
+
const u = [up[0] / ul, up[1] / ul, up[2] / ul];
|
|
2006
|
+
const r = [to0[0] - from[0], to0[1] - from[1], to0[2] - from[2]];
|
|
2007
|
+
const rl = len3(r);
|
|
2008
|
+
if (!(rl > 0)) return null;
|
|
2009
|
+
if (Math.abs(dot3(A, u)) > 1e-9) return null; // axis must lie in the plane perp to up
|
|
2010
|
+
if (Math.abs(dot3(r, A)) > FRAME_DEGENERATE * rl) return null; // and be perpendicular to the member
|
|
2011
|
+
const P = (v) => { const d = dot3(v, u); return [v[0] - d * u[0], v[1] - d * u[1], v[2] - d * u[2]]; };
|
|
2012
|
+
const p0 = P(r), p0l = len3(p0);
|
|
2013
|
+
if (!(p0l > 0)) return null; // already plumb — nothing to swing from
|
|
2014
|
+
const w = [p0[0] / p0l, p0[1] / p0l, p0[2] / p0l];
|
|
2015
|
+
const alpha = dot3(P(r), w); // s(0), positive by construction
|
|
2016
|
+
const beta = dot3(P(cross3(A, r)), w);
|
|
2017
|
+
const R = Math.hypot(alpha, beta);
|
|
2018
|
+
if (!(R > 0)) return null;
|
|
2019
|
+
const phi = Math.atan2(beta, alpha);
|
|
2020
|
+
const half = Math.asin(Math.min(1, (FRAME_DEGENERATE * rl) / R)); // cone half-width, in theta
|
|
2021
|
+
return {
|
|
2022
|
+
positive: (phi + Math.PI / 2) - half - marginRad,
|
|
2023
|
+
negative: (phi - Math.PI / 2) + half + marginRad,
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
/**
|
|
2028
|
+
* Clamp a requested swing angle against the barrier pair, in the mode matching how the value was ENTERED.
|
|
2029
|
+
* Returning one snapped step for all three inputs would silently break Shift-free dragging (continuous by
|
|
2030
|
+
* definition) and typed entry (exact by definition).
|
|
2031
|
+
*
|
|
2032
|
+
* 'snapped' — the last whole snap step still inside the barrier
|
|
2033
|
+
* 'free' — the barrier itself, a smooth stop for a smooth drag
|
|
2034
|
+
* 'typed' — REFUSED (null). Bypassing the snap, which is the shipped typed-entry contract, was never a
|
|
2035
|
+
* licence to bypass geometric validity; the caller keeps its HUD open and says nothing was
|
|
2036
|
+
* committed, rather than silently rewriting the exact value the user asked for.
|
|
2037
|
+
*
|
|
2038
|
+
* Because the barrier already sits short of the cone, a request that merely STOPS INSIDE the cone without
|
|
2039
|
+
* crossing the root is clamped too — that case has no sign change, and a sign-flip-only test would have
|
|
2040
|
+
* accepted a degenerate endpoint.
|
|
2041
|
+
*
|
|
2042
|
+
* @returns {{theta:number, clamped:boolean}|null}
|
|
2043
|
+
*/
|
|
2044
|
+
/**
|
|
2045
|
+
* The extra back-off past the degeneracy cone that a swing barrier carries. ONE constant, because the
|
|
2046
|
+
* drag path and the typed path must agree about what is geometrically legal: if they drift, the symptom
|
|
2047
|
+
* is "the drag let me do it but typing the same number is refused", which reads as a bug in the HUD.
|
|
2048
|
+
*/
|
|
2049
|
+
export const POSITION_SWING_MARGIN_RAD = Math.PI / 180;
|
|
2050
|
+
|
|
2051
|
+
/**
|
|
2052
|
+
* Does this member have at least one snap step of swing travel on BOTH sides of its current heading?
|
|
2053
|
+
*
|
|
2054
|
+
* A member already within the cone-plus-margin of plumb has a barrier pair that does not bracket zero, so
|
|
2055
|
+
* there is no legal swing in one direction at all. Drawing the handle there gives the detailer a grip that
|
|
2056
|
+
* refuses every drag; the honest answer is not to offer it, with a reason they can read.
|
|
2057
|
+
*/
|
|
2058
|
+
export function swingHasTravel(barriers, snapRad) {
|
|
2059
|
+
if (!barriers) return false;
|
|
2060
|
+
const step = typeof snapRad === 'number' && snapRad > 0 ? snapRad : 0;
|
|
2061
|
+
return barriers.positive >= step && barriers.negative <= -step;
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
export function clampSwingTheta(thetaReq, barriers, mode, snapRad) {
|
|
2065
|
+
if (typeof thetaReq !== 'number' || !isFinite(thetaReq)) return null;
|
|
2066
|
+
if (!barriers) return null;
|
|
2067
|
+
const cap = Math.max(-Math.PI, Math.min(Math.PI, thetaReq)); // also bounds a typed/unwrapped sweep
|
|
2068
|
+
const limit = cap >= 0 ? barriers.positive : barriers.negative;
|
|
2069
|
+
if (!(typeof limit === 'number' && isFinite(limit))) return null;
|
|
2070
|
+
// THE BARRIER PAIR NEED NOT BRACKET ZERO. Each barrier is a plumb root backed off by the cone half-width
|
|
2071
|
+
// plus the margin, so on a member that already sits within that back-off of plumb the "negative" barrier
|
|
2072
|
+
// lands on the POSITIVE side (measured: a member 0.2 deg off plumb yields +178.743 / +0.857). Clamping to
|
|
2073
|
+
// it would then hand back a limit signed OPPOSITE to the drag — the member swings the way the hand did
|
|
2074
|
+
// not, by about a degree, with a real write and a real undo entry behind it. There is simply no valid
|
|
2075
|
+
// travel in that direction, so say so rather than substitute a number: every mode refuses, and the caller
|
|
2076
|
+
// reports it. Found by two independent reviewers and reproduced before fixing.
|
|
2077
|
+
if (cap !== 0 && Math.sign(limit) !== Math.sign(cap)) return null;
|
|
2078
|
+
if (cap >= 0 ? cap <= limit : cap >= limit) return { theta: cap, clamped: false };
|
|
2079
|
+
if (mode === 'typed') return null;
|
|
2080
|
+
if (mode === 'free') return { theta: limit, clamped: true };
|
|
2081
|
+
const step = typeof snapRad === 'number' && snapRad > 0 ? snapRad : 0;
|
|
2082
|
+
if (!step) return { theta: limit, clamped: true };
|
|
2083
|
+
const steps = Math.floor(Math.abs(limit) / step);
|
|
2084
|
+
return { theta: Math.sign(limit) * steps * step, clamped: true };
|
|
2085
|
+
}
|