From ff104b8ef5bf89a667e3f240d1f52d02905216e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20W=C4=85sak?= Date: Thu, 5 Dec 2019 15:45:16 +0100 Subject: [PATCH 1/2] Clone offset in adjustBoundingSphereOffset Cloning the offset parameter of adjustBoundingSphereOffset results in no argument reassignment in functions that use it. Because this reassignment is not document and therefore unintentional it prevents confusion when using the Camer api. --- CONTRIBUTORS.md | 1 + Source/Scene/Camera.js | 4 +--- Specs/Scene/CameraSpec.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6346f2b35a77..ce085e672fb3 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -239,3 +239,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Tinco Andringa](https://github.com/tinco) * [André Borud](https://github.com/andreborud) * [Nathan Schulte](https://github.com/nmschulte) +* [Jan Wąsak](https://github.com/jhnwsk) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index ec9266cbe678..94801047a73f 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2939,9 +2939,7 @@ import SceneMode from './SceneMode.js'; var MINIMUM_ZOOM = 100.0; function adjustBoundingSphereOffset(camera, boundingSphere, offset) { - if (!defined(offset)) { - offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET); - } + offset = HeadingPitchRange.clone(defined(offset) ? offset : Camera.DEFAULT_OFFSET); var minimumZoom = camera._scene.screenSpaceCameraController.minimumZoomDistance; var maximumZoom = camera._scene.screenSpaceCameraController.maximumZoomDistance; diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 581363eab74a..9a0d4750c675 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -2633,6 +2633,23 @@ describe('Scene/Camera', function() { expect(camera.pitch).toEqualEpsilon(pitch, CesiumMath.EPSILON5); }); + it('viewBoundingSphere does not modify offset.range when it is zero', function() { + scene.mode = SceneMode.SCENE3D; + + var heading = CesiumMath.toRadians(45.0); + var pitch = CesiumMath.toRadians(-45.0); + var range = 0.0; + var offset = new HeadingPitchRange(heading, pitch, range); + + var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 10.0); + camera.viewBoundingSphere(sphere, offset); + camera._setTransform(Matrix4.IDENTITY); + + expect(offset.heading).toEqual(CesiumMath.toRadians(45.0)); + expect(offset.pitch).toEqual(CesiumMath.toRadians(-45.0)); + expect(offset.range).toEqual(0.0); + }); + it('viewBoundingSphere in 2D', function() { var frustum = new OrthographicOffCenterFrustum(); frustum.left = -10.0; @@ -2748,6 +2765,20 @@ describe('Scene/Camera', function() { expect(CesiumMath.equalsEpsilon(distance, maxValue, 0.1)).toBe(true); }); + it('flyToBoundingSphere does not modify options.offset range if it is zero ', function() { + scene.mode = SceneMode.SCENE3D; + var options = { + offset: new HeadingPitchRange(0.0, -1.5, 0.0) + }; + + var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 100000.0); + camera.flyToBoundingSphere(sphere, options); + + expect(options.offset.heading).toEqual(0.0); + expect(options.offset.pitch).toEqual(-1.5); + expect(options.offset.range).toEqual(0.0); + }); + it('distanceToBoundingSphere', function() { scene.mode = SceneMode.SCENE3D; From 69736c15b18c8f3c3344febcfed5d1dbc5a4cf09 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 29 Jan 2020 09:24:01 -0500 Subject: [PATCH 2/2] CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 9bdee45b1b73..1e2b2cc0b088 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -46,6 +46,7 @@ Change Log * Fixed a bug where rapidly updating a `PolylineCollection` could result in an instanceIndex is out of range error. [#8546](https://github.com/AnalyticalGraphicsInc/cesium/pull/8546) * Fixed a crash that could occur when an entity was deleted while the corresponding `Primitive` was being created asynchronously. [#8569](https://github.com/AnalyticalGraphicsInc/cesium/pull/8569) * Fixed a crash when calling `camera.lookAt` with the origin as the target. This could happen when looking at a tileset with the origin as its center. [#8571](https://github.com/AnalyticalGraphicsInc/cesium/pull/8571) +* Fixed a bug where `camera.viewBoundingSphere` was modifying the `offset` parameter [#8438](https://github.com/AnalyticalGraphicsInc/cesium/pull/8438) ### 1.65.0 - 2020-01-06