diff --git a/Apps/Sandcastle/gallery/Star Burst.html b/Apps/Sandcastle/gallery/Star Burst.html index fc7af5a2ff21..d34571c322d5 100644 --- a/Apps/Sandcastle/gallery/Star Burst.html +++ b/Apps/Sandcastle/gallery/Star Burst.html @@ -88,11 +88,12 @@ var drawingBufferWidth = scene.drawingBufferWidth; var drawingBufferHeight = scene.drawingBufferHeight; + var pixelRatio = scene.pixelRatio; var diff = Cesium.Cartesian3.subtract(entityPosition, camera.positionWC, new Cesium.Cartesian3()); var distance = Cesium.Cartesian3.dot(camera.directionWC, diff); - var dimensions = camera.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, new Cesium.Cartesian2()); + var dimensions = camera.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, new Cesium.Cartesian2()); Cesium.Cartesian2.multiplyByScalar(offset, Cesium.Cartesian2.maximumComponent(dimensions), offset); var labelOffset; diff --git a/CHANGES.md b/CHANGES.md index 7473417bf661..3afc7e2d9f03 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,8 +3,14 @@ Change Log ### 1.63 - 2019-11-01 -##### Fixes :wrench: +##### Deprecated :hourglass_flowing_sand: +* `OrthographicFrustum.getPixelDimensions`, `OrthographicOffCenterFrustum.getPixelDimensions`, `PerspectiveFrustum.getPixelDimensions`, and `PerspectiveOffCenterFrustum.getPixelDimensions` now take a `pixelRatio` argument before the `result` argument. The previous function definition will no longer work in 1.65. [#8237](https://github.com/AnalyticalGraphicsInc/cesium/pull/8237) +##### Additions :tada: +* Added `pixelRatio` parameter to `OrthographicFrustum.getPixelDimensions`, `OrthographicOffCenterFrustum.getPixelDimensions`, `PerspectiveFrustum.getPixelDimensions`, and `PerspectiveOffCenterFrustum.getPixelDimensions`. Pass in `scene.pixelRatio` for dimensions in CSS pixel units or `1.0` for dimensions in native device pixel units. [#8237](https://github.com/AnalyticalGraphicsInc/cesium/pull/8237) + +##### Fixes :wrench: +* Fixed css pixel usage for polylines, point clouds, models, primitives, and post-processing. [#8113](https://github.com/AnalyticalGraphicsInc/cesium/issues/8113) * Fixed a bug where `scene.sampleHeightMostDetailed` and `scene.clampToHeightMostDetailed` would not resolve in request render mode. [#8281](https://github.com/AnalyticalGraphicsInc/cesium/issues/8281) * Fixed seam artifacts when log depth is disabled, `scene.globe.depthTestAgainstTerrain` is false, and primitives are under the globe. [#8205](https://github.com/AnalyticalGraphicsInc/cesium/pull/8205) * Fix dynamic ellipsoids using `innerRadii`, `minimumClock`, `maximumClock`, `minimumCone` or `maximumCone`. [#8277](https://github.com/AnalyticalGraphicsInc/cesium/pull/8277) diff --git a/Source/Core/OrthographicFrustum.js b/Source/Core/OrthographicFrustum.js index 4f244abbbbde..be0a941eb616 100644 --- a/Source/Core/OrthographicFrustum.js +++ b/Source/Core/OrthographicFrustum.js @@ -1,7 +1,9 @@ +import Cartesian2 from './Cartesian2.js'; import Check from './Check.js'; import defaultValue from './defaultValue.js'; import defined from './defined.js'; import defineProperties from './defineProperties.js'; +import deprecationWarning from './deprecationWarning.js'; import DeveloperError from './DeveloperError.js'; import CesiumMath from './Math.js'; import OrthographicOffCenterFrustum from './OrthographicOffCenterFrustum.js'; @@ -200,20 +202,28 @@ import OrthographicOffCenterFrustum from './OrthographicOffCenterFrustum.js'; * @param {Number} drawingBufferWidth The width of the drawing buffer. * @param {Number} drawingBufferHeight The height of the drawing buffer. * @param {Number} distance The distance to the near plane in meters. + * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space. * @param {Cartesian2} result The object onto which to store the result. * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively. * * @exception {DeveloperError} drawingBufferWidth must be greater than zero. * @exception {DeveloperError} drawingBufferHeight must be greater than zero. + * @exception {DeveloperError} pixelRatio must be greater than zero. * * @example * // Example 1 * // Get the width and height of a pixel. - * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, new Cesium.Cartesian2()); + * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, scene.pixelRatio, new Cesium.Cartesian2()); */ - OrthographicFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, result) { + OrthographicFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) { update(this); - return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result); + + if (pixelRatio instanceof Cartesian2) { + result = pixelRatio; + pixelRatio = 1.0; + deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.'); + } + return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result); }; /** diff --git a/Source/Core/OrthographicOffCenterFrustum.js b/Source/Core/OrthographicOffCenterFrustum.js index 665f53783236..96d2eca200c0 100644 --- a/Source/Core/OrthographicOffCenterFrustum.js +++ b/Source/Core/OrthographicOffCenterFrustum.js @@ -1,9 +1,11 @@ +import Cartesian2 from './Cartesian2.js'; import Cartesian3 from './Cartesian3.js'; import Cartesian4 from './Cartesian4.js'; import CullingVolume from './CullingVolume.js'; import defaultValue from './defaultValue.js'; import defined from './defined.js'; import defineProperties from './defineProperties.js'; +import deprecationWarning from './deprecationWarning.js'; import DeveloperError from './DeveloperError.js'; import CesiumMath from './Math.js'; import Matrix4 from './Matrix4.js'; @@ -272,20 +274,28 @@ import Matrix4 from './Matrix4.js'; * @param {Number} drawingBufferWidth The width of the drawing buffer. * @param {Number} drawingBufferHeight The height of the drawing buffer. * @param {Number} distance The distance to the near plane in meters. + * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space. * @param {Cartesian2} result The object onto which to store the result. * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively. * * @exception {DeveloperError} drawingBufferWidth must be greater than zero. * @exception {DeveloperError} drawingBufferHeight must be greater than zero. + * @exception {DeveloperError} pixelRatio must be greater than zero. * * @example * // Example 1 * // Get the width and height of a pixel. - * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, new Cesium.Cartesian2()); + * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, scene.pixelRatio, new Cesium.Cartesian2()); */ - OrthographicOffCenterFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, result) { + OrthographicOffCenterFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) { update(this); + if (pixelRatio instanceof Cartesian2) { + result = pixelRatio; + pixelRatio = 1.0; + deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.'); + } + //>>includeStart('debug', pragmas.debug); if (!defined(drawingBufferWidth) || !defined(drawingBufferHeight)) { throw new DeveloperError('Both drawingBufferWidth and drawingBufferHeight are required.'); @@ -299,6 +309,12 @@ import Matrix4 from './Matrix4.js'; if (!defined(distance)) { throw new DeveloperError('distance is required.'); } + if (!defined(pixelRatio)) { + throw new DeveloperError('pixelRatio is required.'); + } + if (pixelRatio <= 0) { + throw new DeveloperError('pixelRatio must be greater than zero.'); + } if (!defined(result)) { throw new DeveloperError('A result object is required.'); } @@ -306,8 +322,8 @@ import Matrix4 from './Matrix4.js'; var frustumWidth = this.right - this.left; var frustumHeight = this.top - this.bottom; - var pixelWidth = frustumWidth / drawingBufferWidth; - var pixelHeight = frustumHeight / drawingBufferHeight; + var pixelWidth = pixelRatio * frustumWidth / drawingBufferWidth; + var pixelHeight = pixelRatio * frustumHeight / drawingBufferHeight; result.x = pixelWidth; result.y = pixelHeight; diff --git a/Source/Core/PerspectiveFrustum.js b/Source/Core/PerspectiveFrustum.js index 3db75b3c1c40..f16f8e34496b 100644 --- a/Source/Core/PerspectiveFrustum.js +++ b/Source/Core/PerspectiveFrustum.js @@ -1,7 +1,9 @@ +import Cartesian2 from './Cartesian2.js'; import Check from './Check.js'; import defaultValue from './defaultValue.js'; import defined from './defined.js'; import defineProperties from './defineProperties.js'; +import deprecationWarning from './deprecationWarning.js'; import DeveloperError from './DeveloperError.js'; import CesiumMath from './Math.js'; import PerspectiveOffCenterFrustum from './PerspectiveOffCenterFrustum.js'; @@ -284,16 +286,18 @@ import PerspectiveOffCenterFrustum from './PerspectiveOffCenterFrustum.js'; * @param {Number} drawingBufferWidth The width of the drawing buffer. * @param {Number} drawingBufferHeight The height of the drawing buffer. * @param {Number} distance The distance to the near plane in meters. + * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space. * @param {Cartesian2} result The object onto which to store the result. * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively. * * @exception {DeveloperError} drawingBufferWidth must be greater than zero. * @exception {DeveloperError} drawingBufferHeight must be greater than zero. + * @exception {DeveloperError} pixelRatio must be greater than zero. * * @example * // Example 1 * // Get the width and height of a pixel. - * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Cesium.Cartesian2()); + * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, scene.pixelRatio, new Cesium.Cartesian2()); * * @example * // Example 2 @@ -304,11 +308,18 @@ import PerspectiveOffCenterFrustum from './PerspectiveOffCenterFrustum.js'; * var toCenter = Cesium.Cartesian3.subtract(primitive.boundingVolume.center, position, new Cesium.Cartesian3()); // vector from camera to a primitive * var toCenterProj = Cesium.Cartesian3.multiplyByScalar(direction, Cesium.Cartesian3.dot(direction, toCenter), new Cesium.Cartesian3()); // project vector onto camera direction vector * var distance = Cesium.Cartesian3.magnitude(toCenterProj); - * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Cesium.Cartesian2()); + * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, scene.pixelRatio, new Cesium.Cartesian2()); */ - PerspectiveFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, result) { + PerspectiveFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) { update(this); - return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result); + + if (pixelRatio instanceof Cartesian2) { + result = pixelRatio; + pixelRatio = 1.0; + deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.'); + } + + return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result); }; /** diff --git a/Source/Core/PerspectiveOffCenterFrustum.js b/Source/Core/PerspectiveOffCenterFrustum.js index e3ef72cad7d4..7e716bc8cc83 100644 --- a/Source/Core/PerspectiveOffCenterFrustum.js +++ b/Source/Core/PerspectiveOffCenterFrustum.js @@ -1,9 +1,11 @@ +import Cartesian2 from './Cartesian2.js'; import Cartesian3 from './Cartesian3.js'; import Cartesian4 from './Cartesian4.js'; import CullingVolume from './CullingVolume.js'; import defaultValue from './defaultValue.js'; import defined from './defined.js'; import defineProperties from './defineProperties.js'; +import deprecationWarning from './deprecationWarning.js'; import DeveloperError from './DeveloperError.js'; import CesiumMath from './Math.js'; import Matrix4 from './Matrix4.js'; @@ -311,16 +313,18 @@ import Matrix4 from './Matrix4.js'; * @param {Number} drawingBufferWidth The width of the drawing buffer. * @param {Number} drawingBufferHeight The height of the drawing buffer. * @param {Number} distance The distance to the near plane in meters. + * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space. * @param {Cartesian2} result The object onto which to store the result. * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively. * * @exception {DeveloperError} drawingBufferWidth must be greater than zero. * @exception {DeveloperError} drawingBufferHeight must be greater than zero. + * @exception {DeveloperError} pixelRatio must be greater than zero. * * @example * // Example 1 * // Get the width and height of a pixel. - * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Cesium.Cartesian2()); + * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, scene.pixelRatio, new Cesium.Cartesian2()); * * @example * // Example 2 @@ -331,11 +335,17 @@ import Matrix4 from './Matrix4.js'; * var toCenter = Cesium.Cartesian3.subtract(primitive.boundingVolume.center, position, new Cesium.Cartesian3()); // vector from camera to a primitive * var toCenterProj = Cesium.Cartesian3.multiplyByScalar(direction, Cesium.Cartesian3.dot(direction, toCenter), new Cesium.Cartesian3()); // project vector onto camera direction vector * var distance = Cesium.Cartesian3.magnitude(toCenterProj); - * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Cesium.Cartesian2()); + * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, scene.pixelRatio, new Cesium.Cartesian2()); */ - PerspectiveOffCenterFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, result) { + PerspectiveOffCenterFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) { update(this); + if (pixelRatio instanceof Cartesian2) { + result = pixelRatio; + pixelRatio = 1.0; + deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.'); + } + //>>includeStart('debug', pragmas.debug); if (!defined(drawingBufferWidth) || !defined(drawingBufferHeight)) { throw new DeveloperError('Both drawingBufferWidth and drawingBufferHeight are required.'); @@ -349,6 +359,12 @@ import Matrix4 from './Matrix4.js'; if (!defined(distance)) { throw new DeveloperError('distance is required.'); } + if (!defined(pixelRatio)) { + throw new DeveloperError('pixelRatio is required'); + } + if (pixelRatio <= 0) { + throw new DeveloperError('pixelRatio must be greater than zero.'); + } if (!defined(result)) { throw new DeveloperError('A result object is required.'); } @@ -356,9 +372,9 @@ import Matrix4 from './Matrix4.js'; var inverseNear = 1.0 / this.near; var tanTheta = this.top * inverseNear; - var pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight; + var pixelHeight = 2.0 * pixelRatio * distance * tanTheta / drawingBufferHeight; tanTheta = this.right * inverseNear; - var pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth; + var pixelWidth = 2.0 * pixelRatio * distance * tanTheta / drawingBufferWidth; result.x = pixelWidth; result.y = pixelHeight; diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index a741b6ede934..ed43698b6ed0 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2652,7 +2652,7 @@ import SceneMode from './SceneMode.js'; //>>includeEnd('debug'); var distance = this.distanceToBoundingSphere(boundingSphere); - var pixelSize = this.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, scratchPixelSize); + var pixelSize = this.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, this._scene.pixelRatio, scratchPixelSize); return Math.max(pixelSize.x, pixelSize.y); }; diff --git a/Source/Scene/Picking.js b/Source/Scene/Picking.js index 2a2b7c88e841..6ffc2065212d 100644 --- a/Source/Scene/Picking.js +++ b/Source/Scene/Picking.js @@ -108,7 +108,7 @@ import View from './View.js'; Cartesian3.fromElements(origin.z, origin.x, origin.y, origin); } - var pixelSize = frustum.getPixelDimensions(viewport.width, viewport.height, 1.0, scratchOrthoPixelSize); + var pixelSize = frustum.getPixelDimensions(viewport.width, viewport.height, 1.0, 1.0, scratchOrthoPixelSize); var ortho = scratchOrthoPickingFrustum; ortho.right = pixelSize.x * 0.5; @@ -138,7 +138,7 @@ import View from './View.js'; var xDir = x * near * tanTheta; var yDir = y * near * tanPhi; - var pixelSize = frustum.getPixelDimensions(viewport.width, viewport.height, 1.0, scratchPerspPixelSize); + var pixelSize = frustum.getPixelDimensions(viewport.width, viewport.height, 1.0, 1.0, scratchPerspPixelSize); var pickWidth = pixelSize.x * width * 0.5; var pickHeight = pixelSize.y * height * 0.5; diff --git a/Specs/Core/OrthographicFrustumSpec.js b/Specs/Core/OrthographicFrustumSpec.js index 640a49e5d5b6..a4bcb6e2d70b 100644 --- a/Specs/Core/OrthographicFrustumSpec.js +++ b/Specs/Core/OrthographicFrustumSpec.js @@ -139,32 +139,58 @@ describe('Core/OrthographicFrustum', function() { it('get pixel dimensions throws without canvas height', function() { expect(function() { - return frustum.getPixelDimensions(1.0, undefined, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(1.0, undefined, 0.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws without canvas width', function() { expect(function() { - return frustum.getPixelDimensions(undefined, 1.0, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(undefined, 1.0, 0.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws with canvas width less than or equal to zero', function() { expect(function() { - return frustum.getPixelDimensions(0.0, 1.0, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(0.0, 1.0, 0.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws with canvas height less than or equal to zero', function() { expect(function() { - return frustum.getPixelDimensions(1.0, 0.0, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(1.0, 0.0, 0.0, 1.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws without pixel ratio', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 0.0, undefined, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws with pixel ratio less than or equal to zero', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 0.0, 0.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions', function() { - var pixelSize = frustum.getPixelDimensions(1.0, 1.0, 0.0, new Cartesian2()); - expect(pixelSize.x).toEqual(2.0); - expect(pixelSize.y).toEqual(2.0); + var dimensions = new Cartesian2(1.0, 1.0); + var pixelRatio = 1.0; + var distance = 1.0; + var pixelSize = frustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); + var expected = frustum._offCenterFrustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); + expect(pixelSize.x).toEqual(expected.x); + expect(pixelSize.y).toEqual(expected.y); + }); + + it('get pixel dimensions with pixel ratio', function() { + var dimensions = new Cartesian2(1.0, 1.0); + var pixelRatio = 2.0; + var distance = 1.0; + var pixelSize = frustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); + var expected = frustum._offCenterFrustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); + expect(pixelSize.x).toEqual(expected.x); + expect(pixelSize.y).toEqual(expected.y); }); it('equals', function() { diff --git a/Specs/Core/OrthographicOffCenterFrustumSpec.js b/Specs/Core/OrthographicOffCenterFrustumSpec.js index b9ce9dd12b05..497ea8c5b0d4 100644 --- a/Specs/Core/OrthographicOffCenterFrustumSpec.js +++ b/Specs/Core/OrthographicOffCenterFrustumSpec.js @@ -141,34 +141,52 @@ describe('Core/OrthographicOffCenterFrustum', function() { it('get pixel dimensions throws without canvas height', function() { expect(function() { - return frustum.getPixelDimensions(1.0, undefined, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(1.0, undefined, 0.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws without canvas width', function() { expect(function() { - return frustum.getPixelDimensions(undefined, 1.0, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(undefined, 1.0, 0.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws with canvas width less than or equal to zero', function() { expect(function() { - return frustum.getPixelDimensions(0.0, 1.0, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(0.0, 1.0, 0.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws with canvas height less than or equal to zero', function() { expect(function() { - return frustum.getPixelDimensions(1.0, 0.0, 0.0, new Cartesian2()); + return frustum.getPixelDimensions(1.0, 0.0, 0.0, 1.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws without pixel ratio', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 0.0, undefined, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws with pixel ratio less than or equal to zero', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 0.0, 0.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions', function() { - var pixelSize = frustum.getPixelDimensions(1.0, 1.0, 0.0, new Cartesian2()); + var pixelSize = frustum.getPixelDimensions(1.0, 1.0, 0.0, 1.0, new Cartesian2()); expect(pixelSize.x).toEqual(2.0); expect(pixelSize.y).toEqual(2.0); }); + it('get pixel dimensions with pixel ratio', function() { + var pixelSize = frustum.getPixelDimensions(1.0, 1.0, 0.0, 2.0, new Cartesian2()); + expect(pixelSize.x).toEqual(4.0); + expect(pixelSize.y).toEqual(4.0); + }); + it('equals', function() { var frustum2 = new OrthographicOffCenterFrustum(); frustum2.near = 1.0; diff --git a/Specs/Core/PerspectiveFrustumSpec.js b/Specs/Core/PerspectiveFrustumSpec.js index fe4252becf6c..11bdafe3963f 100644 --- a/Specs/Core/PerspectiveFrustumSpec.js +++ b/Specs/Core/PerspectiveFrustumSpec.js @@ -155,10 +155,58 @@ describe('Core/PerspectiveFrustum', function() { expect(frustum.infiniteProjectionMatrix).toEqual(expected); }); + it('get pixel dimensions throws without canvas height', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, undefined, 1.0, 1.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws without canvas width', function() { + expect(function() { + return frustum.getPixelDimensions(undefined, 1.0, 1.0, 1.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws with canvas width less than or equal to zero', function() { + expect(function() { + return frustum.getPixelDimensions(0.0, 1.0, 1.0, 1.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws with canvas height less than or equal to zero', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 0.0, 1.0, 1.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws without pixel ratio', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 1.0, undefined, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws with pixel ratio less than or equal to zero', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 1.0, 0.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + it('get pixel dimensions', function() { var dimensions = new Cartesian2(1.0, 1.0); - var pixelSize = frustum.getPixelDimensions(dimensions.x, dimensions.y, 1.0, new Cartesian2()); - var expected = frustum._offCenterFrustum.getPixelDimensions(dimensions.x, dimensions.y, 1.0, new Cartesian2()); + var pixelRatio = 1.0; + var distance = 1.0; + var pixelSize = frustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); + var expected = frustum._offCenterFrustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); + expect(pixelSize.x).toEqual(expected.x); + expect(pixelSize.y).toEqual(expected.y); + }); + + it('get pixel dimensions with pixel ratio', function() { + var dimensions = new Cartesian2(1.0, 1.0); + var pixelRatio = 2.0; + var distance = 1.0; + var pixelSize = frustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); + var expected = frustum._offCenterFrustum.getPixelDimensions(dimensions.x, dimensions.y, distance, pixelRatio, new Cartesian2()); expect(pixelSize.x).toEqual(expected.x); expect(pixelSize.y).toEqual(expected.y); }); diff --git a/Specs/Core/PerspectiveOffCenterFrustumSpec.js b/Specs/Core/PerspectiveOffCenterFrustumSpec.js index 34d37f7be232..f54c559d0d92 100644 --- a/Specs/Core/PerspectiveOffCenterFrustumSpec.js +++ b/Specs/Core/PerspectiveOffCenterFrustumSpec.js @@ -145,34 +145,52 @@ describe('Core/PerspectiveOffCenterFrustum', function() { it('get pixel dimensions throws without canvas height', function() { expect(function() { - return frustum.getPixelDimensions(1.0, undefined, 1.0, new Cartesian2()); + return frustum.getPixelDimensions(1.0, undefined, 1.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws without canvas width', function() { expect(function() { - return frustum.getPixelDimensions(undefined, 1.0, 1.0, new Cartesian2()); + return frustum.getPixelDimensions(undefined, 1.0, 1.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws with canvas width less than or equal to zero', function() { expect(function() { - return frustum.getPixelDimensions(0.0, 1.0, 1.0, new Cartesian2()); + return frustum.getPixelDimensions(0.0, 1.0, 1.0, 1.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions throws with canvas height less than or equal to zero', function() { expect(function() { - return frustum.getPixelDimensions(1.0, 0.0, 1.0, new Cartesian2()); + return frustum.getPixelDimensions(1.0, 0.0, 1.0, 1.0, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws without pixel ratio', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 1.0, undefined, new Cartesian2()); + }).toThrowDeveloperError(); + }); + + it('get pixel dimensions throws with pixel ratio less than or equal to zero', function() { + expect(function() { + return frustum.getPixelDimensions(1.0, 1.0, 1.0, 0.0, new Cartesian2()); }).toThrowDeveloperError(); }); it('get pixel dimensions', function() { - var pixelSize = frustum.getPixelDimensions(1.0, 1.0, 1.0, new Cartesian2()); + var pixelSize = frustum.getPixelDimensions(1.0, 1.0, 1.0, 1.0, new Cartesian2()); expect(pixelSize.x).toEqual(2.0); expect(pixelSize.y).toEqual(2.0); }); + it('get pixel dimensions with pixel ratio', function() { + var pixelSize = frustum.getPixelDimensions(1.0, 1.0, 1.0, 2.0, new Cartesian2()); + expect(pixelSize.x).toEqual(4.0); + expect(pixelSize.y).toEqual(4.0); + }); + it('equals', function() { var frustum2 = new PerspectiveOffCenterFrustum(); frustum2.right = 1.0; diff --git a/Specs/Scene/BillboardCollectionSpec.js b/Specs/Scene/BillboardCollectionSpec.js index 64eb0db0aeaa..01883c67f838 100644 --- a/Specs/Scene/BillboardCollectionSpec.js +++ b/Specs/Scene/BillboardCollectionSpec.js @@ -1451,7 +1451,7 @@ describe('Scene/BillboardCollection', function() { var vectorProjection = Cartesian3.multiplyByScalar(camera.direction, Cartesian3.dot(diff, camera.direction), new Cartesian3()); var distance = Math.max(0.0, Cartesian3.magnitude(vectorProjection) - bs.radius); - var pixelSize = camera.frustum.getPixelDimensions(dimensions.x, dimensions.y, distance, new Cartesian2()); + var pixelSize = camera.frustum.getPixelDimensions(dimensions.x, dimensions.y, distance, scene.pixelRatio, new Cartesian2()); bs.radius += pixelSize.y * 0.25 * Math.max(greenImage.width, greenImage.height) + pixelSize.y * one.pixelOffset.y; expect(actual.center).toEqual(bs.center); diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index c3ecaa73b074..581363eab74a 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -2767,6 +2767,9 @@ describe('Scene/Camera', function() { it('getPixelSize', function() { scene.mode = SceneMode.SCENE3D; + var oldPixelRatio = scene.pixelRatio; + scene.pixelRatio = 1.0; + var sphere = new BoundingSphere(Cartesian3.ZERO, 0.5); var context = scene.context; var drawingBufferWidth = context.drawingBufferWidth; @@ -2774,11 +2777,13 @@ describe('Scene/Camera', function() { // Compute expected pixel size var distance = camera.distanceToBoundingSphere(sphere); - var pixelDimensions = camera.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, new Cartesian2()); + var pixelDimensions = camera.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, scene.pixelRatio, new Cartesian2()); var expectedPixelSize = Math.max(pixelDimensions.x, pixelDimensions.y); var pixelSize = camera.getPixelSize(sphere, drawingBufferWidth, drawingBufferHeight); expect(pixelSize).toEqual(expectedPixelSize); + + scene.pixelRatio = oldPixelRatio; }); it('getPixelSize throws when there is no bounding sphere', function() {