Skip to content

Commit

Permalink
Replay fixes for Quaternion.computeAxis
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Dec 11, 2023
1 parent 2a57a89 commit 6a7487c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions 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 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 6a7487c

Please sign in to comment.