This commit is contained in:
Zemledelec 2023-08-01 19:48:41 +04:00
parent d7410f6416
commit 31c110da1d
6 changed files with 53 additions and 35 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
out-tsc
.metadata .metadata
Thumbs.db Thumbs.db
Release Release

View File

@ -3,6 +3,7 @@ module.exports = {
coverageDirectory: "coverage", coverageDirectory: "coverage",
collectCoverage: true, collectCoverage: true,
coverageProvider: "v8", coverageProvider: "v8",
setupFiles: ["jest-canvas-mock"], testEnvironment: "jsdom", setupFiles: ["jest-canvas-mock"],
testEnvironment: "jsdom",
setupFilesAfterEnv: ["./tests/setupTests.js"] setupFilesAfterEnv: ["./tests/setupTests.js"]
}; };

10
package-lock.json generated
View File

@ -25,7 +25,7 @@
"prettier": "^2.8.8", "prettier": "^2.8.8",
"rollup": "^3.21.3", "rollup": "^3.21.3",
"rollup-plugin-postcss": "^4.0.2", "rollup-plugin-postcss": "^4.0.2",
"typescript": "^5.0.4" "typescript": "^5.1.6"
} }
}, },
"node_modules/@75lb/deep-merge": { "node_modules/@75lb/deep-merge": {
@ -11479,16 +11479,16 @@
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.0.4", "version": "5.1.6",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz",
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==",
"dev": true, "dev": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
"tsserver": "bin/tsserver" "tsserver": "bin/tsserver"
}, },
"engines": { "engines": {
"node": ">=12.20" "node": ">=14.17"
} }
}, },
"node_modules/typical": { "node_modules/typical": {

View File

@ -12,12 +12,9 @@
"docs": "jsdoc -r ./src/ -c ./jsdoc.conf.json -d ./docs", "docs": "jsdoc -r ./src/ -c ./jsdoc.conf.json -d ./docs",
"serve": "ws", "serve": "ws",
"build": "rollup -c --bundleConfigAsCjs", "build": "rollup -c --bundleConfigAsCjs",
"webgl": "rollup -c --environment entry:webgl",
"core": "rollup -c --environment entry:core",
"test": "jest --env=jsdom --runInBand --ci --coverage=false", "test": "jest --env=jsdom --runInBand --ci --coverage=false",
"test_watch": "jest --env=jsdom --watch", "test_watch": "jest --env=jsdom --watch",
"lint": "eslint -c ./.eslintrc.js src/og", "lint": "eslint -c ./.eslintrc.js src/og",
"generate_types": "rm -rf types; tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types",
"compile_js_as_ts": "tsc src/og/index.js --AllowJs --checkJs --outDir dist/@openglobus/src/", "compile_js_as_ts": "tsc src/og/index.js --AllowJs --checkJs --outDir dist/@openglobus/src/",
"font": "node ./fonts/index.js" "font": "node ./fonts/index.js"
}, },
@ -60,7 +57,7 @@
"prettier": "^2.8.8", "prettier": "^2.8.8",
"rollup": "^3.21.3", "rollup": "^3.21.3",
"rollup-plugin-postcss": "^4.0.2", "rollup-plugin-postcss": "^4.0.2",
"typescript": "^5.0.4" "typescript": "^5.1.6"
}, },
"lint-staged": { "lint-staged": {
"*.{js,ts}": [ "*.{js,ts}": [

View File

@ -1,5 +1,6 @@
"use strict"; "use strict";
//@ts-ignore
import * as mercator from "./mercator.js"; import * as mercator from "./mercator.js";
const HALF_PI = Math.PI * 0.5; const HALF_PI = Math.PI * 0.5;
@ -16,12 +17,12 @@ const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
* @param {number} [height] - Height over the surface. * @param {number} [height] - Height over the surface.
*/ */
export class LonLat { export class LonLat {
/**
* @param {number} [lon] - Longitude. public lon: number = 0;
* @param {number} [lat] - Latitude. public lat: number = 0;
* @param {number} [height] - Height over the surface. public height: number = 0;
*/
constructor(lon = 0, lat = 0, height = 0) { constructor(lon: number = 0, lat: number = 0, height: number = 0) {
/** /**
* Longitude. * Longitude.
* @public * @public
@ -44,7 +45,7 @@ export class LonLat {
this.height = height; this.height = height;
} }
isZero() { public isZero(): boolean {
return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0; return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
} }
@ -54,10 +55,10 @@ export class LonLat {
* @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries) * @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
* @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance. * @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
*/ */
static join(arr) { static join(arr: [number, number, number][]): LonLat[] {
var res = []; let res = [];
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
var ai = arr[i]; let ai = arr[i];
res[i] = new LonLat(ai[0], ai[1], ai[2]); res[i] = new LonLat(ai[0], ai[1], ai[2]);
} }
return res; return res;
@ -69,7 +70,7 @@ export class LonLat {
* @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries) * @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
* @returns {LonLat} - * @returns {LonLat} -
*/ */
static createFromArray(arr) { static createFromArray(arr: [number, number, number]): LonLat {
return new LonLat(arr[0], arr[1], arr[2]); return new LonLat(arr[0], arr[1], arr[2]);
} }
@ -78,7 +79,7 @@ export class LonLat {
* @param lonLat * @param lonLat
* @returns {number[]} * @returns {number[]}
*/ */
static toArray(lonLat) { static toArray(lonLat: LonLat): [number, number, number] {
return [lonLat.lon, lonLat.lat, lonLat.height] return [lonLat.lon, lonLat.lat, lonLat.height]
} }
@ -86,8 +87,8 @@ export class LonLat {
* Create array from lonlat * Create array from lonlat
* @returns {number[]} * @returns {number[]}
*/ */
toArray() { public toArray(): [number, number, number] {
return LonLat.toArray(this) return LonLat.toArray(this);
} }
/** /**
@ -98,7 +99,7 @@ export class LonLat {
* @param {number} [height] - Height. * @param {number} [height] - Height.
* @returns {LonLat} - * @returns {LonLat} -
*/ */
static forwardMercator(lon, lat, height) { static forwardMercator(lon: number, lat: number, height: number): LonLat {
return new LonLat( return new LonLat(
lon * mercator.POLE_BY_180, lon * mercator.POLE_BY_180,
Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI, Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
@ -113,7 +114,7 @@ export class LonLat {
* @param {LonLat} res - Output mercator coordinates * @param {LonLat} res - Output mercator coordinates
* @returns {LonLat} - Output mercator coordinates * @returns {LonLat} - Output mercator coordinates
*/ */
static forwardMercatorRes(lonLat, res) { static forwardMercatorRes(lonLat: LonLat, res: LonLat): LonLat {
res.lon = lonLat.lon * mercator.POLE_BY_180; res.lon = lonLat.lon * mercator.POLE_BY_180;
res.lat = Math.log(Math.tan((90.0 + lonLat.lat) * PI_BY_360)) * mercator.POLE_BY_PI, res.lat = Math.log(Math.tan((90.0 + lonLat.lat) * PI_BY_360)) * mercator.POLE_BY_PI,
res.height = lonLat.height; res.height = lonLat.height;
@ -128,7 +129,7 @@ export class LonLat {
* @param {number} [height] - Height. * @param {number} [height] - Height.
* @returns {LonLat} - * @returns {LonLat} -
*/ */
static inverseMercator(x, y, height = 0) { static inverseMercator(x: number, y: number, height: number = 0): LonLat {
return new LonLat( return new LonLat(
x * mercator.INV_POLE_BY_180, x * mercator.INV_POLE_BY_180,
INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI, INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
@ -144,7 +145,7 @@ export class LonLat {
* @param {number} [height] - Height. * @param {number} [height] - Height.
* @returns {LonLat} - * @returns {LonLat} -
*/ */
set(lon = 0, lat = 0, height = 0) { public set(lon: number = 0, lat: number = 0, height: number = 0): LonLat {
this.lon = lon; this.lon = lon;
this.lat = lat; this.lat = lat;
this.height = height; this.height = height;
@ -157,7 +158,7 @@ export class LonLat {
* @param {LonLat} [lonLat] - Coordinates to copy. * @param {LonLat} [lonLat] - Coordinates to copy.
* @returns {LonLat} - * @returns {LonLat} -
*/ */
copy(lonLat) { public copy(lonLat: LonLat): LonLat {
this.lon = lonLat.lon; this.lon = lonLat.lon;
this.lat = lonLat.lat; this.lat = lonLat.lat;
this.height = lonLat.height; this.height = lonLat.height;
@ -169,7 +170,7 @@ export class LonLat {
* @public * @public
* @returns {LonLat} - * @returns {LonLat} -
*/ */
clone() { public clone(): LonLat {
return new LonLat(this.lon, this.lat, this.height); return new LonLat(this.lon, this.lat, this.height);
} }
@ -178,12 +179,12 @@ export class LonLat {
* @public * @public
* @returns {LonLat} - * @returns {LonLat} -
*/ */
forwardMercator() { public forwardMercator(): LonLat {
return LonLat.forwardMercator(this.lon, this.lat, this.height); return LonLat.forwardMercator(this.lon, this.lat, this.height);
} }
forwardMercatorEPS01() { public forwardMercatorEPS01(): LonLat {
var lat = this.lat; let lat = this.lat;
if (lat > 89.9) { if (lat > 89.9) {
lat = 89.9; lat = 89.9;
} else if (lat < -89.9) { } else if (lat < -89.9) {
@ -200,7 +201,7 @@ export class LonLat {
* @public * @public
* @returns {LonLat} - * @returns {LonLat} -
*/ */
inverseMercator() { public inverseMercator(): LonLat {
return LonLat.inverseMercator(this.lon, this.lat, this.height); return LonLat.inverseMercator(this.lon, this.lat, this.height);
} }
@ -210,7 +211,7 @@ export class LonLat {
* @param {LonLat} b - Coordinate to compare with. * @param {LonLat} b - Coordinate to compare with.
* @returns {boolean} - * @returns {boolean} -
*/ */
equal(b) { public equal(b: LonLat): boolean {
if (b.height) { if (b.height) {
return this.lon === b.lon && this.lat === b.lat && this.height === b.height; return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
} else { } else {

18
tsconfig.json Normal file
View File

@ -0,0 +1,18 @@
{
"include" : [
"./src/og/**/*"
],
"exclude" : [
"node_modules",
"dist"
],
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "out-tsc",
}
}