Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f681060

Browse files
zarovgchoqueux
authored andcommitted
refactor(gis): change ellipsoidSizes from function to object
The ellipsoidSizes export in Coordinates was a function, which was creating an object each time it was called. It has now be changed to an object, meaning that we don't have to execute the function each time. BREAKING CHANGE: ellipsoidSizes from Coordinates.js is no longer a function but an object.
1 parent b08d27b commit f681060

File tree

9 files changed

+24
-30
lines changed

9 files changed

+24
-30
lines changed

src/Core/Geographic/Coordinates.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
1212

1313
const projectionCache = {};
1414

15-
export function ellipsoidSizes() {
16-
return {
17-
x: 6378137,
18-
y: 6378137,
19-
z: 6356752.3142451793,
20-
};
21-
}
15+
export const ellipsoidSizes = {
16+
x: 6378137,
17+
y: 6378137,
18+
z: 6356752.3142451793,
19+
};
2220

23-
const ellipsoid = new Ellipsoid(ellipsoidSizes());
21+
const ellipsoid = new Ellipsoid(ellipsoidSizes);
2422

2523
export const UNIT = {
2624
DEGREE: 1,

src/Core/Prefab/Globe/Atmosphere.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ function Atmosphere() {
4242
wireframe: false,
4343
});
4444

45-
var size = ellipsoidSizes();
46-
var geometry = (new THREE.SphereGeometry(1.14, 64, 64)).scale(size.x, size.y, size.z);
45+
var geometry = (new THREE.SphereGeometry(1.14, 64, 64)).scale(ellipsoidSizes.x, ellipsoidSizes.y, ellipsoidSizes.z);
4746

4847
THREE.Mesh.call(this, geometry, material);
4948

@@ -68,7 +67,7 @@ function Atmosphere() {
6867
depthWrite: false,
6968
});
7069

71-
this.atmosphereIN = new THREE.Mesh((new THREE.SphereGeometry(1.002, 64, 64)).scale(size.x, size.y, size.z), materialAtmoIn);
70+
this.atmosphereIN = new THREE.Mesh((new THREE.SphereGeometry(1.002, 64, 64)).scale(ellipsoidSizes.x, ellipsoidSizes.y, ellipsoidSizes.z), materialAtmoIn);
7271

7372
this.add(this.atmosphereIN);
7473
}

