Skip to content

Commit

Permalink
chore: ECMAScript 2016, replace Math.pow by exponentiation operator (**)
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Dec 4, 2018
1 parent d25b9fa commit 5562ccd
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'eslint-config-airbnb-base/rules/strict',
],
parserOptions: {
ecmaVersion: 6,
ecmaVersion: 7,
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/GlobeControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function GlobeControls(view, targetCoordinate, range, globeRadius, options = {})
};

this.getDollyScale = function getDollyScale() {
return Math.pow(0.95, this.zoomSpeed);
return 0.95 ** this.zoomSpeed;
};

this.rotateLeft = function rotateLeft(angle = 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/PlanarControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ function onContextMenu(event) {
function smooth(value) {
// p between 1.0 and 1.5 (empirical)
const p = 1.20;
return Math.pow((value * value * (3 - 2 * value)), p);
return (value ** 2 * (3 - 2 * value)) ** p;
}

export default PlanarControls;
10 changes: 5 additions & 5 deletions src/Core/Geographic/Extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Extent.prototype.as = function as(crs) {
if (this.isTiledCrs()) {
if (this._crs == 'WMTS:PM' || this._crs == 'TMS') {
// Convert this to the requested crs by using 4326 as an intermediate state.
const nbCol = Math.pow(2, this.zoom);
const nbCol = 2 ** this.zoom;
const nbRow = nbCol;
const sizeRow = 1.0 / nbRow;
// convert row PM to Y PM
Expand Down Expand Up @@ -120,7 +120,7 @@ Extent.prototype.as = function as(crs) {
}
}
} else if (this._crs == 'WMTS:WGS84G' && crs == 'EPSG:4326') {
const nbRow = Math.pow(2, this.zoom);
const nbRow = 2 ** this.zoom;
const size = 180 / nbRow;
const north = size * (nbRow - this.row) - 90;
const south = size * (nbRow - (this.row + 1)) - 90;
Expand Down Expand Up @@ -177,7 +177,7 @@ Extent.prototype.offsetToParent = function offsetToParent(other, target = new TH
}
if (this.isTiledCrs()) {
const diffLevel = this.zoom - other.zoom;
const diff = Math.pow(2, diffLevel);
const diff = 2 ** diffLevel;
const invDiff = 1 / diff;

const r = (this.row - (this.row % diff)) * invDiff;
Expand Down Expand Up @@ -286,7 +286,7 @@ Extent.prototype.isInside = function isInside(other, epsilon) {
return false;
} else {
const diffLevel = this.zoom - other.zoom;
const diff = Math.pow(2, diffLevel);
const diff = 2 ** diffLevel;
const invDiff = 1 / diff;

const r = (this.row - (this.row % diff)) * invDiff;
Expand Down Expand Up @@ -433,7 +433,7 @@ Extent.prototype.extentParent = function extentParent(levelParent) {
if (this.isTiledCrs()) {
if (levelParent && levelParent < this.zoom) {
const diffLevel = this.zoom - levelParent;
const diff = Math.pow(2, diffLevel);
const diff = 2 ** diffLevel;
const invDiff = 1 / diff;

const r = (this.row - (this.row % diff)) * invDiff;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Geographic/Projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Projection = {
var zoom = Math.floor(
Math.log(Math.PI / MathExt.degToRad(dim.y)) / LOG_TWO + 0.5);

var nY = Math.pow(2, zoom);
var nY = 2 ** zoom;
var nX = 2 * nY;

var uX = Math.PI * 2 / nX;
Expand All @@ -83,7 +83,7 @@ const Projection = {
function WMTS_WGS84ToWMTS_PM(cWMTS, bbox) {
var wmtsBox = [];
var level = cWMTS.zoom + 1;
var nbRow = Math.pow(2, level);
var nbRow = 2 ** level;

var sizeRow = 1.0 / nbRow;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function screenCoordsToNodeId(view, tileLayer, viewCoords, radius) {
const idx = (y * 2 * radius + x) * 4;
const data = buffer.slice(idx, idx + 4);
depthRGBA.fromArray(data).divideScalar(255.0);
const unpack = unpack1K(depthRGBA, Math.pow(256, 3));
const unpack = unpack1K(depthRGBA, 256 ** 3);

const _id = Math.round(unpack);
if (ids.indexOf(_id) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Prefab/Globe/Atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Atmosphere.prototype._initRealisticLighning = function _initRealisticLighning()

var uniformsSky = {
v3LightPosition: { value: LIGHTING_POSITION.clone().normalize() },
v3InvWavelength: { value: new THREE.Vector3(1 / Math.pow(atmosphere.wavelength[0], 4), 1 / Math.pow(atmosphere.wavelength[1], 4), 1 / Math.pow(atmosphere.wavelength[2], 4)) },
v3InvWavelength: { value: new THREE.Vector3(1 / atmosphere.wavelength[0] ** 4, 1 / atmosphere.wavelength[1] ** 4, 1 / atmosphere.wavelength[2] ** 4) },
fCameraHeight: { value: 0.0 },
fCameraHeight2: { value: 0.0 },
fInnerRadius: { value: atmosphere.innerRadius },
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Prefab/Globe/BuilderEllipsoidTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ BuilderEllipsoidTile.prototype.constructor = BuilderEllipsoidTile;
// init projected object -> params.projected

BuilderEllipsoidTile.prototype.Prepare = function Prepare(params) {
params.nbRow = Math.pow(2.0, params.level + 1.0);
params.nbRow = 2 ** (params.level + 1.0);

var st1 = WGS84ToOneSubY(params.extent.south());

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Prefab/Globe/GlobeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class GlobeLayer extends TiledGeometryLayer {
1 / ellipsoidSizes.y,
1 / ellipsoidSizes.z));

subdivisionRatio = 1 / Math.pow(2, this.maxDeltaElevationLevel);
subdivisionRatio = 1 / 2 ** this.maxDeltaElevationLevel;
}

preUpdate(context, changeSources) {
Expand Down Expand Up @@ -202,7 +202,7 @@ class GlobeLayer extends TiledGeometryLayer {
let sinus = distance * preSinus;
let zoom = Math.log(Math.PI / (2.0 * Math.asin(sinus))) / Math.log(2);

const delta = Math.PI / Math.pow(2, zoom);
const delta = Math.PI / 2 ** zoom;
const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
const radius = circleChord * 0.5;

Expand All @@ -214,7 +214,7 @@ class GlobeLayer extends TiledGeometryLayer {
}

computeDistanceCameraFromTileZoom(zoom, camera) {
const delta = Math.PI / Math.pow(2, zoom);
const delta = Math.PI / 2 ** zoom;
const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
const radius = circleChord * 0.5;
const error = radius / SIZE_TEXTURE_TILE;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Prefab/GlobeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function GlobeView(viewerDiv, coordCarto, options = {}) {

// Compute fog distance, this function makes it possible to have a shorter distance
// when the camera approaches the ground
this.fogDistance = mfogDistance * Math.pow((len - ellipsoidSizes.x * 0.99) * 0.25 / ellipsoidSizes.x, 1.5);
this.fogDistance = mfogDistance * ((len - ellipsoidSizes.x * 0.99) * 0.25 / ellipsoidSizes.x) ** 1.5;

// get altitude camera
coordCam.set(this.referenceCrs, this.camera.camera3D.position).as('EPSG:4326', coordGeoCam);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Prefab/Planar/PlanarLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PlanarLayer extends TiledGeometryLayer {
const offsetScale = nodeLayer.offsetScales[0];
const ratio = offsetScale.z;
// ratio is node size / texture size
if (ratio < 1 / Math.pow(2, maxDeltaElevationLevel)) {
if (ratio < 1 / (2 ** maxDeltaElevationLevel)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Prefab/Planar/PlanarTileBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PlanarTileBuilder.prototype.constructor = PlanarTileBuilder;
// prepare params
// init projected object -> params.projected
PlanarTileBuilder.prototype.Prepare = function Prepare(params) {
params.nbRow = Math.pow(2.0, params.zoom + 1.0);
params.nbRow = 2 ** (params.zoom + 1.0);
params.projected = new THREE.Vector3();
};

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/VectorTileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function project(line, ox, oy, size) {
}

function toGeoJSON(x, y, z) {
const size = this.extent * Math.pow(2, z);
const size = this.extent * 2 ** z;
const x0 = this.extent * x;
const y0 = this.extent * y;
let coords = this.loadGeometry();
Expand Down
2 changes: 1 addition & 1 deletion src/Process/PointCloudProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function computeScreenSpaceError(context, layer, elt, distance) {
if (distance <= 0) {
return Infinity;
}
const pointSpacing = layer.metadata.spacing / Math.pow(2, elt.name.length);
const pointSpacing = layer.metadata.spacing / 2 ** elt.name.length;
// Estimate the onscreen distance between 2 points
const onScreenSpacing = context.camera.preSSE * pointSpacing / distance;
// [ P1 ]--------------[ P2 ]
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/c3DEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ c3DEngine.prototype.depthBufferRGBAValueToOrthoZ = function depthBufferRGBAValue
const gl_FragDepthEXT = unpack1K(depthRGBA);
const logDepthBufFC = 2.0 / (Math.log(camera.far + 1.0) / Math.LN2);
// invert function : gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;
return Math.pow(2.0, 2.0 * gl_FragDepthEXT / logDepthBufFC);
return 2 ** (2 * gl_FragDepthEXT / logDepthBufFC);
} else {
let gl_FragCoord_Z = unpack1K(depthRGBA);
gl_FragCoord_Z = gl_FragCoord_Z * 2.0 - 1.0;
Expand Down

0 comments on commit 5562ccd

Please sign in to comment.