Skip to content

Commit 1f39670

Browse files
committed
Added Cesium.Math.cbrt
1 parent 1372cd1 commit 1f39670

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change Log
55

66
##### Additions :tada:
77
* Added support for a promise to a resource for `CesiumTerrainProvider`, `createTileMapServiceImageryProvider` and `Cesium3DTileset` [#6204](https://github.com/AnalyticalGraphicsInc/cesium/pull/6204)
8+
* Added `Cesium.Math.cbrt`.
89

910
##### Fixes :wrench:
1011
* Fixed bug where AxisAlignedBoundingBox did not copy over center value when cloning an undefined result. [#6183](https://github.com/AnalyticalGraphicsInc/cesium/pull/6183)

Source/Core/Math.js

+14
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,20 @@ define([
835835
return Math.log(number) / Math.log(base);
836836
};
837837

838+
function cbrt(number) {
839+
var result = Math.pow(Math.abs(number), 1.0 / 3.0);
840+
return number < 0.0 ? -result : result;
841+
}
842+
843+
/**
844+
* Finds the cube root of a number.
845+
* Returns NaN if <code>number</code> is not provided.
846+
*
847+
* @param {Number} [number] The number.
848+
* @returns {Number} The result.
849+
*/
850+
CesiumMath.cbrt = defined(Math.cbrt) ? Math.cbrt : cbrt;
851+
838852
/**
839853
* @private
840854
*/

Source/Scene/PointCloud3DTileContent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ define([
1313
'../Core/DeveloperError',
1414
'../Core/FeatureDetection',
1515
'../Core/getStringFromTypedArray',
16+
'../Core/Math',
1617
'../Core/Matrix3',
1718
'../Core/Matrix4',
1819
'../Core/oneTimeWarning',
@@ -51,6 +52,7 @@ define([
5152
DeveloperError,
5253
FeatureDetection,
5354
getStringFromTypedArray,
55+
CesiumMath,
5456
Matrix3,
5557
Matrix4,
5658
oneTimeWarning,
@@ -466,7 +468,7 @@ define([
466468
// Typical use case is leaves, where lower estimates of interpoint distance might
467469
// lead to underattenuation.
468470
var sphereVolume = content._tile.contentBoundingVolume.boundingSphere.volume();
469-
content._baseResolutionApproximation = Math.pow(sphereVolume / pointsLength, 1/3); // IE doesn't support cbrt
471+
content._baseResolutionApproximation = CesiumMath.cbrt(sphereVolume / pointsLength);
470472
}
471473

472474
var scratchPointSizeAndTilesetTimeAndGeometricErrorAndDepthMultiplier = new Cartesian4();

Specs/Core/MathSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,12 @@ defineSuite([
434434
CesiumMath.logBase(64, undefined);
435435
}).toThrowDeveloperError();
436436
});
437+
438+
it('cbrt', function() {
439+
expect(CesiumMath.cbrt(27.0)).toEqual(3.0);
440+
expect(CesiumMath.cbrt(-27.0)).toEqual(-3.0);
441+
expect(CesiumMath.cbrt(0.0)).toEqual(0.0);
442+
expect(CesiumMath.cbrt(1.0)).toEqual(1.0);
443+
expect(CesiumMath.cbrt()).toEqual(NaN);
444+
});
437445
});

0 commit comments

Comments
 (0)