src/Core/Prefab/GlobeView.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export function createGlobeLayer(id, options = {}) {
8484
*/
8585
function GlobeView(viewerDiv, coordCarto, options = {}) {
8686
THREE.Object3D.DefaultUp.set(0, 0, 1);
87-
const size = ellipsoidSizes().x;
8887
// Setup View
8988
View.call(this, 'EPSG:4978', viewerDiv, options);
9089

@@ -94,8 +93,8 @@ function GlobeView(viewerDiv, coordCarto, options = {}) {
9493
coordCarto.latitude,
9594
coordCarto.altitude);
9695

97-
this.camera.camera3D.near = Math.max(15.0, 0.000002352 * size);
98-
this.camera.camera3D.far = size * 10;
96+
this.camera.camera3D.near = Math.max(15.0, 0.000002352 * ellipsoidSizes.x);
97+
this.camera.camera3D.far = ellipsoidSizes.x * 10;
9998

10099
const tileLayer = new GlobeLayer('globe', options.object3d);
101100

@@ -125,11 +124,11 @@ function GlobeView(viewerDiv, coordCarto, options = {}) {
125124
this.camera.setPosition(positionCamera);
126125
this.camera.camera3D.lookAt(positionTargetCamera.as('EPSG:4978').xyz());
127126
} else {
128-
this.controls = new GlobeControls(this, positionTargetCamera, coordCarto.altitude, size);
127+
this.controls = new GlobeControls(this, positionTargetCamera, coordCarto.altitude, ellipsoidSizes.x);
129128
this.controls.handleCollision = typeof (options.handleCollision) !== 'undefined' ? options.handleCollision : true;
130129
}
131130

132-
const mfogDistance = size * 160.0;
131+
const mfogDistance = ellipsoidSizes.x * 160.0;
133132
this._renderState = RendererConstant.FINAL;
134133
this._fullSizeDepthBuffer = null;
135134

@@ -157,7 +156,7 @@ function GlobeView(viewerDiv, coordCarto, options = {}) {
157156

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

162161
// get altitude camera
163162
coordCam.set(this.referenceCrs, this.camera.camera3D.position).as('EPSG:4326', coordGeoCam);

src/Process/GlobeTileProcessing.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export function preGlobeUpdate(context, layer) {
3131
worldToScaledEllipsoid.getInverse(layer.object3d.matrixWorld);
3232
worldToScaledEllipsoid.premultiply(
3333
new THREE.Matrix4().makeScale(
34-
1 / ellipsoidSizes().x,
35-
1 / ellipsoidSizes().y,
36-
1 / ellipsoidSizes().z));
34+
1 / ellipsoidSizes.x,
35+
1 / ellipsoidSizes.y,
36+
1 / ellipsoidSizes.z));
3737

3838
// pre-horizon culling
3939
// cV is camera's position in worldToScaledEllipsoid system
@@ -154,14 +154,13 @@ export function globeSchemeTileWMTS(type) {
154154
}
155155

156156
export function computeTileZoomFromDistanceCamera(distance, view) {
157-
const sizeEllipsoid = ellipsoidSizes().x;
158-
const preSinus = SIZE_TEXTURE_TILE * (SSE_SUBDIVISION_THRESHOLD * 0.5) / view.camera.preSSE / sizeEllipsoid;
157+
const preSinus = SIZE_TEXTURE_TILE * (SSE_SUBDIVISION_THRESHOLD * 0.5) / view.camera.preSSE / ellipsoidSizes.x;
159158

160159
let sinus = distance * preSinus;
161160
let zoom = Math.log(Math.PI / (2.0 * Math.asin(sinus))) / Math.log(2);
162161

163162
const delta = Math.PI / Math.pow(2, zoom);
164-
const circleChord = 2.0 * sizeEllipsoid * Math.sin(delta * 0.5);
163+
const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
165164
const radius = circleChord * 0.5;
166165

167166
// adjust with bounding sphere rayon
@@ -173,7 +172,7 @@ export function computeTileZoomFromDistanceCamera(distance, view) {
173172

174173
export function computeDistanceCameraFromTileZoom(zoom, view) {
175174
const delta = Math.PI / Math.pow(2, zoom);
176-
const circleChord = 2.0 * ellipsoidSizes().x * Math.sin(delta * 0.5);
175+
const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
177176
const radius = circleChord * 0.5;
178177
const error = radius / SIZE_TEXTURE_TILE;
179178

src/Renderer/ThreeExtended/GlobeControls.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,7 @@ GlobeControls.prototype.pixelsToMeters = function pixelsToMeters(pixels, pixelPi
11221122

11231123
GlobeControls.prototype.pixelsToDegrees = function pixelsToDegrees(pixels, pixelPitch = 0.28) {
11241124
const chord = this.pixelsToMeters(pixels, pixelPitch);
1125-
const radius = ellipsoidSizes().x;
1126-
return THREE.Math.radToDeg(2 * Math.asin(chord / (2 * radius)));
1125+
return THREE.Math.radToDeg(2 * Math.asin(chord / (2 * ellipsoidSizes.x)));
11271126
};
11281127

11291128
/**

src/utils/CameraUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Ellipsoid from '../Core/Math/Ellipsoid';
88
THREE.Object3D.DefaultUp.set(0, 0, 1);
99
const targetPosition = new THREE.Vector3();
1010
const targetCoord = new Coordinates('EPSG:4326', 0, 0, 0);
11-
const ellipsoid = new Ellipsoid(ellipsoidSizes());
11+
const ellipsoid = new Ellipsoid(ellipsoidSizes);
1212
const rigs = [];
1313
const slerp = [];
1414

test/examples/CameraUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function newGlobePage() {
1010
window.THREE = itowns.THREE;
1111
const raycaster = new itowns.THREE.Raycaster();
1212
const screen = new itowns.THREE.Vector2();
13-
const ellipsoid = new itowns.Ellipsoid(itowns.ellipsoidSizes());
13+
const ellipsoid = new itowns.Ellipsoid(itowns.ellipsoidSizes);
1414
globeView
1515
.getPickingPositionFromDepth = function fn(mouse, target = new itowns.THREE.Vector3()) {
1616
const g = this.mainLoop.gfxEngine;

test/examples/GlobeControls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function newGlobePage() {
1313
.getPickingPositionFromDepth = function fn(mouse, target = new itowns.THREE.Vector3()) {
1414
const g = this.mainLoop.gfxEngine;
1515
const dim = g.getWindowSize();
16-
const ellipsoid = new itowns.Ellipsoid(itowns.ellipsoidSizes());
16+
const ellipsoid = new itowns.Ellipsoid(itowns.ellipsoidSizes);
1717
screen.copy(mouse || dim.clone().multiplyScalar(0.5));
1818
screen.x = Math.floor(screen.x);
1919
screen.y = Math.floor(screen.y);

test/unit/CameraUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DEMUtils.getElevationValueAt = () => ({ z: 0 });
1111

1212
const raycaster = new THREE.Raycaster();
1313
const center = new THREE.Vector2();
14-
const ellipsoid = new Ellipsoid(ellipsoidSizes());
14+
const ellipsoid = new Ellipsoid(ellipsoidSizes);
1515

1616
function pickEllipsoid(camera) {
1717
raycaster.setFromCamera(center, camera);

0 commit comments

Comments
 (0)