Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Cesium.Math.cbrt #6222

Merged
merged 3 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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`. [#6222](https://github.com/AnalyticalGraphicsInc/cesium/pull/6222)
* `Resource` class [#6205](https://github.com/AnalyticalGraphicsInc/cesium/issues/6205)
* Added `put`, `patch`, `delete`, `options` and `head` methods, so it can be used for all XHR requests.
* Added `preserveQueryParameters` parameter to `getDerivedResource`, to allow us to append query parameters instead of always replacing them.
Expand Down
14 changes: 14 additions & 0 deletions Source/Core/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>number</code> is not provided.
*
* @param {Number} [number] The number.
* @returns {Number} The result.
*/
CesiumMath.cbrt = defined(Math.cbrt) ? Math.cbrt : cbrt;

/**
* @private
*/
Expand Down
4 changes: 3 additions & 1 deletion Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define([
'../Core/DeveloperError',
'../Core/FeatureDetection',
'../Core/getStringFromTypedArray',
'../Core/Math',
'../Core/Matrix3',
'../Core/Matrix4',
'../Core/oneTimeWarning',
Expand Down Expand Up @@ -51,6 +52,7 @@ define([
DeveloperError,
FeatureDetection,
getStringFromTypedArray,
CesiumMath,
Matrix3,
Matrix4,
oneTimeWarning,
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions Specs/Core/MathSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});