Skip to content

Commit fd010a9

Browse files
committed
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.
1 parent afff7a4 commit fd010a9

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
239239
* [Tinco Andringa](https://github.com/tinco)
240240
* [André Borud](https://github.com/andreborud)
241241
* [Nathan Schulte](https://github.com/nmschulte)
242+
* [Jan Wąsak](https://github.com/jhnwsk)

Source/Scene/Camera.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2939,9 +2939,7 @@ import SceneMode from './SceneMode.js';
29392939
var MINIMUM_ZOOM = 100.0;
29402940

29412941
function adjustBoundingSphereOffset(camera, boundingSphere, offset) {
2942-
if (!defined(offset)) {
2943-
offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET);
2944-
}
2942+
offset = HeadingPitchRange.clone(defined(offset) ? offset : Camera.DEFAULT_OFFSET);
29452943

29462944
var minimumZoom = camera._scene.screenSpaceCameraController.minimumZoomDistance;
29472945
var maximumZoom = camera._scene.screenSpaceCameraController.maximumZoomDistance;
@@ -3038,7 +3036,9 @@ import SceneMode from './SceneMode.js';
30383036
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
30393037
var scene2D = this._mode === SceneMode.SCENE2D || this._mode === SceneMode.COLUMBUS_VIEW;
30403038
this._setTransform(Matrix4.IDENTITY);
3039+
console.log(options.offset);
30413040
var offset = adjustBoundingSphereOffset(this, boundingSphere, options.offset);
3041+
console.log(options.offset);
30423042

30433043
var position;
30443044
if (scene2D) {

Specs/Scene/CameraSpec.js

+31
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,23 @@ describe('Scene/Camera', function() {
26332633
expect(camera.pitch).toEqualEpsilon(pitch, CesiumMath.EPSILON5);
26342634
});
26352635

2636+
it('viewBoundingSphere does not modify offset.range when it is zero', function() {
2637+
scene.mode = SceneMode.SCENE3D;
2638+
2639+
var heading = CesiumMath.toRadians(45.0);
2640+
var pitch = CesiumMath.toRadians(-45.0);
2641+
var range = 0.0;
2642+
var offset = new HeadingPitchRange(heading, pitch, range);
2643+
2644+
var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 10.0);
2645+
camera.viewBoundingSphere(sphere, offset);
2646+
camera._setTransform(Matrix4.IDENTITY);
2647+
2648+
expect(offset.heading).toEqual(CesiumMath.toRadians(45.0));
2649+
expect(offset.pitch).toEqual(CesiumMath.toRadians(-45.0));
2650+
expect(offset.range).toEqual(0.0);
2651+
});
2652+
26362653
it('viewBoundingSphere in 2D', function() {
26372654
var frustum = new OrthographicOffCenterFrustum();
26382655
frustum.left = -10.0;
@@ -2748,6 +2765,20 @@ describe('Scene/Camera', function() {
27482765
expect(CesiumMath.equalsEpsilon(distance, maxValue, 0.1)).toBe(true);
27492766
});
27502767

2768+
it('flyToBoundingSphere does not modify options.offset range if it is zero ', function() {
2769+
scene.mode = SceneMode.SCENE3D;
2770+
var options = {
2771+
offset: new HeadingPitchRange(0.0, -1.5, 0.0)
2772+
};
2773+
2774+
var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 100000.0);
2775+
camera.flyToBoundingSphere(sphere, options);
2776+
2777+
expect(options.offset.heading).toEqual(0.0);
2778+
expect(options.offset.pitch).toEqual(-1.5);
2779+
expect(options.offset.range).toEqual(0.0);
2780+
});
2781+
27512782
it('distanceToBoundingSphere', function() {
27522783
scene.mode = SceneMode.SCENE3D;
27532784

0 commit comments

Comments
 (0)