From 023d5faf2112d36916affdb722ce98236038d2c5 Mon Sep 17 00:00:00 2001 From: gchoqueux Date: Wed, 17 Nov 2021 17:23:18 +0100 Subject: [PATCH] refactor(Extent): use Extent.planarDimensions instead of Extent.dimensions --- examples/view_multi_25d.html | 2 +- src/Converter/Feature2Texture.js | 4 ++-- src/Converter/convertToTile.js | 2 +- src/Core/Geographic/Extent.js | 14 +++++++------- src/Core/Prefab/Globe/BuilderEllipsoidTile.js | 2 +- src/Core/Prefab/PlanarView.js | 2 +- src/Parser/VectorTileParser.js | 2 +- src/Renderer/OBB.js | 4 ++-- src/Utils/CameraUtils.js | 2 +- src/Utils/DEMUtils.js | 4 ++-- test/unit/CameraUtils.js | 10 +++++----- test/unit/dataSourceProvider.js | 2 +- test/unit/feature2mesh.js | 2 +- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/view_multi_25d.html b/examples/view_multi_25d.html index 4adb6a752d..dde280775c 100644 --- a/examples/view_multi_25d.html +++ b/examples/view_multi_25d.html @@ -81,7 +81,7 @@ itowns.THREE.Object3D.DefaultUp.set(0, 0, 1); - scale = new itowns.THREE.Vector3(1, 1, 1).divideScalar(extent.dimensions().x); + scale = new itowns.THREE.Vector3(1, 1, 1).divideScalar(extent.planarDimensions().x); // Instanciate View view = new itowns.View(extent.crs, viewerDiv); diff --git a/src/Converter/Feature2Texture.js b/src/Converter/Feature2Texture.js index b5f9611448..a531ceeba7 100644 --- a/src/Converter/Feature2Texture.js +++ b/src/Converter/Feature2Texture.js @@ -103,7 +103,7 @@ function drawPoint(ctx, x, y, style = {}, invCtxScale) { const coord = new Coordinates('EPSG:4326', 0, 0, 0); function drawFeature(ctx, feature, extent, style, invCtxScale) { - const extentDim = extent.dimensions(); + const extentDim = extent.planarDimensions(); const scaleRadius = extentDim.x / ctx.canvas.width; const globals = { zoom: extent.zoom }; @@ -154,7 +154,7 @@ export default { if (collection) { // A texture is instancied drawn canvas // origin and dimension are used to transform the feature's coordinates to canvas's space - extent.dimensions(dimension); + extent.planarDimensions(dimension); const c = document.createElement('canvas'); coord.crs = extent.crs; diff --git a/src/Converter/convertToTile.js b/src/Converter/convertToTile.js index 1df04ceff2..6800a19557 100644 --- a/src/Converter/convertToTile.js +++ b/src/Converter/convertToTile.js @@ -28,7 +28,7 @@ function setTileFromTiledLayer(tile, tileLayer) { // If the point is below the horizon, // the tile is guaranteed to be below the horizon as well. tile.horizonCullingPoint = tile.extent.center().as('EPSG:4978').toVector3(); - tile.extent.dimensions(dimensions).multiplyScalar(THREE.MathUtils.DEG2RAD); + tile.extent.planarDimensions(dimensions).multiplyScalar(THREE.MathUtils.DEG2RAD); // alpha is maximum angle between two points of tile const alpha = dimensions.length(); diff --git a/src/Core/Geographic/Extent.js b/src/Core/Geographic/Extent.js index d424e99b60..9ba2f1ce89 100644 --- a/src/Core/Geographic/Extent.js +++ b/src/Core/Geographic/Extent.js @@ -49,7 +49,7 @@ export const schemeTiles = new Map(); function getInfoTms(crs) { const epsg = CRS.formatToEPSG(crs); const globalExtent = globalExtentTMS.get(epsg); - const globalDimension = globalExtent.dimensions(_dim2); + const globalDimension = globalExtent.planarDimensions(_dim2); const tms = CRS.formatToTms(crs); const sTs = schemeTiles.get(tms) || schemeTiles.get('default'); // The isInverted parameter is to be set to the correct value, true or false @@ -132,7 +132,7 @@ class Extent { const extent = _extent.copy(this).as(CRS.formatToEPSG(crs), _extent2); const { globalExtent, globalDimension, sTs } = getInfoTms(CRS.formatToEPSG(crs)); extent.clampByExtent(globalExtent); - extent.dimensions(dimensionTile); + extent.planarDimensions(dimensionTile); const zoom = (this.zoom + 1) || Math.floor(Math.log2(Math.round(globalDimension.x / (dimensionTile.x * sTs.x)))); const countTiles = getCountTiles(crs, zoom); @@ -154,7 +154,7 @@ class Extent { const target = new Extent(crs, 0, 0, 0); const { globalExtent, globalDimension, sTs, isInverted } = getInfoTms(this.crs); const center = this.center(_c); - this.dimensions(dimensionTile); + this.planarDimensions(dimensionTile); // Each level has 2^n * 2^n tiles... // ... so we count how many tiles of the same width as tile we can fit in the layer // ... 2^zoom = tilecount => zoom = log2(tilecount) @@ -242,7 +242,7 @@ class Extent { if (CRS.isTms(this.crs)) { throw new Error('Invalid operation for WMTS bbox'); } - this.dimensions(_dim); + this.planarDimensions(_dim); target.crs = this.crs; target.setFromValues(this.west + _dim.x * 0.5, this.south + _dim.y * 0.5); @@ -391,8 +391,8 @@ class Extent { r.invDiff, r.invDiff); } - extent.dimensions(_dim); - this.dimensions(_dim2); + extent.planarDimensions(_dim); + this.planarDimensions(_dim2); const originX = (this.west - extent.west) / _dim.x; const originY = (extent.north - this.north) / _dim.y; @@ -650,7 +650,7 @@ class Extent { */ subdivisionByScheme(scheme = defaultScheme) { const subdivisedExtents = []; - const dimSub = this.dimensions(_dim).divide(scheme); + const dimSub = this.planarDimensions(_dim).divide(scheme); for (let x = scheme.x - 1; x >= 0; x--) { for (let y = scheme.y - 1; y >= 0; y--) { const west = this.west + x * dimSub.x; diff --git a/src/Core/Prefab/Globe/BuilderEllipsoidTile.js b/src/Core/Prefab/Globe/BuilderEllipsoidTile.js index c0fafcf89a..21a7bc805b 100644 --- a/src/Core/Prefab/Globe/BuilderEllipsoidTile.js +++ b/src/Core/Prefab/Globe/BuilderEllipsoidTile.js @@ -62,7 +62,7 @@ class BuilderEllipsoidTile { // let's avoid building too much temp objects params.projected = { longitude: 0, latitude: 0 }; - params.extent.dimensions(this.tmp.dimension); + params.extent.planarDimensions(this.tmp.dimension); } // get center tile in cartesian 3D diff --git a/src/Core/Prefab/PlanarView.js b/src/Core/Prefab/PlanarView.js index 1123ff076b..74de41f0b2 100644 --- a/src/Core/Prefab/PlanarView.js +++ b/src/Core/Prefab/PlanarView.js @@ -40,7 +40,7 @@ class PlanarView extends View { this.isPlanarView = true; // Configure camera - const dim = extent.dimensions(); + const dim = extent.planarDimensions(); const max = Math.max(dim.x, dim.y); const camera3D = this.camera.camera3D; camera3D.near = 0.1; diff --git a/src/Parser/VectorTileParser.js b/src/Parser/VectorTileParser.js index 815fbf3fba..f5d5d6e9bf 100644 --- a/src/Parser/VectorTileParser.js +++ b/src/Parser/VectorTileParser.js @@ -5,7 +5,7 @@ import { globalExtentTMS } from 'Core/Geographic/Extent'; import { FeatureCollection, FEATURE_TYPES } from 'Core/Feature'; import { deprecatedParsingOptionsToNewOne } from 'Core/Deprecated/Undeprecator'; -const worldDimension3857 = globalExtentTMS.get('EPSG:3857').dimensions(); +const worldDimension3857 = globalExtentTMS.get('EPSG:3857').planarDimensions(); const globalExtent = new Vector3(worldDimension3857.x, worldDimension3857.y, 1); const lastPoint = new Vector2(); const firstPoint = new Vector2(); diff --git a/src/Renderer/OBB.js b/src/Renderer/OBB.js index b247e9a25a..53d38246a9 100644 --- a/src/Renderer/OBB.js +++ b/src/Renderer/OBB.js @@ -112,7 +112,7 @@ class OBB extends THREE.Object3D { if (extent.crs == 'EPSG:4326') { const { sharableExtent, quaternion, position } = builder.computeSharableExtent(extent); // Compute the minimum count of segment to build tile - const segment = Math.max(Math.floor(sharableExtent.dimensions(dimension).x / 90 + 1), 2); + const segment = Math.max(Math.floor(sharableExtent.planarDimensions(dimension).x / 90 + 1), 2); const paramsGeometry = { extent: sharableExtent, level: 0, @@ -132,7 +132,7 @@ class OBB extends THREE.Object3D { this.updateMatrixWorld(true); } else if (!CRS.isTms(extent.crs) && CRS.isMetricUnit(extent.crs)) { extent.center(coord).toVector3(this.position); - extent.dimensions(dimension); + extent.planarDimensions(dimension); size.set(dimension.x, dimension.y, Math.abs(maxHeight - minHeight)); this.box3D.setFromCenterAndSize(center, size); this.updateMatrixWorld(true); diff --git a/src/Utils/CameraUtils.js b/src/Utils/CameraUtils.js index 1f5f562fb9..a4d0ed7125 100644 --- a/src/Utils/CameraUtils.js +++ b/src/Utils/CameraUtils.js @@ -431,7 +431,7 @@ export default { dimensions = { x: size.y, y: size.x }; } else { extent = extent.as(view.referenceCrs); - dimensions = extent.dimensions(); + dimensions = extent.planarDimensions(); } extent.center(cameraTransformOptions.coord); diff --git a/src/Utils/DEMUtils.js b/src/Utils/DEMUtils.js index 010fc8cd0c..3b40bf0b4d 100644 --- a/src/Utils/DEMUtils.js +++ b/src/Utils/DEMUtils.js @@ -308,7 +308,7 @@ function offsetInExtent(point, extent, target = new THREE.Vector2()) { throw new Error(`Unsupported mix: ${point.crs} and ${extent.crs}`); } - extent.dimensions(dimension); + extent.planarDimensions(dimension); const originX = (point.x - extent.west) / dimension.x; const originY = (extent.north - point.y) / dimension.y; @@ -364,7 +364,7 @@ function _readZ(layer, method, coord, nodes, cache) { // at (offset.x, offset.y) and we're done // - the correct one: emulate the vertex shader code if (method == PRECISE_READ_Z) { - pt.z = _readZCorrect(layer, src, temp.offset, tile.extent.dimensions(), tileWithValidElevationTexture.extent.dimensions()); + pt.z = _readZCorrect(layer, src, temp.offset, tile.extent.planarDimensions(), tileWithValidElevationTexture.extent.planarDimensions()); } else { pt.z = _readZFast(layer, src, temp.offset); } diff --git a/test/unit/CameraUtils.js b/test/unit/CameraUtils.js index e5c4309303..f3ad611633 100644 --- a/test/unit/CameraUtils.js +++ b/test/unit/CameraUtils.js @@ -128,22 +128,22 @@ describe('Camera utils unit test', function () { CameraUtils.transformCameraToLookAtTarget(view, camera3D, subExtent); assert.equal( (camera3D.top - camera3D.bottom) / camera3D.zoom, - subExtent.dimensions().y, + subExtent.planarDimensions().y, ); assert.equal( (camera3D.right - camera3D.left) / camera3D.zoom, - subExtent.dimensions().y * 1.5, + subExtent.planarDimensions().y * 1.5, ); // case r < R (r = 1.5 and R = 2.0) subExtent.set(0, 10, 0, 5); CameraUtils.transformCameraToLookAtTarget(view, camera3D, subExtent); assert.ok( - (camera3D.top - camera3D.bottom) / camera3D.zoom - subExtent.dimensions().x / 1.5 < Math.pow(10, -14), + (camera3D.top - camera3D.bottom) / camera3D.zoom - subExtent.planarDimensions().x / 1.5 < Math.pow(10, -14), ); assert.equal( (camera3D.right - camera3D.left) / camera3D.zoom, - subExtent.dimensions().x, + subExtent.planarDimensions().x, ); const perspectiveCamera = new Camera(view.referenceCrs, 60, 40); @@ -154,7 +154,7 @@ describe('Camera utils unit test', function () { camera3D.updateMatrixWorld(true); assert.ok( CameraUtils.getCameraTransformOptionsFromExtent(view, camera3D, subExtent).range - - subExtent.dimensions().y / (2 * Math.tan(THREE.Math.degToRad(camera3D.fov) / 2)) < Math.pow(10, -14), + subExtent.planarDimensions().y / (2 * Math.tan(THREE.Math.degToRad(camera3D.fov) / 2)) < Math.pow(10, -14), ); }); }); diff --git a/test/unit/dataSourceProvider.js b/test/unit/dataSourceProvider.js index 8f86c59c1a..f7ac48b9d9 100644 --- a/test/unit/dataSourceProvider.js +++ b/test/unit/dataSourceProvider.js @@ -37,7 +37,7 @@ describe('Provide in Sources', function () { geom.OBB = new OBB(new THREE.Vector3(), new THREE.Vector3(1, 1, 1)); const globalExtent = globalExtentTMS.get('EPSG:3857'); const zoom = 10; - const sizeTile = globalExtent.dimensions().x / 2 ** zoom; + const sizeTile = globalExtent.planarDimensions().x / 2 ** zoom; const extent = new Extent('EPSG:3857', 0, sizeTile, 0, sizeTile); // const zoom = 4; const material = new LayeredMaterial(); diff --git a/test/unit/feature2mesh.js b/test/unit/feature2mesh.js index 3691c37f08..3009544cb4 100644 --- a/test/unit/feature2mesh.js +++ b/test/unit/feature2mesh.js @@ -33,7 +33,7 @@ describe('Feature2Mesh', function () { it('rect mesh area should match geometry extent', () => parsed.then((collection) => { const mesh = Feature2Mesh.convert()(collection); - const extentSize = collection.extent.dimensions(); + const extentSize = collection.extent.planarDimensions(); assert.equal( extentSize.x * extentSize.y,