Add factory/getters for quat coeffs in both orders

Reference issue

#2926 (closed)

What does this implement/fix?

This change introduces two new factory functions and two accessor methods to make quaternion coefficient ordering explicit:

Quaternion<Scalar>::FromCoeffsScalarFirst(w, x, y, z);
Quaternion<Scalar>::FromCoeffsScalarLast(x, y, z, w);
q.coeffsScalarFirst();
q.coeffsScalarLast();

These explicit alternatives to the existing constructor and coeffs() accessor makes the scalar/vector layout unambiguous at the call site, and would hopefully mitigate some bugs in interop contexts or translating from papers.

Additional information

There is some room for bikeshedding, mostly surrounding the decision to distinguish the quaternion layout by Scalar(First|Last) or wxyz|xyzw

The original issue proposed the latter, but I was reminded that scipy 's Rotation::(from|to)_quat provided prior art for using scalar_first as its argument keyword. Besides, the existing main constructor already set a bad precedent of expecting parameters in w-z order then populating coefficients in xyzw order, so the alphabets are no longer unambiguous.

Also, only 2 functions implemented here do something new, but I implemented two pairs of functions to make this API fully symmetric.

Merge request reports

Loading