diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-18 21:36:07 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-18 21:36:07 +0100 |
| commit | f48397c58248ca338c258b1de762314926fe681f (patch) | |
| tree | 219ddcc63f1600ae5604d655bb4c6faabd91ca33 /tools/mq_editor/utils.js | |
| parent | eeecb76eef15f684b7909ff22fd054680c2a3498 (diff) | |
feat(mq_editor): movable inner bezier control points + clamp() refactor
- P1/P2 in amp editor now draggable horizontally; t0<t1<t2<t3 enforced
- Add clamp() to utils.js; replace all Math.max/min clamping patterns
- Cursor hints: move for P1/P2, ns-resize for P0/P3
- Remove test_fft.html
- Docs: Delete key, style.css/utils.js in architecture, bezier editor section
handoff(Claude): inner control points done, clamp() adopted everywhere
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'tools/mq_editor/utils.js')
| -rw-r--r-- | tools/mq_editor/utils.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/mq_editor/utils.js b/tools/mq_editor/utils.js index 2c6b2f5..ed34b8e 100644 --- a/tools/mq_editor/utils.js +++ b/tools/mq_editor/utils.js @@ -8,7 +8,7 @@ function evalBezier(curve, t) { const dt = curve.t3 - curve.t0; if (dt <= 0) return curve.v0; let u = (t - curve.t0) / dt; - u = Math.max(0, Math.min(1, u)); + u = clamp(u, 0, 1); const u1 = (curve.t1 - curve.t0) / dt; const u2 = (curve.t2 - curve.t0) / dt; const d0 = (-u1) * (-u2) * (-1); @@ -29,7 +29,7 @@ function evalBezierAmp(curve, t) { const dt = curve.t3 - curve.t0; if (dt <= 0) return curve.a0; let u = (t - curve.t0) / dt; - u = Math.max(0, Math.min(1, u)); + u = clamp(u, 0, 1); const u1 = (curve.t1 - curve.t0) / dt; const u2 = (curve.t2 - curve.t0) / dt; const d0 = (-u1) * (-u2) * (-1); @@ -45,6 +45,8 @@ function evalBezierAmp(curve, t) { return l0 * curve.a0 + l1 * curve.a1 + l2 * curve.a2 + l3 * curve.a3; } +function clamp(v, lo, hi) { return v < lo ? lo : v > hi ? hi : v; } + // Get canvas-relative {x, y} from a mouse event function getCanvasCoords(e, canvas) { const rect = canvas.getBoundingClientRect(); |
