Skip to content

Commit

Permalink
Modifs: Corr to better fit master and JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Oct 30, 2023
1 parent b7538b0 commit a411439
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
36 changes: 26 additions & 10 deletions src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,29 @@ import Coordinates from 'Core/Geographic/Coordinates';

const coord = new Coordinates('EPSG:4326', 0, 0, 0);

/**
* @class
* @classdesc FeatureContext is a class to store all informations
* about context to generate the style of each FeatureGeometry.
*
* @property {Coordinates} worldCoord @private Coordinates of the FeatureGeometry in world system.
* @property {Coordinates} localCoordinates @private Are the coordinates systeme origin local or global.
* @property {boolean} isProjected @private Are the coordinates already been projected.
* @property {FeatureGeometry} geometry @private
* @property {Object} globals
* @property {Object} collection
* @property {Coordinates} coordinates
*/
class FeatureContext {
#worldCoord = new Coordinates('EPSG:4326', 0, 0, 0);
#localCoordinates = new Coordinates('EPSG:4326', 0, 0, 0);
#isProjected = true;
#geometry = {};

constructor() {
/**
* @constructor
*/
this.globals = {};
}

Expand Down Expand Up @@ -247,11 +263,10 @@ function featureToPoint(feature, options) {

coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v));
const style = feature.style.applyContext(context);
const { base_altitude, color } = style.point;
coord.z = 0;
const { color } = style.point;

// populate vertices
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v);
base.copy(normal).multiplyScalar(context.collection.center.z).add(coord).toArray(vertices, v);
toColor(color).multiplyScalar(255).toArray(colors, v);
batchIds[j] = id;
}
Expand Down Expand Up @@ -319,12 +334,14 @@ function featureToLine(feature, options) {
}

coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v));

const style = feature.style.applyContext(context);
const { base_altitude, color } = style.stroke;
coord.z = 0;
const { color } = style.stroke;

// populate geometry buffers
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v);
base.copy(normal).multiplyScalar(context.collection.center.z).add(coord);
base.toArray(vertices, v);

toColor(color).multiplyScalar(255).toArray(colors, v);
batchIds[j] = id;
}
Expand Down Expand Up @@ -373,11 +390,10 @@ function featureToPolygon(feature, options) {

coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, i));
const style = feature.style.applyContext(context);
const { base_altitude, color } = style.fill;
coord.z = 0;
const { color } = style.fill;

// populate geometry buffers
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, i);
base.copy(normal).multiplyScalar(context.collection.center.z).add(coord).toArray(vertices, i);
batchIds[b] = id;
toColor(color).multiplyScalar(255).toArray(colors, i);
}
Expand Down Expand Up @@ -463,7 +479,7 @@ function featureToExtrudedPolygon(feature, options) {
coord.z = 0;

// populate base geometry buffers
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, i);
base.copy(normal).multiplyScalar(base_altitude - context.collection.center.z).add(coord).toArray(vertices, i);
batchIds[b] = id;

// populate top geometry buffers
Expand Down
27 changes: 8 additions & 19 deletions src/Core/Geographic/Coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Coordinates {
* @example
* itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
* You can find most projections and their proj4 code at [epsg.io]{@link https://epsg.io/}
* @param {number|Array<number>|Coordinates|THREE.Vector3} [v0=0] -
* @param {number|number[]|Coordinates|THREE.Vector3} [v0=0] -
* x or longitude value, or a more complex one: it can be an array of three
* numbers, being x/lon, x/lat, z/alt, or it can be `THREE.Vector3`. It can
* also simply be a Coordinates.
Expand Down Expand Up @@ -98,7 +98,7 @@ class Coordinates {

/**
* Sets the Coordinate Reference System.
* @param {String} crs Coordinate Reference System (e.g. 'EPSG:4978')
* @param {string} crs Coordinate Reference System (e.g. 'EPSG:4978')
*/
setCrs(crs) {
CRS.isValid(crs);
Expand All @@ -107,7 +107,6 @@ class Coordinates {

/**
* Set the values of this Coordinates.
*
* @param {number} [v0=0] - x or longitude value.
* @param {number} [v1=0] - y or latitude value.
* @param {number} [v2=0] - z or altitude value.
Expand All @@ -125,8 +124,7 @@ class Coordinates {

/**
* Set the values of this Coordinates from an array.
*
* @param {Array<number>} array - An array of number to assign to the
* @param {number[]} array - An array of number to assign to the
* Coordinates.
* @param {number} [offset] - Optional offset into the array.
*
Expand All @@ -139,7 +137,6 @@ class Coordinates {
/**
* Set the values of this Coordinates from a `THREE.Vector3` or an `Object`
* having `x/y/z` properties, like a `Coordinates`.
*
* @param {THREE.Vector3|Coordinates} v0 - The object to read the values
* from.
*
Expand All @@ -162,7 +159,6 @@ class Coordinates {
/**
* Copies the values of the passed Coordinates to this one. The CRS is
* however not copied.
*
* @param {Coordinates} src - The source to copy from.
*
* @return {Coordinates} This Coordinates.
Expand Down Expand Up @@ -206,7 +202,6 @@ class Coordinates {

/**
* Return this Coordinates values into a `THREE.Vector3`.
*
* @param {THREE.Vector3} [target] - The target to put the values in. If not
* specified, a new vector will be created.
*
Expand All @@ -218,13 +213,11 @@ class Coordinates {

/**
* Copy values coordinates to array
*
* @param {number[]} array - array to store this vector to. If this is not
* provided a new array will be created.
* @param {number} [offset=0] - optional offset into the array.
*
* @return {number[]} Returns an array [x, y, z], or copies x, y and z into
* the provided array.
* @return {number[]} Returns an array [x, y, z], or copies x, y and z into the provided array.
*/
toArray(array = [], offset = 0) {
return THREE.Vector3.prototype.toArray.call(this, array, offset);
Expand All @@ -233,10 +226,9 @@ class Coordinates {
/**
* Calculate planar distance between this coordinates and `coord`.
* Planar distance is the straight-line euclidean distance calculated in a 2D cartesian coordinate system.
*
* @param {Coordinates} coord The coordinate
* @return {number} planar distance
*
* @return {number} planar distance
*/
planarDistanceTo(coord) {
this.toVector3(v0).setZ(0);
Expand All @@ -248,12 +240,10 @@ class Coordinates {
* Calculate geodetic distance between this coordinates and `coord`.
* **Geodetic distance** is calculated in an ellispoid space as the shortest distance
* across the curved surface of the world.
*
* => As the crow flies/ Orthodromy
*
* @param {Coordinates} coord The coordinate
* @return {number} geodetic distance
*
* @return {number} geodetic distance
*/
geodeticDistanceTo(coord) {
this.as('EPSG:4326', coord0);
Expand All @@ -263,10 +253,9 @@ class Coordinates {

/**
* Calculate earth euclidean distance between this coordinates and `coord`.
*
* @param {Coordinates} coord The coordinate
* @return {number} earth euclidean distance
*
* @return {number} earth euclidean distance
*/
spatialEuclideanDistanceTo(coord) {
this.as('EPSG:4978', coord0).toVector3(v0);
Expand All @@ -276,8 +265,8 @@ class Coordinates {

/**
* Multiplies this `coordinates` (with an implicit 1 in the 4th dimension) and `mat`.
*
* @param {THREE.Matrix4} mat The matrix.
*
* @return {Coordinates} return this object.
*/
applyMatrix4(mat) {
Expand Down

0 comments on commit a411439

Please sign in to comment.