Skip to content

Commit

Permalink
refactor(Extent): use Extent.planarDimensions instead of Extent.dimen…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
gchoqueux authored and mgermerie committed Nov 18, 2021
1 parent ed583d9 commit 023d5fa
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/view_multi_25d.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Converter/Feature2Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/convertToTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions src/Core/Geographic/Extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
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 @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Prefab/PlanarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/VectorTileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/OBB.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/CameraUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/DEMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions test/unit/CameraUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
);
});
});
2 changes: 1 addition & 1 deletion test/unit/dataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/feature2mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 023d5fa

Please sign in to comment.