@turf/angle 7.0.0-alpha.0 → 7.0.0-alpha.110
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 +4 -9
- package/dist/cjs/index.cjs +42 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +4 -2
- package/dist/esm/index.d.mts +24 -0
- package/dist/esm/index.mjs +42 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +38 -32
- package/dist/es/index.js +0 -49
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -52
package/README.md
CHANGED
|
@@ -34,26 +34,21 @@ Returns **[number][4]** Angle between the provided points, or its explementary.
|
|
|
34
34
|
|
|
35
35
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
36
36
|
|
|
37
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
38
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
39
|
-
./scripts/generate-readmes in the turf project. -->
|
|
37
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
40
38
|
|
|
41
39
|
---
|
|
42
40
|
|
|
43
|
-
This module is part of the [Turfjs project](
|
|
44
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
45
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
46
|
-
PRs and issues.
|
|
41
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
47
42
|
|
|
48
43
|
### Installation
|
|
49
44
|
|
|
50
|
-
Install this module individually:
|
|
45
|
+
Install this single module individually:
|
|
51
46
|
|
|
52
47
|
```sh
|
|
53
48
|
$ npm install @turf/angle
|
|
54
49
|
```
|
|
55
50
|
|
|
56
|
-
Or install the
|
|
51
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
57
52
|
|
|
58
53
|
```sh
|
|
59
54
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _bearing = require('@turf/bearing');
|
|
6
|
+
var _helpers = require('@turf/helpers');
|
|
7
|
+
var _rhumbbearing = require('@turf/rhumb-bearing');
|
|
8
|
+
function angle(startPoint, midPoint, endPoint, options = {}) {
|
|
9
|
+
if (!_helpers.isObject.call(void 0, options)) {
|
|
10
|
+
throw new Error("options is invalid");
|
|
11
|
+
}
|
|
12
|
+
if (!startPoint) {
|
|
13
|
+
throw new Error("startPoint is required");
|
|
14
|
+
}
|
|
15
|
+
if (!midPoint) {
|
|
16
|
+
throw new Error("midPoint is required");
|
|
17
|
+
}
|
|
18
|
+
if (!endPoint) {
|
|
19
|
+
throw new Error("endPoint is required");
|
|
20
|
+
}
|
|
21
|
+
const A = startPoint;
|
|
22
|
+
const O = midPoint;
|
|
23
|
+
const B = endPoint;
|
|
24
|
+
const azimuthAO = _helpers.bearingToAzimuth.call(void 0,
|
|
25
|
+
options.mercator !== true ? _bearing.bearing.call(void 0, A, O) : _rhumbbearing.rhumbBearing.call(void 0, A, O)
|
|
26
|
+
);
|
|
27
|
+
const azimuthBO = _helpers.bearingToAzimuth.call(void 0,
|
|
28
|
+
options.mercator !== true ? _bearing.bearing.call(void 0, B, O) : _rhumbbearing.rhumbBearing.call(void 0, B, O)
|
|
29
|
+
);
|
|
30
|
+
const angleAO = Math.abs(azimuthAO - azimuthBO);
|
|
31
|
+
if (options.explementary === true) {
|
|
32
|
+
return 360 - angleAO;
|
|
33
|
+
}
|
|
34
|
+
return angleAO;
|
|
35
|
+
}
|
|
36
|
+
__name(angle, "angle");
|
|
37
|
+
var turf_angle_default = angle;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.angle = angle; exports.default = turf_angle_default;
|
|
42
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAAA,SAAS,eAAe;AACxB,SAAS,kBAAyB,gBAAgB;AAClD,SAAS,oBAAoB;AAkB7B,SAAS,MACP,YACA,UACA,UACA,UAGI,CAAC,GACG;AAER,MAAI,CAAC,SAAS,OAAO,GAAG;AACtB,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAGA,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AACA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,sBAAsB;AAAA,EACxC;AACA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,sBAAsB;AAAA,EACxC;AAGA,QAAM,IAAI;AACV,QAAM,IAAI;AACV,QAAM,IAAI;AAGV,QAAM,YAAY;AAAA,IAChB,QAAQ,aAAa,OAAO,QAAQ,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC;AAAA,EAC/D;AACA,QAAM,YAAY;AAAA,IAChB,QAAQ,aAAa,OAAO,QAAQ,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC;AAAA,EAC/D;AACA,QAAM,UAAU,KAAK,IAAI,YAAY,SAAS;AAG9C,MAAI,QAAQ,iBAAiB,MAAM;AACjC,WAAO,MAAM;AAAA,EACf;AACA,SAAO;AACT;AA5CS;AA+CT,IAAO,qBAAQ","sourcesContent":["import { bearing } from \"@turf/bearing\";\nimport { bearingToAzimuth, Coord, isObject } from \"@turf/helpers\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\n\n/**\n * Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)\n * angle with origin on the `startPoint-midPoint` segment, or its explementary angle if required.\n *\n * @name angle\n * @param {Coord} startPoint Start Point Coordinates\n * @param {Coord} midPoint Mid Point Coordinates\n * @param {Coord} endPoint End Point Coordinates\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.explementary=false] Returns the explementary angle instead (360 - angle)\n * @param {boolean} [options.mercator=false] if calculations should be performed over Mercator or WGS84 projection\n * @returns {number} Angle between the provided points, or its explementary.\n * @example\n * turf.angle([5, 5], [5, 6], [3, 4]);\n * //=45\n */\nfunction angle(\n startPoint: Coord,\n midPoint: Coord,\n endPoint: Coord,\n options: {\n explementary?: boolean;\n mercator?: boolean;\n } = {}\n): number {\n // Optional Parameters\n if (!isObject(options)) {\n throw new Error(\"options is invalid\");\n }\n\n // Validation\n if (!startPoint) {\n throw new Error(\"startPoint is required\");\n }\n if (!midPoint) {\n throw new Error(\"midPoint is required\");\n }\n if (!endPoint) {\n throw new Error(\"endPoint is required\");\n }\n\n // Rename to shorter variables\n const A = startPoint;\n const O = midPoint;\n const B = endPoint;\n\n // Main\n const azimuthAO = bearingToAzimuth(\n options.mercator !== true ? bearing(A, O) : rhumbBearing(A, O)\n );\n const azimuthBO = bearingToAzimuth(\n options.mercator !== true ? bearing(B, O) : rhumbBearing(B, O)\n );\n const angleAO = Math.abs(azimuthAO - azimuthBO);\n\n // Explementary angle\n if (options.explementary === true) {\n return 360 - angleAO;\n }\n return angleAO;\n}\n\nexport { angle };\nexport default angle;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Coord } from
|
|
1
|
+
import { Coord } from '@turf/helpers';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)
|
|
4
5
|
* angle with origin on the `startPoint-midPoint` segment, or its explementary angle if required.
|
|
@@ -19,4 +20,5 @@ declare function angle(startPoint: Coord, midPoint: Coord, endPoint: Coord, opti
|
|
|
19
20
|
explementary?: boolean;
|
|
20
21
|
mercator?: boolean;
|
|
21
22
|
}): number;
|
|
22
|
-
|
|
23
|
+
|
|
24
|
+
export { angle, angle as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Coord } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)
|
|
5
|
+
* angle with origin on the `startPoint-midPoint` segment, or its explementary angle if required.
|
|
6
|
+
*
|
|
7
|
+
* @name angle
|
|
8
|
+
* @param {Coord} startPoint Start Point Coordinates
|
|
9
|
+
* @param {Coord} midPoint Mid Point Coordinates
|
|
10
|
+
* @param {Coord} endPoint End Point Coordinates
|
|
11
|
+
* @param {Object} [options={}] Optional parameters
|
|
12
|
+
* @param {boolean} [options.explementary=false] Returns the explementary angle instead (360 - angle)
|
|
13
|
+
* @param {boolean} [options.mercator=false] if calculations should be performed over Mercator or WGS84 projection
|
|
14
|
+
* @returns {number} Angle between the provided points, or its explementary.
|
|
15
|
+
* @example
|
|
16
|
+
* turf.angle([5, 5], [5, 6], [3, 4]);
|
|
17
|
+
* //=45
|
|
18
|
+
*/
|
|
19
|
+
declare function angle(startPoint: Coord, midPoint: Coord, endPoint: Coord, options?: {
|
|
20
|
+
explementary?: boolean;
|
|
21
|
+
mercator?: boolean;
|
|
22
|
+
}): number;
|
|
23
|
+
|
|
24
|
+
export { angle, angle as default };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { bearing } from "@turf/bearing";
|
|
6
|
+
import { bearingToAzimuth, isObject } from "@turf/helpers";
|
|
7
|
+
import { rhumbBearing } from "@turf/rhumb-bearing";
|
|
8
|
+
function angle(startPoint, midPoint, endPoint, options = {}) {
|
|
9
|
+
if (!isObject(options)) {
|
|
10
|
+
throw new Error("options is invalid");
|
|
11
|
+
}
|
|
12
|
+
if (!startPoint) {
|
|
13
|
+
throw new Error("startPoint is required");
|
|
14
|
+
}
|
|
15
|
+
if (!midPoint) {
|
|
16
|
+
throw new Error("midPoint is required");
|
|
17
|
+
}
|
|
18
|
+
if (!endPoint) {
|
|
19
|
+
throw new Error("endPoint is required");
|
|
20
|
+
}
|
|
21
|
+
const A = startPoint;
|
|
22
|
+
const O = midPoint;
|
|
23
|
+
const B = endPoint;
|
|
24
|
+
const azimuthAO = bearingToAzimuth(
|
|
25
|
+
options.mercator !== true ? bearing(A, O) : rhumbBearing(A, O)
|
|
26
|
+
);
|
|
27
|
+
const azimuthBO = bearingToAzimuth(
|
|
28
|
+
options.mercator !== true ? bearing(B, O) : rhumbBearing(B, O)
|
|
29
|
+
);
|
|
30
|
+
const angleAO = Math.abs(azimuthAO - azimuthBO);
|
|
31
|
+
if (options.explementary === true) {
|
|
32
|
+
return 360 - angleAO;
|
|
33
|
+
}
|
|
34
|
+
return angleAO;
|
|
35
|
+
}
|
|
36
|
+
__name(angle, "angle");
|
|
37
|
+
var turf_angle_default = angle;
|
|
38
|
+
export {
|
|
39
|
+
angle,
|
|
40
|
+
turf_angle_default as default
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { bearing } from \"@turf/bearing\";\nimport { bearingToAzimuth, Coord, isObject } from \"@turf/helpers\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\n\n/**\n * Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)\n * angle with origin on the `startPoint-midPoint` segment, or its explementary angle if required.\n *\n * @name angle\n * @param {Coord} startPoint Start Point Coordinates\n * @param {Coord} midPoint Mid Point Coordinates\n * @param {Coord} endPoint End Point Coordinates\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.explementary=false] Returns the explementary angle instead (360 - angle)\n * @param {boolean} [options.mercator=false] if calculations should be performed over Mercator or WGS84 projection\n * @returns {number} Angle between the provided points, or its explementary.\n * @example\n * turf.angle([5, 5], [5, 6], [3, 4]);\n * //=45\n */\nfunction angle(\n startPoint: Coord,\n midPoint: Coord,\n endPoint: Coord,\n options: {\n explementary?: boolean;\n mercator?: boolean;\n } = {}\n): number {\n // Optional Parameters\n if (!isObject(options)) {\n throw new Error(\"options is invalid\");\n }\n\n // Validation\n if (!startPoint) {\n throw new Error(\"startPoint is required\");\n }\n if (!midPoint) {\n throw new Error(\"midPoint is required\");\n }\n if (!endPoint) {\n throw new Error(\"endPoint is required\");\n }\n\n // Rename to shorter variables\n const A = startPoint;\n const O = midPoint;\n const B = endPoint;\n\n // Main\n const azimuthAO = bearingToAzimuth(\n options.mercator !== true ? bearing(A, O) : rhumbBearing(A, O)\n );\n const azimuthBO = bearingToAzimuth(\n options.mercator !== true ? bearing(B, O) : rhumbBearing(B, O)\n );\n const angleAO = Math.abs(azimuthAO - azimuthBO);\n\n // Explementary angle\n if (options.explementary === true) {\n return 360 - angleAO;\n }\n return angleAO;\n}\n\nexport { angle };\nexport default angle;\n"],"mappings":";;;;AAAA,SAAS,eAAe;AACxB,SAAS,kBAAyB,gBAAgB;AAClD,SAAS,oBAAoB;AAkB7B,SAAS,MACP,YACA,UACA,UACA,UAGI,CAAC,GACG;AAER,MAAI,CAAC,SAAS,OAAO,GAAG;AACtB,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAGA,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AACA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,sBAAsB;AAAA,EACxC;AACA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,sBAAsB;AAAA,EACxC;AAGA,QAAM,IAAI;AACV,QAAM,IAAI;AACV,QAAM,IAAI;AAGV,QAAM,YAAY;AAAA,IAChB,QAAQ,aAAa,OAAO,QAAQ,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC;AAAA,EAC/D;AACA,QAAM,YAAY;AAAA,IAChB,QAAQ,aAAa,OAAO,QAAQ,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC;AAAA,EAC/D;AACA,QAAM,UAAU,KAAK,IAAI,YAAY,SAAS;AAG9C,MAAI,QAAQ,iBAAiB,MAAM;AACjC,WAAO,MAAM;AAAA,EACf;AACA,SAAO;AACT;AA5CS;AA+CT,IAAO,qBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/angle",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf angle module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -23,50 +23,56 @@
|
|
|
23
23
|
"turf",
|
|
24
24
|
"angle"
|
|
25
25
|
],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"type": "commonjs",
|
|
27
|
+
"main": "dist/cjs/index.cjs",
|
|
28
|
+
"module": "dist/esm/index.mjs",
|
|
29
|
+
"types": "dist/cjs/index.d.ts",
|
|
28
30
|
"exports": {
|
|
29
31
|
"./package.json": "./package.json",
|
|
30
32
|
".": {
|
|
31
|
-
"import":
|
|
32
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/esm/index.d.mts",
|
|
35
|
+
"default": "./dist/esm/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/index.d.ts",
|
|
39
|
+
"default": "./dist/cjs/index.cjs"
|
|
40
|
+
}
|
|
33
41
|
}
|
|
34
42
|
},
|
|
35
|
-
"types": "dist/js/index.d.ts",
|
|
36
43
|
"sideEffects": false,
|
|
37
44
|
"files": [
|
|
38
45
|
"dist"
|
|
39
46
|
],
|
|
40
47
|
"scripts": {
|
|
41
|
-
"bench": "
|
|
42
|
-
"build": "
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"test": "npm-run-all test:*",
|
|
47
|
-
"test:tape": "ts-node -r esm test.js"
|
|
48
|
+
"bench": "tsx bench.ts",
|
|
49
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
50
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
51
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
52
|
+
"test:tape": "tsx test.ts"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
|
-
"@turf/distance": "^7.0.0-alpha.
|
|
51
|
-
"@turf/sector": "^7.0.0-alpha.
|
|
52
|
-
"@turf/truncate": "^7.0.0-alpha.
|
|
53
|
-
"@types/
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
55
|
+
"@turf/distance": "^7.0.0-alpha.110+1411d63a7",
|
|
56
|
+
"@turf/sector": "^7.0.0-alpha.110+1411d63a7",
|
|
57
|
+
"@turf/truncate": "^7.0.0-alpha.110+1411d63a7",
|
|
58
|
+
"@types/benchmark": "^2.1.5",
|
|
59
|
+
"@types/tape": "^4.2.32",
|
|
60
|
+
"benchmark": "^2.1.4",
|
|
61
|
+
"glob": "^10.3.10",
|
|
62
|
+
"load-json-file": "^7.0.1",
|
|
63
|
+
"npm-run-all": "^4.1.5",
|
|
64
|
+
"tape": "^5.7.2",
|
|
65
|
+
"tsup": "^8.0.1",
|
|
66
|
+
"tsx": "^4.6.2",
|
|
67
|
+
"typescript": "^5.2.2",
|
|
68
|
+
"write-json-file": "^5.0.0"
|
|
63
69
|
},
|
|
64
70
|
"dependencies": {
|
|
65
|
-
"@turf/bearing": "^7.0.0-alpha.
|
|
66
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
67
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
68
|
-
"@turf/rhumb-bearing": "^7.0.0-alpha.
|
|
69
|
-
"tslib": "^2.
|
|
71
|
+
"@turf/bearing": "^7.0.0-alpha.110+1411d63a7",
|
|
72
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
73
|
+
"@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
|
|
74
|
+
"@turf/rhumb-bearing": "^7.0.0-alpha.110+1411d63a7",
|
|
75
|
+
"tslib": "^2.6.2"
|
|
70
76
|
},
|
|
71
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
72
78
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import bearing from "@turf/bearing";
|
|
2
|
-
import { bearingToAzimuth, isObject } from "@turf/helpers";
|
|
3
|
-
import rhumbBearing from "@turf/rhumb-bearing";
|
|
4
|
-
/**
|
|
5
|
-
* Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)
|
|
6
|
-
* angle with origin on the `startPoint-midPoint` segment, or its explementary angle if required.
|
|
7
|
-
*
|
|
8
|
-
* @name angle
|
|
9
|
-
* @param {Coord} startPoint Start Point Coordinates
|
|
10
|
-
* @param {Coord} midPoint Mid Point Coordinates
|
|
11
|
-
* @param {Coord} endPoint End Point Coordinates
|
|
12
|
-
* @param {Object} [options={}] Optional parameters
|
|
13
|
-
* @param {boolean} [options.explementary=false] Returns the explementary angle instead (360 - angle)
|
|
14
|
-
* @param {boolean} [options.mercator=false] if calculations should be performed over Mercator or WGS84 projection
|
|
15
|
-
* @returns {number} Angle between the provided points, or its explementary.
|
|
16
|
-
* @example
|
|
17
|
-
* turf.angle([5, 5], [5, 6], [3, 4]);
|
|
18
|
-
* //=45
|
|
19
|
-
*/
|
|
20
|
-
function angle(startPoint, midPoint, endPoint, options = {}) {
|
|
21
|
-
// Optional Parameters
|
|
22
|
-
if (!isObject(options)) {
|
|
23
|
-
throw new Error("options is invalid");
|
|
24
|
-
}
|
|
25
|
-
// Validation
|
|
26
|
-
if (!startPoint) {
|
|
27
|
-
throw new Error("startPoint is required");
|
|
28
|
-
}
|
|
29
|
-
if (!midPoint) {
|
|
30
|
-
throw new Error("midPoint is required");
|
|
31
|
-
}
|
|
32
|
-
if (!endPoint) {
|
|
33
|
-
throw new Error("endPoint is required");
|
|
34
|
-
}
|
|
35
|
-
// Rename to shorter variables
|
|
36
|
-
const A = startPoint;
|
|
37
|
-
const O = midPoint;
|
|
38
|
-
const B = endPoint;
|
|
39
|
-
// Main
|
|
40
|
-
const azimuthAO = bearingToAzimuth(options.mercator !== true ? bearing(A, O) : rhumbBearing(A, O));
|
|
41
|
-
const azimuthBO = bearingToAzimuth(options.mercator !== true ? bearing(B, O) : rhumbBearing(B, O));
|
|
42
|
-
const angleAO = Math.abs(azimuthAO - azimuthBO);
|
|
43
|
-
// Explementary angle
|
|
44
|
-
if (options.explementary === true) {
|
|
45
|
-
return 360 - angleAO;
|
|
46
|
-
}
|
|
47
|
-
return angleAO;
|
|
48
|
-
}
|
|
49
|
-
export default angle;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const bearing_1 = tslib_1.__importDefault(require("@turf/bearing"));
|
|
5
|
-
const helpers_1 = require("@turf/helpers");
|
|
6
|
-
const rhumb_bearing_1 = tslib_1.__importDefault(require("@turf/rhumb-bearing"));
|
|
7
|
-
/**
|
|
8
|
-
* Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)
|
|
9
|
-
* angle with origin on the `startPoint-midPoint` segment, or its explementary angle if required.
|
|
10
|
-
*
|
|
11
|
-
* @name angle
|
|
12
|
-
* @param {Coord} startPoint Start Point Coordinates
|
|
13
|
-
* @param {Coord} midPoint Mid Point Coordinates
|
|
14
|
-
* @param {Coord} endPoint End Point Coordinates
|
|
15
|
-
* @param {Object} [options={}] Optional parameters
|
|
16
|
-
* @param {boolean} [options.explementary=false] Returns the explementary angle instead (360 - angle)
|
|
17
|
-
* @param {boolean} [options.mercator=false] if calculations should be performed over Mercator or WGS84 projection
|
|
18
|
-
* @returns {number} Angle between the provided points, or its explementary.
|
|
19
|
-
* @example
|
|
20
|
-
* turf.angle([5, 5], [5, 6], [3, 4]);
|
|
21
|
-
* //=45
|
|
22
|
-
*/
|
|
23
|
-
function angle(startPoint, midPoint, endPoint, options = {}) {
|
|
24
|
-
// Optional Parameters
|
|
25
|
-
if (!helpers_1.isObject(options)) {
|
|
26
|
-
throw new Error("options is invalid");
|
|
27
|
-
}
|
|
28
|
-
// Validation
|
|
29
|
-
if (!startPoint) {
|
|
30
|
-
throw new Error("startPoint is required");
|
|
31
|
-
}
|
|
32
|
-
if (!midPoint) {
|
|
33
|
-
throw new Error("midPoint is required");
|
|
34
|
-
}
|
|
35
|
-
if (!endPoint) {
|
|
36
|
-
throw new Error("endPoint is required");
|
|
37
|
-
}
|
|
38
|
-
// Rename to shorter variables
|
|
39
|
-
const A = startPoint;
|
|
40
|
-
const O = midPoint;
|
|
41
|
-
const B = endPoint;
|
|
42
|
-
// Main
|
|
43
|
-
const azimuthAO = helpers_1.bearingToAzimuth(options.mercator !== true ? bearing_1.default(A, O) : rhumb_bearing_1.default(A, O));
|
|
44
|
-
const azimuthBO = helpers_1.bearingToAzimuth(options.mercator !== true ? bearing_1.default(B, O) : rhumb_bearing_1.default(B, O));
|
|
45
|
-
const angleAO = Math.abs(azimuthAO - azimuthBO);
|
|
46
|
-
// Explementary angle
|
|
47
|
-
if (options.explementary === true) {
|
|
48
|
-
return 360 - angleAO;
|
|
49
|
-
}
|
|
50
|
-
return angleAO;
|
|
51
|
-
}
|
|
52
|
-
exports.default = angle;
|