@ulrik.ek/wgs84 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  A tiny library fully implemented in Typescript to handle WGS84 coordinates in GeoJson and "small" distances between them with very high accuracy (~1 cm), based on a local, flat earth approximation.
6
6
 
7
- - All functions uses degrees for latitude and longitude, and meters for distances.
8
- - Parses and gives output in GeoJson using the [Point definition](https://en.wikipedia.org/wiki/GeoJSON). If you already have imported the typescript definition for Point in the geojson package you can use that (that is what I do in unit testing). Otherwise you can import `Point` from this package.
9
- - No dependencies to other NPM modules.
10
- - The math is based on [Aviation Formulary V1.47 by Ed Williams](https://edwilliams.org/avform147.htm#flat).
11
- - Functions will throw `Error` if fed impossible values, e.g. incorrectly formatted GeoJSON or lat >= 90 degrees (math will not work!). _Make sure to handle that!_
7
+ - All functions uses degrees for latitude and longitude, and meters for distances.
8
+ - Parses and gives output in GeoJson using the [Point definition](https://en.wikipedia.org/wiki/GeoJSON). If you already have imported the typescript definition for Point in the geojson package you can use that (that is what I do in unit testing). Otherwise you can import `Point` from this package.
9
+ - No dependencies to other NPM modules.
10
+ - The math is based on [Aviation Formulary V1.47 by Ed Williams](https://edwilliams.org/avform147.htm#flat).
11
+ - Functions will throw `Error` if fed impossible values, e.g. incorrectly formatted GeoJSON or lat >= 90 degrees (math will not work!). _Make sure to handle that!_
12
12
 
13
13
  ## Getting Started
14
14
 
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  export interface Point {
2
- type: 'Point';
3
2
  coordinates: number[];
3
+ type: 'Point';
4
4
  }
5
5
  export declare function point(lat: number, lon: number, height?: number): Point;
6
- export declare function R1(position: Point): number;
7
- export declare function R2(position: Point): number;
8
- export declare function distanceNorth(origin: Point, target: Point): number;
6
+ export declare function bearing(origin: Point, target: Point): number;
7
+ export declare function distance(origin: Point, target: Point): number;
9
8
  export declare function distanceEast(origin: Point, target: Point): number;
9
+ export declare function distanceNorth(origin: Point, target: Point): number;
10
10
  export declare function distanceUp(origin: Point, target: Point): number;
11
- export declare function distance(origin: Point, target: Point): number;
12
- export declare function bearing(origin: Point, target: Point): number;
13
- export declare function pointNorthOf(origin: Point, dN: number): Point;
14
- export declare function pointEastOf(origin: Point, dE: number): Point;
15
11
  export declare function pointAbove(origin: Point, dH: number): Point;
12
+ export declare function pointEastOf(origin: Point, dE: number): Point;
13
+ export declare function pointNorthOf(origin: Point, dN: number): Point;
14
+ export declare function R1(position: Point): number;
15
+ export declare function R2(position: Point): number;
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.point = point;
4
- exports.R1 = R1;
5
- exports.R2 = R2;
6
- exports.distanceNorth = distanceNorth;
4
+ exports.bearing = bearing;
5
+ exports.distance = distance;
7
6
  exports.distanceEast = distanceEast;
7
+ exports.distanceNorth = distanceNorth;
8
8
  exports.distanceUp = distanceUp;
9
- exports.distance = distance;
10
- exports.bearing = bearing;
11
- exports.pointNorthOf = pointNorthOf;
12
- exports.pointEastOf = pointEastOf;
13
9
  exports.pointAbove = pointAbove;
10
+ exports.pointEastOf = pointEastOf;
11
+ exports.pointNorthOf = pointNorthOf;
12
+ exports.R1 = R1;
13
+ exports.R2 = R2;
14
14
  function point(lat, lon, height) {
15
15
  const result = height
16
16
  ? { coordinates: [lon, lat, height], type: 'Point' }
@@ -21,22 +21,22 @@ function point(lat, lon, height) {
21
21
  const R = 6378.137 * 1000;
22
22
  const f = 1 / 298.257_223_563;
23
23
  const eSquared = f * (2 - f);
24
- function R1(position) {
25
- validCoord(position);
26
- const lat = degToRad(position.coordinates[1]);
27
- return (R * (1 - eSquared)) / Math.pow(1 - eSquared * Math.pow(Math.sin(lat), 2), 3 / 2);
28
- }
29
- function R2(position) {
30
- validCoord(position);
31
- const lat = degToRad(position.coordinates[1]);
32
- return R / Math.sqrt(1 - eSquared * Math.pow(Math.sin(lat), 2));
33
- }
34
- function distanceNorth(origin, target) {
24
+ function bearing(origin, target) {
35
25
  validCoord(origin);
36
26
  validCoord(target);
37
- const originLat = degToRad(origin.coordinates[1]);
38
- const targetLat = degToRad(target.coordinates[1]);
39
- return R1(origin) * (targetLat - originLat);
27
+ return ((radToDeg(Math.atan2(distanceEast(origin, target), distanceNorth(origin, target))) + 360) %
28
+ 360);
29
+ }
30
+ function distance(origin, target) {
31
+ if (origin.coordinates.length === 2 || target.coordinates.length === 2) {
32
+ return Math.hypot(distanceNorth(origin, target), distanceEast(origin, target));
33
+ }
34
+ else if (origin.coordinates.length === 3 && target.coordinates.length === 3) {
35
+ return Math.hypot(distanceNorth(origin, target), distanceEast(origin, target), distanceUp(origin, target));
36
+ }
37
+ else {
38
+ throw new Error('Inputs are not GeoJSON Points.');
39
+ }
40
40
  }
41
41
  function distanceEast(origin, target) {
42
42
  validCoord(origin);
@@ -53,6 +53,13 @@ function distanceEast(origin, target) {
53
53
  }
54
54
  return R2(origin) * Math.cos(originLat) * deltaAngle;
55
55
  }
56
+ function distanceNorth(origin, target) {
57
+ validCoord(origin);
58
+ validCoord(target);
59
+ const originLat = degToRad(origin.coordinates[1]);
60
+ const targetLat = degToRad(target.coordinates[1]);
61
+ return R1(origin) * (targetLat - originLat);
62
+ }
56
63
  function distanceUp(origin, target) {
57
64
  if (origin.coordinates.length === 3 && target.coordinates.length === 3) {
58
65
  return target.coordinates[2] - origin.coordinates[2];
@@ -61,37 +68,12 @@ function distanceUp(origin, target) {
61
68
  throw new Error('Input is not GeoJSON Point with height.');
62
69
  }
63
70
  }
64
- function distance(origin, target) {
65
- if (origin.coordinates.length === 2 || target.coordinates.length === 2) {
66
- return Math.hypot(distanceNorth(origin, target), distanceEast(origin, target));
67
- }
68
- else if (origin.coordinates.length === 3 && target.coordinates.length === 3) {
69
- return Math.hypot(distanceNorth(origin, target), distanceEast(origin, target), distanceUp(origin, target));
70
- }
71
- else {
72
- throw new Error('Inputs are not GeoJSON Points.');
73
- }
74
- }
75
- function bearing(origin, target) {
76
- validCoord(origin);
77
- validCoord(target);
78
- return ((radToDeg(Math.atan2(distanceEast(origin, target), distanceNorth(origin, target))) + 360) %
79
- 360);
80
- }
81
- function pointNorthOf(origin, dN) {
71
+ function pointAbove(origin, dH) {
82
72
  validCoord(origin);
83
- const lon = origin.coordinates[0];
84
- const lat = radToDeg(degToRad(origin.coordinates[1]) + dN / R1(origin));
85
- let result;
86
- if (origin.coordinates[2]) {
87
- const h = origin.coordinates[2];
88
- result = { coordinates: [lon, lat, h], type: 'Point' };
89
- }
90
- else {
91
- result = { coordinates: [lon, lat], type: 'Point' };
92
- }
93
- validCoord(result);
94
- return result;
73
+ return {
74
+ coordinates: [origin.coordinates[0], origin.coordinates[1], origin.coordinates[2] + dH],
75
+ type: 'Point'
76
+ };
95
77
  }
96
78
  function pointEastOf(origin, dE) {
97
79
  validCoord(origin);
@@ -111,12 +93,30 @@ function pointEastOf(origin, dE) {
111
93
  return { coordinates: [lon, lat], type: 'Point' };
112
94
  }
113
95
  }
114
- function pointAbove(origin, dH) {
96
+ function pointNorthOf(origin, dN) {
115
97
  validCoord(origin);
116
- return {
117
- coordinates: [origin.coordinates[0], origin.coordinates[1], origin.coordinates[2] + dH],
118
- type: 'Point'
119
- };
98
+ const lon = origin.coordinates[0];
99
+ const lat = radToDeg(degToRad(origin.coordinates[1]) + dN / R1(origin));
100
+ let result;
101
+ if (origin.coordinates[2]) {
102
+ const h = origin.coordinates[2];
103
+ result = { coordinates: [lon, lat, h], type: 'Point' };
104
+ }
105
+ else {
106
+ result = { coordinates: [lon, lat], type: 'Point' };
107
+ }
108
+ validCoord(result);
109
+ return result;
110
+ }
111
+ function R1(position) {
112
+ validCoord(position);
113
+ const lat = degToRad(position.coordinates[1]);
114
+ return (R * (1 - eSquared)) / Math.pow(1 - eSquared * Math.pow(Math.sin(lat), 2), 3 / 2);
115
+ }
116
+ function R2(position) {
117
+ validCoord(position);
118
+ const lat = degToRad(position.coordinates[1]);
119
+ return R / Math.sqrt(1 - eSquared * Math.pow(Math.sin(lat), 2));
120
120
  }
121
121
  function degToRad(deg) {
122
122
  return (deg * Math.PI) / 180;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAiBA,sBAMC;AAeD,gBAIC;AAQD,gBAIC;AASD,sCAMC;AASD,oCAaC;AAQD,gCAMC;AAUD,4BAYC;AAUD,0BAQC;AASD,oCAaC;AASD,kCAiBC;AASD,gCAMC;AA/LD,SAAgB,KAAK,CAAC,GAAW,EAAE,GAAW,EAAE,MAAe;IAC3D,MAAM,MAAM,GAAU,MAAM;QACxB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;QACpD,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACjD,UAAU,CAAC,MAAM,CAAC,CAAC;IACnB,OAAO,MAAM,CAAC;AAClB,CAAC;AAGD,MAAM,CAAC,GAAW,QAAQ,GAAG,IAAI,CAAC;AAElC,MAAM,CAAC,GAAW,CAAC,GAAG,eAAe,CAAC;AAEtC,MAAM,QAAQ,GAAW,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAQrC,SAAgB,EAAE,CAAC,QAAe;IAC9B,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrB,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAA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AI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts"],"errors":true,"version":"6.0.2"}
@@ -0,0 +1,79 @@
1
+ // @ts-check
2
+ import eslint from '@eslint/js';
3
+ import tseslint from 'typescript-eslint';
4
+ import perfectionist from 'eslint-plugin-perfectionist';
5
+ import globals from 'globals';
6
+
7
+ export default tseslint.config(
8
+ // 1. Globala ignoreringar (ersätter din gamla ignores-block)
9
+ {
10
+ ignores: [
11
+ 'dist/**',
12
+ 'coverage/**',
13
+ 'report/**',
14
+ 'node_modules/**',
15
+ 'doc/**',
16
+ '*.config.*'
17
+ ],
18
+ },
19
+
20
+ // 2. Bas-konfiguration (JS & TS Rekommenderat + Sortering)
21
+ eslint.configs.recommended,
22
+ ...tseslint.configs.recommended,
23
+ perfectionist.configs['recommended-natural'],
24
+
25
+ // 3. Gemensamma inställningar för alla filer
26
+ {
27
+ languageOptions: {
28
+ ecmaVersion: 'latest',
29
+ sourceType: 'module',
30
+ globals: {
31
+ ...globals.node,
32
+ ...globals.vitest, // Lägger till describe, it, expect etc. automatiskt
33
+ },
34
+ },
35
+ rules: {
36
+ // Allmänna regler
37
+ 'no-console': 'error',
38
+ 'no-var': 'error',
39
+ 'prefer-const': 'error',
40
+ 'eqeqeq': ['error', 'always'],
41
+ 'curly': 'error',
42
+ 'no-throw-literal': 'error',
43
+
44
+ // TypeScript-specifika regler (utan typ-check krav)
45
+ '@typescript-eslint/no-unused-vars': 'warn',
46
+ '@typescript-eslint/explicit-function-return-type': 'error',
47
+ '@typescript-eslint/no-explicit-any': 'warn',
48
+ '@typescript-eslint/consistent-type-assertions': ['error', { assertionStyle: 'as' }],
49
+
50
+ // Perfectionist sköter nu all sortering (imports, keys, class members)
51
+ // Du behöver inte längre definiera order[] manuellt om du inte vill ha en special-ordning.
52
+ },
53
+ },
54
+
55
+ // 4. Konfiguration för källkod med strikt typ-check
56
+ {
57
+ files: ['src/**/*.ts'],
58
+ languageOptions: {
59
+ parserOptions: {
60
+ project: './tsconfig.json',
61
+ tsconfigRootDir: import.meta.dirname,
62
+ },
63
+ },
64
+ rules: {
65
+ // Här kan du lägga till regler som kräver projekt-context
66
+ '@typescript-eslint/prefer-readonly': 'error',
67
+ '@typescript-eslint/require-array-sort-compare': 'error',
68
+ },
69
+ },
70
+
71
+ // 5. Undantag för tester och exempel (tillåt console etc.)
72
+ {
73
+ files: ['test/**/*.ts', 'example/**/*.ts'],
74
+ rules: {
75
+ 'no-console': 'off', // Tillåt console i exempel och tester
76
+ '@typescript-eslint/no-explicit-any': 'off',
77
+ },
78
+ }
79
+ );
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
- {
2
- "name": "@ulrik.ek/wgs84",
3
- "version": "1.0.4",
4
- "description": "Basic library for computing small distances between WGS84 coordinates using a flat earth approximation.",
5
- "author": "Ulrik E.",
6
- "license": "MIT",
7
- "main": "dist/index.js",
8
- "directories": {
9
- "doc": "doc",
10
- "test": "test"
11
- },
12
- "type": "commonjs",
13
- "scripts": {
14
- "audit": "npm audit --registry=https://registry.npmjs.org",
15
- "lint": "npx eslint .",
16
- "lint_fix": "npx eslint . --fix",
17
- "style": "npx prettier --check \"./**/*.ts\" --check \"./**/*.json\" --check \"./**/*.md\"",
18
- "style_fix": "npx prettier --write \"./**/*.ts\" --write \"./**/*.json\" --write \"./**/*.md\"",
19
- "verify_and_install": "npm cache verify && npm install",
20
- "clean": "npx shx rm -rf ./coverage/ ./report/ ./dist/",
21
- "build": "tsc --build tsconfig.json",
22
- "test": "npm run clean && npx jest --clearCache && jest --verbose --coverage --color --modulePathIgnorePatterns=./dist/ && npm run build",
23
- "run_example": "npx ts-node example/index.ts",
24
- "type_doc": "npx typedoc --plugin typedoc-plugin-markdown --out doc src/index.ts --excludeNotDocumented"
25
- },
26
- "devDependencies": {
27
- "@types/geojson": "^7946.0.14",
28
- "@types/jest": "^29.5.12",
29
- "@types/node": "^22.1.0",
30
- "@typescript-eslint/eslint-plugin": "^7.5.0",
31
- "@typescript-eslint/parser": "^7.5.0",
32
- "eslint": "^8.57.0",
33
- "eslint-plugin-import": "^2.29.1",
34
- "eslint-plugin-jest": "^27.9.0",
35
- "eslint-plugin-json": "^3.1.0",
36
- "eslint-plugin-simple-import-sort": "^12.0.0",
37
- "eslint-plugin-sort-class-members": "^1.20.0",
38
- "eslint-plugin-sort-keys-fix": "^1.1.2",
39
- "eslint-plugin-unicorn": "^52.0.0",
40
- "eslint-plugin-yaml": "^0.5.0",
41
- "jest": "^29.7.0",
42
- "jest-junit": "^16.0.0",
43
- "prettier": "3.3.0",
44
- "shx": "^0.3.4",
45
- "ts-jest": "^29.1.2",
46
- "ts-node": "^10.9.2",
47
- "typedoc": "^0.26.5",
48
- "typedoc-plugin-markdown": "^4.2.3",
49
- "typescript": "^5.5.4"
50
- },
51
- "types": "./dist/index.d.ts",
52
- "repository": {
53
- "type": "git",
54
- "url": "git+https://github.com/UEk/wgs84.git"
55
- },
56
- "bugs": {
57
- "url": "https://github.com/UEk/wgs84/issues"
58
- },
59
- "homepage": "https://github.com/UEk/wgs84#readme",
60
- "keywords": ["wgs84", "geojson", "latitude", "longitude"]
61
- }
1
+ {
2
+ "name": "@ulrik.ek/wgs84",
3
+ "version": "1.1.0",
4
+ "description": "Basic library for computing small distances between WGS84 coordinates using a flat earth approximation.",
5
+ "author": "Ulrik E.",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "directories": {
9
+ "doc": "doc",
10
+ "test": "test"
11
+ },
12
+ "type": "commonjs",
13
+ "scripts": {
14
+ "audit": "npm audit --registry=https://registry.npmjs.org",
15
+ "lint": "npx eslint .",
16
+ "lint_fix": "npx eslint . --fix",
17
+ "style": "npx prettier --check \"./**/*.ts\" --check \"./**/*.json\" --check \"./**/*.md\"",
18
+ "style_fix": "npx prettier --write \"./**/*.ts\" --write \"./**/*.json\" --write \"./**/*.md\"",
19
+ "verify_and_install": "npm cache verify && npm install",
20
+ "clean": "npx shx rm -rf ./coverage/ ./report/ ./dist/",
21
+ "build": "tsc --build tsconfig.json",
22
+ "test": "vitest run --coverage",
23
+ "test:watch": "vitest",
24
+ "run_example": "npx tsx example/index.ts",
25
+ "type_doc": "npx typedoc --plugin typedoc-plugin-markdown --out doc src/index.ts --excludeNotDocumented"
26
+ },
27
+ "devDependencies": {
28
+ "@eslint/js": "^10.0.1",
29
+ "@types/geojson": "^7946.0.16",
30
+ "@types/jest": "^30.0.0",
31
+ "@types/node": "^25.5.2",
32
+ "@vitest/coverage-v8": "^4.1.2",
33
+ "eslint": "^10.2.0",
34
+ "eslint-plugin-perfectionist": "^5.8.0",
35
+ "globals": "^17.4.0",
36
+ "prettier": "^3.8.1",
37
+ "shx": "^0.4.0",
38
+ "ts-jest": "^29.4.9",
39
+ "tsx": "^4.21.0",
40
+ "typedoc": "^0.28.18",
41
+ "typedoc-plugin-markdown": "^4.11.0",
42
+ "typescript": "^6.0.2",
43
+ "typescript-eslint": "^8.58.0",
44
+ "vitest": "^4.1.2"
45
+ },
46
+ "types": "./dist/index.d.ts",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/UEk/wgs84.git"
50
+ },
51
+ "bugs": {
52
+ "url": "https://github.com/UEk/wgs84/issues"
53
+ },
54
+ "homepage": "https://github.com/UEk/wgs84#readme",
55
+ "keywords": [
56
+ "wgs84",
57
+ "geojson",
58
+ "latitude",
59
+ "longitude"
60
+ ]
61
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/index.ts"],"version":"6.0.2"}
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true, // Gör att 'describe', 'it', 'expect' finns tillgängliga globalt (som i Jest)
6
+ environment: 'node',
7
+ coverage: {
8
+ provider: 'v8',
9
+ reporter: ['text', 'json', 'html']
10
+ }
11
+ }
12
+ });