Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automation: Integrate with Device Orientation API's Automation section
Related to w3c/deviceorientation#124. Both the Device Orientation API and the Orientation Sensor specifications provide orientation data. Among other differences, the former provides the data as a set of intrinsic Tait-Bryant Euler angles, whereas the latter uses quaternions. From an automation perspective, though, it makes sense to use the same virtual sensor types for both APIs and take care of the conversions internally. The Device Orientation spec's Automation section defines steps for parsing a user-provided reading as alpha, beta, gamma numbers that adhere to the requirements laid out by the same spec. This commit augments the same "parse orientation data reading" algorithm by also setting a "quaternion" entry in the reading map that is set in two different ways: 1. If the user-provided readings contain a "quaternion" key, it is used as-is via the "parse quaternion reading" algorithm, and it is also converted to Euler angles so that the "alpha"/"beta"/"gamma" reading entries are also set. 2. Otherwise, the user-provider Euler angles are converted to a quaternion that is then used to set the "quaternion" entry in the readings map. The conversions are not trivial, so some new abstract operations have been added to aid in the process. The Euler angles to quaternion algorithm has been copied from Chromium. The quaternion to Euler angles algorithm has been copied from both Chromium and Gecko, both of which need to do this to convert Android's orientation data to a format suitable for their Device Orientation API implementations.
- Loading branch information