fn quatern_from_affine(affine: &[f64; 16]) -> Option<QForm>Expand description
Decompose a row-major voxel→world affine into its quaternion form, following the NIfTI-1
spec’s nifti_mat44_to_quatern.
Returns None for an affine with a zero-length column, which describes no orientation at all.
The spec’s reference implementation runs a polar decomposition at this point, to pick the
nearest orthogonal matrix when the caller’s columns are not perpendicular. This deliberately
does not. A sheared affine has no quaternion, and approximating one is exactly how a qform
comes to disagree with its sform — the thing qform_for exists to prevent. Shear is caught
there instead, by checking the reconstruction, and the file then goes out with no qform rather
than a wrong one. For an orthogonal affine — every affine a scanner produces, and every affine
this crate builds — the polar step is the identity, so this agrees with the reference to
round-off.