diff --git a/CHANGES.md b/CHANGES.md index 0cb368456eaf..34a23c345b2d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ##### Fixes :wrench: - Fixed zip.js configurations causing CesiumJS to not work with Node 16. [#9861](https://github.com/CesiumGS/cesium/pull/9861) +- Fixed a bug in `Rectangle.union` with rectangles that span the entire globe. [#9865](https://github.com/CesiumGS/cesium/pull/9861) ### 1.86 - 2021-10-01 diff --git a/Source/Core/Rectangle.js b/Source/Core/Rectangle.js index aa2f915fb992..5a497909439e 100644 --- a/Source/Core/Rectangle.js +++ b/Source/Core/Rectangle.js @@ -740,10 +740,10 @@ Rectangle.union = function (rectangle, otherRectangle, result) { rectangleWest += CesiumMath.TWO_PI; } - var west = CesiumMath.convertLongitudeRange( + var west = CesiumMath.negativePiToPi( Math.min(rectangleWest, otherRectangleWest) ); - var east = CesiumMath.convertLongitudeRange( + var east = CesiumMath.negativePiToPi( Math.max(rectangleEast, otherRectangleEast) ); diff --git a/Specs/Core/RectangleSpec.js b/Specs/Core/RectangleSpec.js index 36db8a65726d..c914dd01698d 100644 --- a/Specs/Core/RectangleSpec.js +++ b/Specs/Core/RectangleSpec.js @@ -773,6 +773,29 @@ describe("Core/Rectangle", function () { expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); + it("union works with rectangles that span the entire globe", function () { + var rectangle1 = new Rectangle( + -CesiumMath.PI, + -CesiumMath.PI_OVER_TWO, + +CesiumMath.PI, + 0.0 + ); + var rectangle2 = new Rectangle( + -CesiumMath.PI, + 0.0, + +CesiumMath.PI, + +CesiumMath.PI_OVER_TWO + ); + var expected = new Rectangle( + -CesiumMath.PI, + -CesiumMath.PI_OVER_TWO, + +CesiumMath.PI, + +CesiumMath.PI_OVER_TWO + ); + var returnedResult = Rectangle.union(rectangle1, rectangle2); + expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); + }); + it("expand works if rectangle needs to grow right", function () { var rectangle = new Rectangle(0.5, 0.1, 0.75, 0.9); var cartographic = new Cartographic(0.85, 0.5);