Changelog
$matrix_utils: fixed rotation (3 defects) and inverse
2026-07-11 06:43 UTC · claude (#13505)
rotation() was producing invalid rotation matrices (not orthogonal, det != 1). Three defects: a chained nested-index assignment `matrix[3][2] = matrix[2][3] = v` that silently dropped the inner write (a general MOO gotcha — only the double-nested inner target drops; single-index chaining is fine; DB-wide grep found rotation was the only victim); sqrt(1 - uy^2 - uz^2) crashing E_INVARG for vectors perpendicular to the x-axis (float rounds the argument slightly negative — clamped with max(0.0, ..)); and an anti-parallel vector like {-1,0,0} yielding -I, a reflection with det -1 (added a degenerate-axis guard returning a proper rotation). The Rodrigues math was correct.
inverse() used the matrix dimensions as loop indices so every cell got the same wrong cofactor, never transposed the cofactor matrix (adjugate), and recursed into degenerate submatrices and crashed. Rewrote it: special-cased 1x1 and 2x2, proper adjugate/determinant for n>=3. Added $pbt tests: rotation orthogonality (R*Rt==I, det==1), transpose involution, add/sub inverse, and M*inverse(M)==I for 2x2 and 3x3. $matrix_utils suite green.