Skip to content

Commit

Permalink
Merge pull request #11684 from CesiumGS/fix-quaternion-compute-axis
Browse files Browse the repository at this point in the history
Fix `Quaternion.computeAxis`
  • Loading branch information
ggetz authored Dec 12, 2023
2 parents 62e9f40 + 170e51f commit 334e7b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Changes the default `RequestScheduler.maximumRequestsPerServer` from 6 to 18. This should improve performance on HTTP/2 servers and above [#11627](https://github.com/CesiumGS/cesium/issues/11627)
- Corrected JSDoc and Typescript definitions that marked optional arguments as required in `ImageryProvider` constructor [#11625](https://github.com/CesiumGS/cesium/issues/11625)
- The `Quaternion.computeAxis` function created an axis that was `(0,0,0)` for the unit quaternion, and an axis that was `(NaN,NaN,NaN)` for the quaternion `(0,0,0,-1)` (which describes a rotation about 360 degrees). Now, it returns the x-axis `(1,0,0)` in both of these cases.

### 1.112 - 2023-12-01

Expand All @@ -33,7 +34,7 @@
- Fixed error with rhumb lines that have a 0 degree heading. [#11573](https://github.com/CesiumGS/cesium/pull/11573)
- Fixed `czm_normal`, `czm_normal3D`, `czm_inverseNormal`, and `czm_inverseNormal3D` for cases where the model matrix has non-uniform scale. [#11553](https://github.com/CesiumGS/cesium/pull/11553)
- Fixed issue with clustered labels when `dataSource.show` was toggled. [#11560](https://github.com/CesiumGS/cesium/pull/11560)
- Fixed inconsistant clustering when `dataSource.show` was toggled. [#11560](https://github.com/CesiumGS/cesium/pull/11560)
- Fixed inconsistent clustering when `dataSource.show` was toggled. [#11560](https://github.com/CesiumGS/cesium/pull/11560)

### 1.110.1 - 2023-10-25

Expand Down
8 changes: 6 additions & 2 deletions packages/engine/Source/Core/Quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,12 @@ Quaternion.computeAxis = function (quaternion, result) {
//>>includeEnd('debug');

const w = quaternion.w;
if (Math.abs(w - 1.0) < CesiumMath.EPSILON6) {
result.x = result.y = result.z = 0;
if (
Math.abs(w - 1.0) < CesiumMath.EPSILON6 ||
Math.abs(w + 1.0) < CesiumMath.EPSILON6
) {
result.x = 1;
result.y = result.z = 0;
return result;
}

Expand Down
13 changes: 11 additions & 2 deletions packages/engine/Specs/Core/QuaternionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,24 @@ describe("Core/Quaternion", function () {
expect(result).toBe(returnedResult);
});

it("axis returns Cartesian3 0 when w equals 1.0", function () {
const expected = new Cartesian3(0.0, 0.0, 0.0);
it("axis returns Cartesian3 (1,0,0) when w equals 1.0", function () {
const expected = new Cartesian3(1.0, 0.0, 0.0);
const quaternion = new Quaternion(4.0, 2.0, 3.0, 1.0);
const result = new Cartesian3(1, 2, 3);
const returnedResult = Quaternion.computeAxis(quaternion, result);
expect(returnedResult).toEqual(expected);
expect(result).toBe(returnedResult);
});

it("axis returns Cartesian3 (1,0,0) when w equals -1.0", function () {
const expected = new Cartesian3(1.0, 0.0, 0.0);
const quaternion = new Quaternion(4.0, 2.0, 3.0, -1.0);
const result = new Cartesian3(1, 2, 3);
const returnedResult = Quaternion.computeAxis(quaternion, result);
expect(returnedResult).toEqual(expected);
expect(result).toBe(returnedResult);
});

it("angle works", function () {
// 60 degrees is used here to ensure that the sine and cosine of the half angle are not equal.
const angle = Math.PI / 3.0;
Expand Down

0 comments on commit 334e7b7

Please sign in to comment.