From 1f3967076a87823f404a2667eb142db3026aafc7 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 14 Feb 2018 16:54:23 -0500 Subject: [PATCH 1/2] Added Cesium.Math.cbrt --- CHANGES.md | 1 + Source/Core/Math.js | 14 ++++++++++++++ Source/Scene/PointCloud3DTileContent.js | 4 +++- Specs/Core/MathSpec.js | 8 ++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 0eea3f775bc5..3e264490c586 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log ##### Additions :tada: * Added support for a promise to a resource for `CesiumTerrainProvider`, `createTileMapServiceImageryProvider` and `Cesium3DTileset` [#6204](https://github.com/AnalyticalGraphicsInc/cesium/pull/6204) +* Added `Cesium.Math.cbrt`. ##### Fixes :wrench: * Fixed bug where AxisAlignedBoundingBox did not copy over center value when cloning an undefined result. [#6183](https://github.com/AnalyticalGraphicsInc/cesium/pull/6183) diff --git a/Source/Core/Math.js b/Source/Core/Math.js index 3c90ed58b95c..174889ce7c48 100644 --- a/Source/Core/Math.js +++ b/Source/Core/Math.js @@ -835,6 +835,20 @@ define([ return Math.log(number) / Math.log(base); }; + function cbrt(number) { + var result = Math.pow(Math.abs(number), 1.0 / 3.0); + return number < 0.0 ? -result : result; + } + + /** + * Finds the cube root of a number. + * Returns NaN if number is not provided. + * + * @param {Number} [number] The number. + * @returns {Number} The result. + */ + CesiumMath.cbrt = defined(Math.cbrt) ? Math.cbrt : cbrt; + /** * @private */ diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index 7fbc50ceb4a8..4941ee3240af 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -13,6 +13,7 @@ define([ '../Core/DeveloperError', '../Core/FeatureDetection', '../Core/getStringFromTypedArray', + '../Core/Math', '../Core/Matrix3', '../Core/Matrix4', '../Core/oneTimeWarning', @@ -51,6 +52,7 @@ define([ DeveloperError, FeatureDetection, getStringFromTypedArray, + CesiumMath, Matrix3, Matrix4, oneTimeWarning, @@ -466,7 +468,7 @@ define([ // Typical use case is leaves, where lower estimates of interpoint distance might // lead to underattenuation. var sphereVolume = content._tile.contentBoundingVolume.boundingSphere.volume(); - content._baseResolutionApproximation = Math.pow(sphereVolume / pointsLength, 1/3); // IE doesn't support cbrt + content._baseResolutionApproximation = CesiumMath.cbrt(sphereVolume / pointsLength); } var scratchPointSizeAndTilesetTimeAndGeometricErrorAndDepthMultiplier = new Cartesian4(); diff --git a/Specs/Core/MathSpec.js b/Specs/Core/MathSpec.js index 30dd0c169df9..26a4e1b523ed 100644 --- a/Specs/Core/MathSpec.js +++ b/Specs/Core/MathSpec.js @@ -434,4 +434,12 @@ defineSuite([ CesiumMath.logBase(64, undefined); }).toThrowDeveloperError(); }); + + it('cbrt', function() { + expect(CesiumMath.cbrt(27.0)).toEqual(3.0); + expect(CesiumMath.cbrt(-27.0)).toEqual(-3.0); + expect(CesiumMath.cbrt(0.0)).toEqual(0.0); + expect(CesiumMath.cbrt(1.0)).toEqual(1.0); + expect(CesiumMath.cbrt()).toEqual(NaN); + }); }); From 153c1f743d3f2667db8e46703d0b1ebfcb665f54 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 14 Feb 2018 17:02:32 -0500 Subject: [PATCH 2/2] Updated CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 3e264490c586..123cc4b0cf7a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Change Log ##### Additions :tada: * Added support for a promise to a resource for `CesiumTerrainProvider`, `createTileMapServiceImageryProvider` and `Cesium3DTileset` [#6204](https://github.com/AnalyticalGraphicsInc/cesium/pull/6204) -* Added `Cesium.Math.cbrt`. +* Added `Cesium.Math.cbrt`. [#6222](https://github.com/AnalyticalGraphicsInc/cesium/pull/6222) ##### Fixes :wrench: * Fixed bug where AxisAlignedBoundingBox did not copy over center value when cloning an undefined result. [#6183](https://github.com/AnalyticalGraphicsInc/cesium/pull/6183)