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

Ecma script 2016 #932

Merged
merged 2 commits into from
Dec 4, 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
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
6 changes: 3 additions & 3 deletions src/Core/Picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ 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) {
if (!ids.includes(_id)) {
ids.push(_id);
}
});
Expand Down Expand Up @@ -120,7 +120,7 @@ export default {
const _ids = screenCoordsToNodeId(_view, layer, viewCoords, radius);

const extractResult = (node) => {
if (_ids.indexOf(node.id) >= 0 && node instanceof TileMesh) {
if (_ids.includes(node.id) && node instanceof TileMesh) {
results.push({
object: node,
layer,
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/Core/System/Capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function _WebGLShader(renderer, type, string) {
}

function isFirefox() {
return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().includes('firefox');
}

export default {
Expand Down
5 changes: 2 additions & 3 deletions src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ View.prototype.addLayer = function addLayer(layer, parentLayer) {
layer.whenReady.then((layer) => {
this.notifyChange(parentLayer || layer, false);
if (!this._frameRequesters[MAIN_LOOP_EVENTS.UPDATE_END] ||
this._frameRequesters[MAIN_LOOP_EVENTS.UPDATE_END].indexOf(this._allLayersAreReadyCallback) == -1) {
!this._frameRequesters[MAIN_LOOP_EVENTS.UPDATE_END].includes(this._allLayersAreReadyCallback)) {
this.addFrameRequester(MAIN_LOOP_EVENTS.UPDATE_END, this._allLayersAreReadyCallback);
}
resolve(layer);
Expand Down Expand Up @@ -452,8 +452,7 @@ View.prototype.addFrameRequester = function addFrameRequester(when, frameRequest
* @param {FrameRequester} frameRequester
*/
View.prototype.removeFrameRequester = function removeFrameRequester(when, frameRequester) {
const index = this._frameRequesters[when].indexOf(frameRequester);
if (index >= 0) {
if (this._frameRequesters[when].includes(frameRequester)) {
this._delayedFrameRequesterRemoval.push({ when, frameRequester });
} else {
console.error('Invalid call to removeFrameRequester: frameRequester isn\'t registered');
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/B3dmParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function filterUnsupportedSemantics(obj) {
}
for (const name of names) {
const semantic = obj.gltfShader.boundUniforms[name].semantic;
if (supported.indexOf(semantic) < 0) {
if (!supported.includes(semantic)) {
delete obj.gltfShader.boundUniforms[name];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/GeoJsonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function readFeature(crsIn, crsOut, json, filteringExtent, options, featureMerge

// copy other properties
for (const key of Object.keys(json)) {
if (keyProperties.indexOf(key.toLowerCase()) < 0) {
if (!keyProperties.includes(key.toLowerCase())) {
properties[key] = json[key];
}
}
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
4 changes: 2 additions & 2 deletions src/Renderer/Shader/ShaderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const reMain = new RegExp('[^\\w]*main[^\\w]*(void)?[^\\w]*{');
export default {
patchMaterialForLogDepthSupport(material) {
// Check if the shader does not already use the log depth buffer
if (material.vertexShader.indexOf('USE_LOGDEPTHBUF') !== -1
|| material.vertexShader.indexOf('logdepthbuf_pars_vertex') !== -1) {
if (material.vertexShader.includes('USE_LOGDEPTHBUF')
|| material.vertexShader.includes('logdepthbuf_pars_vertex')) {
return;
}

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