@turf/point-to-line-distance 7.0.0-alpha.1 → 7.0.0-alpha.111
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 +84 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +5 -3
- package/dist/esm/index.d.mts +29 -0
- package/dist/esm/index.mjs +84 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +39 -34
- package/dist/es/index.js +0 -104
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -107
package/README.md
CHANGED
|
@@ -48,26 +48,21 @@ Returns **[number][6]** distance between point and line
|
|
|
48
48
|
|
|
49
49
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
50
50
|
|
|
51
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
52
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
53
|
-
./scripts/generate-readmes in the turf project. -->
|
|
51
|
+
<!-- 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. -->
|
|
54
52
|
|
|
55
53
|
---
|
|
56
54
|
|
|
57
|
-
This module is part of the [Turfjs project](
|
|
58
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
59
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
60
|
-
PRs and issues.
|
|
55
|
+
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.
|
|
61
56
|
|
|
62
57
|
### Installation
|
|
63
58
|
|
|
64
|
-
Install this module individually:
|
|
59
|
+
Install this single module individually:
|
|
65
60
|
|
|
66
61
|
```sh
|
|
67
62
|
$ npm install @turf/point-to-line-distance
|
|
68
63
|
```
|
|
69
64
|
|
|
70
|
-
Or install the
|
|
65
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
71
66
|
|
|
72
67
|
```sh
|
|
73
68
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,84 @@
|
|
|
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 _distance = require('@turf/distance');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _helpers = require('@turf/helpers');
|
|
12
|
+
var _invariant = require('@turf/invariant');
|
|
13
|
+
var _meta = require('@turf/meta');
|
|
14
|
+
var _rhumbdistance = require('@turf/rhumb-distance');
|
|
15
|
+
function pointToLineDistance(pt, line, options = {}) {
|
|
16
|
+
if (!options.method) {
|
|
17
|
+
options.method = "geodesic";
|
|
18
|
+
}
|
|
19
|
+
if (!options.units) {
|
|
20
|
+
options.units = "kilometers";
|
|
21
|
+
}
|
|
22
|
+
if (!pt) {
|
|
23
|
+
throw new Error("pt is required");
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(pt)) {
|
|
26
|
+
pt = _helpers.point.call(void 0, pt);
|
|
27
|
+
} else if (pt.type === "Point") {
|
|
28
|
+
pt = _helpers.feature.call(void 0, pt);
|
|
29
|
+
} else {
|
|
30
|
+
_invariant.featureOf.call(void 0, pt, "Point", "point");
|
|
31
|
+
}
|
|
32
|
+
if (!line) {
|
|
33
|
+
throw new Error("line is required");
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(line)) {
|
|
36
|
+
line = _helpers.lineString.call(void 0, line);
|
|
37
|
+
} else if (line.type === "LineString") {
|
|
38
|
+
line = _helpers.feature.call(void 0, line);
|
|
39
|
+
} else {
|
|
40
|
+
_invariant.featureOf.call(void 0, line, "LineString", "line");
|
|
41
|
+
}
|
|
42
|
+
let distance = Infinity;
|
|
43
|
+
const p = pt.geometry.coordinates;
|
|
44
|
+
_meta.segmentEach.call(void 0, line, (segment) => {
|
|
45
|
+
const a = segment.geometry.coordinates[0];
|
|
46
|
+
const b = segment.geometry.coordinates[1];
|
|
47
|
+
const d = distanceToSegment(p, a, b, options);
|
|
48
|
+
if (d < distance) {
|
|
49
|
+
distance = d;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return _helpers.convertLength.call(void 0, distance, "degrees", options.units);
|
|
53
|
+
}
|
|
54
|
+
__name(pointToLineDistance, "pointToLineDistance");
|
|
55
|
+
function distanceToSegment(p, a, b, options) {
|
|
56
|
+
const v = [b[0] - a[0], b[1] - a[1]];
|
|
57
|
+
const w = [p[0] - a[0], p[1] - a[1]];
|
|
58
|
+
const c1 = dot(w, v);
|
|
59
|
+
if (c1 <= 0) {
|
|
60
|
+
return calcDistance(p, a, { method: options.method, units: "degrees" });
|
|
61
|
+
}
|
|
62
|
+
const c2 = dot(v, v);
|
|
63
|
+
if (c2 <= c1) {
|
|
64
|
+
return calcDistance(p, b, { method: options.method, units: "degrees" });
|
|
65
|
+
}
|
|
66
|
+
const b2 = c1 / c2;
|
|
67
|
+
const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
|
|
68
|
+
return calcDistance(p, Pb, { method: options.method, units: "degrees" });
|
|
69
|
+
}
|
|
70
|
+
__name(distanceToSegment, "distanceToSegment");
|
|
71
|
+
function dot(u, v) {
|
|
72
|
+
return u[0] * v[0] + u[1] * v[1];
|
|
73
|
+
}
|
|
74
|
+
__name(dot, "dot");
|
|
75
|
+
function calcDistance(a, b, options) {
|
|
76
|
+
return options.method === "planar" ? _rhumbdistance.rhumbDistance.call(void 0, a, b, options) : _distance.distance.call(void 0, a, b, options);
|
|
77
|
+
}
|
|
78
|
+
__name(calcDistance, "calcDistance");
|
|
79
|
+
var turf_point_to_line_distance_default = pointToLineDistance;
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
exports.default = turf_point_to_line_distance_default; exports.pointToLineDistance = pointToLineDistance;
|
|
84
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAEA,SAAS,YAAY,mBAAmB;AACxC;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,yBAAyB;AAsBnD,SAAS,oBACP,IACA,MACA,UAGI,CAAC,GACG;AAER,MAAI,CAAC,QAAQ,QAAQ;AACnB,YAAQ,SAAS;AAAA,EACnB;AACA,MAAI,CAAC,QAAQ,OAAO;AAClB,YAAQ,QAAQ;AAAA,EAClB;AAGA,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,gBAAgB;AAAA,EAClC;AACA,MAAI,MAAM,QAAQ,EAAE,GAAG;AACrB,SAAK,MAAM,EAAE;AAAA,EACf,WAAW,GAAG,SAAS,SAAS;AAC9B,SAAK,QAAQ,EAAE;AAAA,EACjB,OAAO;AACL,cAAU,IAAI,SAAS,OAAO;AAAA,EAChC;AAEA,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AACA,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAO,WAAW,IAAI;AAAA,EACxB,WAAW,KAAK,SAAS,cAAc;AACrC,WAAO,QAAQ,IAAI;AAAA,EACrB,OAAO;AACL,cAAU,MAAM,cAAc,MAAM;AAAA,EACtC;AAEA,MAAI,WAAW;AACf,QAAM,IAAI,GAAG,SAAS;AACtB,cAAY,MAAM,CAAC,YAAY;AAC7B,UAAM,IAAI,QAAS,SAAS,YAAY,CAAC;AACzC,UAAM,IAAI,QAAS,SAAS,YAAY,CAAC;AACzC,UAAM,IAAI,kBAAkB,GAAG,GAAG,GAAG,OAAO;AAC5C,QAAI,IAAI,UAAU;AAChB,iBAAW;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,cAAc,UAAU,WAAW,QAAQ,KAAK;AACzD;AAlDS;AA8DT,SAAS,kBACP,GACA,GACA,GACA,SACA;AACA,QAAM,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AACnC,QAAM,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAEnC,QAAM,KAAK,IAAI,GAAG,CAAC;AACnB,MAAI,MAAM,GAAG;AACX,WAAO,aAAa,GAAG,GAAG,EAAE,QAAQ,QAAQ,QAAQ,OAAO,UAAU,CAAC;AAAA,EACxE;AACA,QAAM,KAAK,IAAI,GAAG,CAAC;AACnB,MAAI,MAAM,IAAI;AACZ,WAAO,aAAa,GAAG,GAAG,EAAE,QAAQ,QAAQ,QAAQ,OAAO,UAAU,CAAC;AAAA,EACxE;AACA,QAAM,KAAK,KAAK;AAChB,QAAM,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;AAC9C,SAAO,aAAa,GAAG,IAAI,EAAE,QAAQ,QAAQ,QAAQ,OAAO,UAAU,CAAC;AACzE;AApBS;AAsBT,SAAS,IAAI,GAAa,GAAa;AACrC,SAAO,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACjC;AAFS;AAIT,SAAS,aAAa,GAAa,GAAa,SAAc;AAC5D,SAAO,QAAQ,WAAW,WACtB,kBAAkB,GAAG,GAAG,OAAO,IAC/B,YAAY,GAAG,GAAG,OAAO;AAC/B;AAJS;AAOT,IAAO,sCAAQ","sourcesContent":["// Taken from http://geomalgorithms.com/a02-_lines.html\nimport { Feature, LineString } from \"geojson\";\nimport { distance as getDistance } from \"@turf/distance\";\nimport {\n convertLength,\n Coord,\n feature,\n lineString,\n point,\n Units,\n} from \"@turf/helpers\";\nimport { featureOf } from \"@turf/invariant\";\nimport { segmentEach } from \"@turf/meta\";\nimport { rhumbDistance as getPlanarDistance } from \"@turf/rhumb-distance\";\n\n/**\n * Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the\n * minimum distance between the point and any segment of the `LineString`.\n *\n * @name pointToLineDistance\n * @param {Feature<Point>|Array<number>} pt Feature or Geometry\n * @param {Feature<LineString>} line GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be anything supported by turf/convertLength\n * (ex: degrees, radians, miles, or kilometers)\n * @param {string} [options.method=\"geodesic\"] wether to calculate the distance based on geodesic (spheroid) or\n * planar (flat) method. Valid options are 'geodesic' or 'planar'.\n * @returns {number} distance between point and line\n * @example\n * var pt = turf.point([0, 0]);\n * var line = turf.lineString([[1, 1],[-1, 1]]);\n *\n * var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});\n * //=69.11854715938406\n */\nfunction pointToLineDistance(\n pt: Coord,\n line: Feature<LineString> | LineString,\n options: {\n units?: Units;\n method?: \"geodesic\" | \"planar\";\n } = {}\n): number {\n // Optional parameters\n if (!options.method) {\n options.method = \"geodesic\";\n }\n if (!options.units) {\n options.units = \"kilometers\";\n }\n\n // validation\n if (!pt) {\n throw new Error(\"pt is required\");\n }\n if (Array.isArray(pt)) {\n pt = point(pt);\n } else if (pt.type === \"Point\") {\n pt = feature(pt);\n } else {\n featureOf(pt, \"Point\", \"point\");\n }\n\n if (!line) {\n throw new Error(\"line is required\");\n }\n if (Array.isArray(line)) {\n line = lineString(line);\n } else if (line.type === \"LineString\") {\n line = feature(line);\n } else {\n featureOf(line, \"LineString\", \"line\");\n }\n\n let distance = Infinity;\n const p = pt.geometry.coordinates;\n segmentEach(line, (segment) => {\n const a = segment!.geometry.coordinates[0];\n const b = segment!.geometry.coordinates[1];\n const d = distanceToSegment(p, a, b, options);\n if (d < distance) {\n distance = d;\n }\n });\n return convertLength(distance, \"degrees\", options.units);\n}\n\n/**\n * Returns the distance between a point P on a segment AB.\n *\n * @private\n * @param {Array<number>} p external point\n * @param {Array<number>} a first segment point\n * @param {Array<number>} b second segment point\n * @param {Object} [options={}] Optional parameters\n * @returns {number} distance\n */\nfunction distanceToSegment(\n p: number[],\n a: number[],\n b: number[],\n options: any\n) {\n const v = [b[0] - a[0], b[1] - a[1]];\n const w = [p[0] - a[0], p[1] - a[1]];\n\n const c1 = dot(w, v);\n if (c1 <= 0) {\n return calcDistance(p, a, { method: options.method, units: \"degrees\" });\n }\n const c2 = dot(v, v);\n if (c2 <= c1) {\n return calcDistance(p, b, { method: options.method, units: \"degrees\" });\n }\n const b2 = c1 / c2;\n const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];\n return calcDistance(p, Pb, { method: options.method, units: \"degrees\" });\n}\n\nfunction dot(u: number[], v: number[]) {\n return u[0] * v[0] + u[1] * v[1];\n}\n\nfunction calcDistance(a: number[], b: number[], options: any) {\n return options.method === \"planar\"\n ? getPlanarDistance(a, b, options)\n : getDistance(a, b, options);\n}\n\nexport { pointToLineDistance };\nexport default pointToLineDistance;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Feature, LineString } from
|
|
2
|
-
import { Coord, Units } from
|
|
1
|
+
import { Feature, LineString } from 'geojson';
|
|
2
|
+
import { Coord, Units } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
|
|
5
6
|
* minimum distance between the point and any segment of the `LineString`.
|
|
@@ -24,4 +25,5 @@ declare function pointToLineDistance(pt: Coord, line: Feature<LineString> | Line
|
|
|
24
25
|
units?: Units;
|
|
25
26
|
method?: "geodesic" | "planar";
|
|
26
27
|
}): number;
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
export { pointToLineDistance as default, pointToLineDistance };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Feature, LineString } from 'geojson';
|
|
2
|
+
import { Coord, Units } from '@turf/helpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
|
|
6
|
+
* minimum distance between the point and any segment of the `LineString`.
|
|
7
|
+
*
|
|
8
|
+
* @name pointToLineDistance
|
|
9
|
+
* @param {Feature<Point>|Array<number>} pt Feature or Geometry
|
|
10
|
+
* @param {Feature<LineString>} line GeoJSON Feature or Geometry
|
|
11
|
+
* @param {Object} [options={}] Optional parameters
|
|
12
|
+
* @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength
|
|
13
|
+
* (ex: degrees, radians, miles, or kilometers)
|
|
14
|
+
* @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or
|
|
15
|
+
* planar (flat) method. Valid options are 'geodesic' or 'planar'.
|
|
16
|
+
* @returns {number} distance between point and line
|
|
17
|
+
* @example
|
|
18
|
+
* var pt = turf.point([0, 0]);
|
|
19
|
+
* var line = turf.lineString([[1, 1],[-1, 1]]);
|
|
20
|
+
*
|
|
21
|
+
* var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
|
|
22
|
+
* //=69.11854715938406
|
|
23
|
+
*/
|
|
24
|
+
declare function pointToLineDistance(pt: Coord, line: Feature<LineString> | LineString, options?: {
|
|
25
|
+
units?: Units;
|
|
26
|
+
method?: "geodesic" | "planar";
|
|
27
|
+
}): number;
|
|
28
|
+
|
|
29
|
+
export { pointToLineDistance as default, pointToLineDistance };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { distance as getDistance } from "@turf/distance";
|
|
6
|
+
import {
|
|
7
|
+
convertLength,
|
|
8
|
+
feature,
|
|
9
|
+
lineString,
|
|
10
|
+
point
|
|
11
|
+
} from "@turf/helpers";
|
|
12
|
+
import { featureOf } from "@turf/invariant";
|
|
13
|
+
import { segmentEach } from "@turf/meta";
|
|
14
|
+
import { rhumbDistance as getPlanarDistance } from "@turf/rhumb-distance";
|
|
15
|
+
function pointToLineDistance(pt, line, options = {}) {
|
|
16
|
+
if (!options.method) {
|
|
17
|
+
options.method = "geodesic";
|
|
18
|
+
}
|
|
19
|
+
if (!options.units) {
|
|
20
|
+
options.units = "kilometers";
|
|
21
|
+
}
|
|
22
|
+
if (!pt) {
|
|
23
|
+
throw new Error("pt is required");
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(pt)) {
|
|
26
|
+
pt = point(pt);
|
|
27
|
+
} else if (pt.type === "Point") {
|
|
28
|
+
pt = feature(pt);
|
|
29
|
+
} else {
|
|
30
|
+
featureOf(pt, "Point", "point");
|
|
31
|
+
}
|
|
32
|
+
if (!line) {
|
|
33
|
+
throw new Error("line is required");
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(line)) {
|
|
36
|
+
line = lineString(line);
|
|
37
|
+
} else if (line.type === "LineString") {
|
|
38
|
+
line = feature(line);
|
|
39
|
+
} else {
|
|
40
|
+
featureOf(line, "LineString", "line");
|
|
41
|
+
}
|
|
42
|
+
let distance = Infinity;
|
|
43
|
+
const p = pt.geometry.coordinates;
|
|
44
|
+
segmentEach(line, (segment) => {
|
|
45
|
+
const a = segment.geometry.coordinates[0];
|
|
46
|
+
const b = segment.geometry.coordinates[1];
|
|
47
|
+
const d = distanceToSegment(p, a, b, options);
|
|
48
|
+
if (d < distance) {
|
|
49
|
+
distance = d;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return convertLength(distance, "degrees", options.units);
|
|
53
|
+
}
|
|
54
|
+
__name(pointToLineDistance, "pointToLineDistance");
|
|
55
|
+
function distanceToSegment(p, a, b, options) {
|
|
56
|
+
const v = [b[0] - a[0], b[1] - a[1]];
|
|
57
|
+
const w = [p[0] - a[0], p[1] - a[1]];
|
|
58
|
+
const c1 = dot(w, v);
|
|
59
|
+
if (c1 <= 0) {
|
|
60
|
+
return calcDistance(p, a, { method: options.method, units: "degrees" });
|
|
61
|
+
}
|
|
62
|
+
const c2 = dot(v, v);
|
|
63
|
+
if (c2 <= c1) {
|
|
64
|
+
return calcDistance(p, b, { method: options.method, units: "degrees" });
|
|
65
|
+
}
|
|
66
|
+
const b2 = c1 / c2;
|
|
67
|
+
const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
|
|
68
|
+
return calcDistance(p, Pb, { method: options.method, units: "degrees" });
|
|
69
|
+
}
|
|
70
|
+
__name(distanceToSegment, "distanceToSegment");
|
|
71
|
+
function dot(u, v) {
|
|
72
|
+
return u[0] * v[0] + u[1] * v[1];
|
|
73
|
+
}
|
|
74
|
+
__name(dot, "dot");
|
|
75
|
+
function calcDistance(a, b, options) {
|
|
76
|
+
return options.method === "planar" ? getPlanarDistance(a, b, options) : getDistance(a, b, options);
|
|
77
|
+
}
|
|
78
|
+
__name(calcDistance, "calcDistance");
|
|
79
|
+
var turf_point_to_line_distance_default = pointToLineDistance;
|
|
80
|
+
export {
|
|
81
|
+
turf_point_to_line_distance_default as default,
|
|
82
|
+
pointToLineDistance
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["// Taken from http://geomalgorithms.com/a02-_lines.html\nimport { Feature, LineString } from \"geojson\";\nimport { distance as getDistance } from \"@turf/distance\";\nimport {\n convertLength,\n Coord,\n feature,\n lineString,\n point,\n Units,\n} from \"@turf/helpers\";\nimport { featureOf } from \"@turf/invariant\";\nimport { segmentEach } from \"@turf/meta\";\nimport { rhumbDistance as getPlanarDistance } from \"@turf/rhumb-distance\";\n\n/**\n * Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the\n * minimum distance between the point and any segment of the `LineString`.\n *\n * @name pointToLineDistance\n * @param {Feature<Point>|Array<number>} pt Feature or Geometry\n * @param {Feature<LineString>} line GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be anything supported by turf/convertLength\n * (ex: degrees, radians, miles, or kilometers)\n * @param {string} [options.method=\"geodesic\"] wether to calculate the distance based on geodesic (spheroid) or\n * planar (flat) method. Valid options are 'geodesic' or 'planar'.\n * @returns {number} distance between point and line\n * @example\n * var pt = turf.point([0, 0]);\n * var line = turf.lineString([[1, 1],[-1, 1]]);\n *\n * var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});\n * //=69.11854715938406\n */\nfunction pointToLineDistance(\n pt: Coord,\n line: Feature<LineString> | LineString,\n options: {\n units?: Units;\n method?: \"geodesic\" | \"planar\";\n } = {}\n): number {\n // Optional parameters\n if (!options.method) {\n options.method = \"geodesic\";\n }\n if (!options.units) {\n options.units = \"kilometers\";\n }\n\n // validation\n if (!pt) {\n throw new Error(\"pt is required\");\n }\n if (Array.isArray(pt)) {\n pt = point(pt);\n } else if (pt.type === \"Point\") {\n pt = feature(pt);\n } else {\n featureOf(pt, \"Point\", \"point\");\n }\n\n if (!line) {\n throw new Error(\"line is required\");\n }\n if (Array.isArray(line)) {\n line = lineString(line);\n } else if (line.type === \"LineString\") {\n line = feature(line);\n } else {\n featureOf(line, \"LineString\", \"line\");\n }\n\n let distance = Infinity;\n const p = pt.geometry.coordinates;\n segmentEach(line, (segment) => {\n const a = segment!.geometry.coordinates[0];\n const b = segment!.geometry.coordinates[1];\n const d = distanceToSegment(p, a, b, options);\n if (d < distance) {\n distance = d;\n }\n });\n return convertLength(distance, \"degrees\", options.units);\n}\n\n/**\n * Returns the distance between a point P on a segment AB.\n *\n * @private\n * @param {Array<number>} p external point\n * @param {Array<number>} a first segment point\n * @param {Array<number>} b second segment point\n * @param {Object} [options={}] Optional parameters\n * @returns {number} distance\n */\nfunction distanceToSegment(\n p: number[],\n a: number[],\n b: number[],\n options: any\n) {\n const v = [b[0] - a[0], b[1] - a[1]];\n const w = [p[0] - a[0], p[1] - a[1]];\n\n const c1 = dot(w, v);\n if (c1 <= 0) {\n return calcDistance(p, a, { method: options.method, units: \"degrees\" });\n }\n const c2 = dot(v, v);\n if (c2 <= c1) {\n return calcDistance(p, b, { method: options.method, units: \"degrees\" });\n }\n const b2 = c1 / c2;\n const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];\n return calcDistance(p, Pb, { method: options.method, units: \"degrees\" });\n}\n\nfunction dot(u: number[], v: number[]) {\n return u[0] * v[0] + u[1] * v[1];\n}\n\nfunction calcDistance(a: number[], b: number[], options: any) {\n return options.method === \"planar\"\n ? getPlanarDistance(a, b, options)\n : getDistance(a, b, options);\n}\n\nexport { pointToLineDistance };\nexport default pointToLineDistance;\n"],"mappings":";;;;AAEA,SAAS,YAAY,mBAAmB;AACxC;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,yBAAyB;AAsBnD,SAAS,oBACP,IACA,MACA,UAGI,CAAC,GACG;AAER,MAAI,CAAC,QAAQ,QAAQ;AACnB,YAAQ,SAAS;AAAA,EACnB;AACA,MAAI,CAAC,QAAQ,OAAO;AAClB,YAAQ,QAAQ;AAAA,EAClB;AAGA,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,gBAAgB;AAAA,EAClC;AACA,MAAI,MAAM,QAAQ,EAAE,GAAG;AACrB,SAAK,MAAM,EAAE;AAAA,EACf,WAAW,GAAG,SAAS,SAAS;AAC9B,SAAK,QAAQ,EAAE;AAAA,EACjB,OAAO;AACL,cAAU,IAAI,SAAS,OAAO;AAAA,EAChC;AAEA,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AACA,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAO,WAAW,IAAI;AAAA,EACxB,WAAW,KAAK,SAAS,cAAc;AACrC,WAAO,QAAQ,IAAI;AAAA,EACrB,OAAO;AACL,cAAU,MAAM,cAAc,MAAM;AAAA,EACtC;AAEA,MAAI,WAAW;AACf,QAAM,IAAI,GAAG,SAAS;AACtB,cAAY,MAAM,CAAC,YAAY;AAC7B,UAAM,IAAI,QAAS,SAAS,YAAY,CAAC;AACzC,UAAM,IAAI,QAAS,SAAS,YAAY,CAAC;AACzC,UAAM,IAAI,kBAAkB,GAAG,GAAG,GAAG,OAAO;AAC5C,QAAI,IAAI,UAAU;AAChB,iBAAW;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,cAAc,UAAU,WAAW,QAAQ,KAAK;AACzD;AAlDS;AA8DT,SAAS,kBACP,GACA,GACA,GACA,SACA;AACA,QAAM,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AACnC,QAAM,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAEnC,QAAM,KAAK,IAAI,GAAG,CAAC;AACnB,MAAI,MAAM,GAAG;AACX,WAAO,aAAa,GAAG,GAAG,EAAE,QAAQ,QAAQ,QAAQ,OAAO,UAAU,CAAC;AAAA,EACxE;AACA,QAAM,KAAK,IAAI,GAAG,CAAC;AACnB,MAAI,MAAM,IAAI;AACZ,WAAO,aAAa,GAAG,GAAG,EAAE,QAAQ,QAAQ,QAAQ,OAAO,UAAU,CAAC;AAAA,EACxE;AACA,QAAM,KAAK,KAAK;AAChB,QAAM,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;AAC9C,SAAO,aAAa,GAAG,IAAI,EAAE,QAAQ,QAAQ,QAAQ,OAAO,UAAU,CAAC;AACzE;AApBS;AAsBT,SAAS,IAAI,GAAa,GAAa;AACrC,SAAO,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACjC;AAFS;AAIT,SAAS,aAAa,GAAa,GAAa,SAAc;AAC5D,SAAO,QAAQ,WAAW,WACtB,kBAAkB,GAAG,GAAG,OAAO,IAC/B,YAAY,GAAG,GAAG,OAAO;AAC/B;AAJS;AAOT,IAAO,sCAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/point-to-line-distance",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.111+08576cb50",
|
|
4
4
|
"description": "turf point-to-line-distance module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -24,53 +24,58 @@
|
|
|
24
24
|
"point-to-line-distance",
|
|
25
25
|
"distance"
|
|
26
26
|
],
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"type": "commonjs",
|
|
28
|
+
"main": "dist/cjs/index.cjs",
|
|
29
|
+
"module": "dist/esm/index.mjs",
|
|
30
|
+
"types": "dist/cjs/index.d.ts",
|
|
29
31
|
"exports": {
|
|
30
32
|
"./package.json": "./package.json",
|
|
31
33
|
".": {
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/esm/index.d.mts",
|
|
36
|
+
"default": "./dist/esm/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/cjs/index.d.ts",
|
|
40
|
+
"default": "./dist/cjs/index.cjs"
|
|
41
|
+
}
|
|
35
42
|
}
|
|
36
43
|
},
|
|
37
|
-
"types": "dist/js/index.d.ts",
|
|
38
44
|
"sideEffects": false,
|
|
39
45
|
"files": [
|
|
40
46
|
"dist"
|
|
41
47
|
],
|
|
42
48
|
"scripts": {
|
|
43
|
-
"bench": "tsx bench.
|
|
44
|
-
"build": "
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"test": "npm-run-all test:*",
|
|
49
|
-
"test:tape": "tsx test.js",
|
|
49
|
+
"bench": "tsx bench.ts",
|
|
50
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
51
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
52
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
53
|
+
"test:tape": "tsx test.ts",
|
|
50
54
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
|
-
"@turf/circle": "^7.0.0-alpha.
|
|
54
|
-
"@types/
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
57
|
+
"@turf/circle": "^7.0.0-alpha.111+08576cb50",
|
|
58
|
+
"@types/benchmark": "^2.1.5",
|
|
59
|
+
"@types/tape": "^4.2.32",
|
|
60
|
+
"benchmark": "^2.1.4",
|
|
61
|
+
"load-json-file": "^7.0.1",
|
|
62
|
+
"npm-run-all": "^4.1.5",
|
|
63
|
+
"tape": "^5.7.2",
|
|
64
|
+
"tsup": "^8.0.1",
|
|
65
|
+
"tsx": "^4.6.2",
|
|
66
|
+
"typescript": "^5.2.2",
|
|
67
|
+
"write-json-file": "^5.0.0"
|
|
63
68
|
},
|
|
64
69
|
"dependencies": {
|
|
65
|
-
"@turf/bearing": "^7.0.0-alpha.
|
|
66
|
-
"@turf/distance": "^7.0.0-alpha.
|
|
67
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
68
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
69
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
70
|
-
"@turf/projection": "^7.0.0-alpha.
|
|
71
|
-
"@turf/rhumb-bearing": "^7.0.0-alpha.
|
|
72
|
-
"@turf/rhumb-distance": "^7.0.0-alpha.
|
|
73
|
-
"tslib": "^2.
|
|
70
|
+
"@turf/bearing": "^7.0.0-alpha.111+08576cb50",
|
|
71
|
+
"@turf/distance": "^7.0.0-alpha.111+08576cb50",
|
|
72
|
+
"@turf/helpers": "^7.0.0-alpha.111+08576cb50",
|
|
73
|
+
"@turf/invariant": "^7.0.0-alpha.111+08576cb50",
|
|
74
|
+
"@turf/meta": "^7.0.0-alpha.111+08576cb50",
|
|
75
|
+
"@turf/projection": "^7.0.0-alpha.111+08576cb50",
|
|
76
|
+
"@turf/rhumb-bearing": "^7.0.0-alpha.111+08576cb50",
|
|
77
|
+
"@turf/rhumb-distance": "^7.0.0-alpha.111+08576cb50",
|
|
78
|
+
"tslib": "^2.6.2"
|
|
74
79
|
},
|
|
75
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
|
|
76
81
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import getDistance from "@turf/distance";
|
|
2
|
-
import { convertLength, feature, lineString, point, } from "@turf/helpers";
|
|
3
|
-
import { featureOf } from "@turf/invariant";
|
|
4
|
-
import { segmentEach } from "@turf/meta";
|
|
5
|
-
import getPlanarDistance from "@turf/rhumb-distance";
|
|
6
|
-
/**
|
|
7
|
-
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
|
|
8
|
-
* minimum distance between the point and any segment of the `LineString`.
|
|
9
|
-
*
|
|
10
|
-
* @name pointToLineDistance
|
|
11
|
-
* @param {Feature<Point>|Array<number>} pt Feature or Geometry
|
|
12
|
-
* @param {Feature<LineString>} line GeoJSON Feature or Geometry
|
|
13
|
-
* @param {Object} [options={}] Optional parameters
|
|
14
|
-
* @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength
|
|
15
|
-
* (ex: degrees, radians, miles, or kilometers)
|
|
16
|
-
* @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or
|
|
17
|
-
* planar (flat) method. Valid options are 'geodesic' or 'planar'.
|
|
18
|
-
* @returns {number} distance between point and line
|
|
19
|
-
* @example
|
|
20
|
-
* var pt = turf.point([0, 0]);
|
|
21
|
-
* var line = turf.lineString([[1, 1],[-1, 1]]);
|
|
22
|
-
*
|
|
23
|
-
* var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
|
|
24
|
-
* //=69.11854715938406
|
|
25
|
-
*/
|
|
26
|
-
function pointToLineDistance(pt, line, options = {}) {
|
|
27
|
-
// Optional parameters
|
|
28
|
-
if (!options.method) {
|
|
29
|
-
options.method = "geodesic";
|
|
30
|
-
}
|
|
31
|
-
if (!options.units) {
|
|
32
|
-
options.units = "kilometers";
|
|
33
|
-
}
|
|
34
|
-
// validation
|
|
35
|
-
if (!pt) {
|
|
36
|
-
throw new Error("pt is required");
|
|
37
|
-
}
|
|
38
|
-
if (Array.isArray(pt)) {
|
|
39
|
-
pt = point(pt);
|
|
40
|
-
}
|
|
41
|
-
else if (pt.type === "Point") {
|
|
42
|
-
pt = feature(pt);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
featureOf(pt, "Point", "point");
|
|
46
|
-
}
|
|
47
|
-
if (!line) {
|
|
48
|
-
throw new Error("line is required");
|
|
49
|
-
}
|
|
50
|
-
if (Array.isArray(line)) {
|
|
51
|
-
line = lineString(line);
|
|
52
|
-
}
|
|
53
|
-
else if (line.type === "LineString") {
|
|
54
|
-
line = feature(line);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
featureOf(line, "LineString", "line");
|
|
58
|
-
}
|
|
59
|
-
let distance = Infinity;
|
|
60
|
-
const p = pt.geometry.coordinates;
|
|
61
|
-
segmentEach(line, (segment) => {
|
|
62
|
-
const a = segment.geometry.coordinates[0];
|
|
63
|
-
const b = segment.geometry.coordinates[1];
|
|
64
|
-
const d = distanceToSegment(p, a, b, options);
|
|
65
|
-
if (d < distance) {
|
|
66
|
-
distance = d;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return convertLength(distance, "degrees", options.units);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Returns the distance between a point P on a segment AB.
|
|
73
|
-
*
|
|
74
|
-
* @private
|
|
75
|
-
* @param {Array<number>} p external point
|
|
76
|
-
* @param {Array<number>} a first segment point
|
|
77
|
-
* @param {Array<number>} b second segment point
|
|
78
|
-
* @param {Object} [options={}] Optional parameters
|
|
79
|
-
* @returns {number} distance
|
|
80
|
-
*/
|
|
81
|
-
function distanceToSegment(p, a, b, options) {
|
|
82
|
-
const v = [b[0] - a[0], b[1] - a[1]];
|
|
83
|
-
const w = [p[0] - a[0], p[1] - a[1]];
|
|
84
|
-
const c1 = dot(w, v);
|
|
85
|
-
if (c1 <= 0) {
|
|
86
|
-
return calcDistance(p, a, { method: options.method, units: "degrees" });
|
|
87
|
-
}
|
|
88
|
-
const c2 = dot(v, v);
|
|
89
|
-
if (c2 <= c1) {
|
|
90
|
-
return calcDistance(p, b, { method: options.method, units: "degrees" });
|
|
91
|
-
}
|
|
92
|
-
const b2 = c1 / c2;
|
|
93
|
-
const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
|
|
94
|
-
return calcDistance(p, Pb, { method: options.method, units: "degrees" });
|
|
95
|
-
}
|
|
96
|
-
function dot(u, v) {
|
|
97
|
-
return u[0] * v[0] + u[1] * v[1];
|
|
98
|
-
}
|
|
99
|
-
function calcDistance(a, b, options) {
|
|
100
|
-
return options.method === "planar"
|
|
101
|
-
? getPlanarDistance(a, b, options)
|
|
102
|
-
: getDistance(a, b, options);
|
|
103
|
-
}
|
|
104
|
-
export default pointToLineDistance;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
|
|
5
|
-
const helpers_1 = require("@turf/helpers");
|
|
6
|
-
const invariant_1 = require("@turf/invariant");
|
|
7
|
-
const meta_1 = require("@turf/meta");
|
|
8
|
-
const rhumb_distance_1 = tslib_1.__importDefault(require("@turf/rhumb-distance"));
|
|
9
|
-
/**
|
|
10
|
-
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
|
|
11
|
-
* minimum distance between the point and any segment of the `LineString`.
|
|
12
|
-
*
|
|
13
|
-
* @name pointToLineDistance
|
|
14
|
-
* @param {Feature<Point>|Array<number>} pt Feature or Geometry
|
|
15
|
-
* @param {Feature<LineString>} line GeoJSON Feature or Geometry
|
|
16
|
-
* @param {Object} [options={}] Optional parameters
|
|
17
|
-
* @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength
|
|
18
|
-
* (ex: degrees, radians, miles, or kilometers)
|
|
19
|
-
* @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or
|
|
20
|
-
* planar (flat) method. Valid options are 'geodesic' or 'planar'.
|
|
21
|
-
* @returns {number} distance between point and line
|
|
22
|
-
* @example
|
|
23
|
-
* var pt = turf.point([0, 0]);
|
|
24
|
-
* var line = turf.lineString([[1, 1],[-1, 1]]);
|
|
25
|
-
*
|
|
26
|
-
* var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
|
|
27
|
-
* //=69.11854715938406
|
|
28
|
-
*/
|
|
29
|
-
function pointToLineDistance(pt, line, options = {}) {
|
|
30
|
-
// Optional parameters
|
|
31
|
-
if (!options.method) {
|
|
32
|
-
options.method = "geodesic";
|
|
33
|
-
}
|
|
34
|
-
if (!options.units) {
|
|
35
|
-
options.units = "kilometers";
|
|
36
|
-
}
|
|
37
|
-
// validation
|
|
38
|
-
if (!pt) {
|
|
39
|
-
throw new Error("pt is required");
|
|
40
|
-
}
|
|
41
|
-
if (Array.isArray(pt)) {
|
|
42
|
-
pt = helpers_1.point(pt);
|
|
43
|
-
}
|
|
44
|
-
else if (pt.type === "Point") {
|
|
45
|
-
pt = helpers_1.feature(pt);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
invariant_1.featureOf(pt, "Point", "point");
|
|
49
|
-
}
|
|
50
|
-
if (!line) {
|
|
51
|
-
throw new Error("line is required");
|
|
52
|
-
}
|
|
53
|
-
if (Array.isArray(line)) {
|
|
54
|
-
line = helpers_1.lineString(line);
|
|
55
|
-
}
|
|
56
|
-
else if (line.type === "LineString") {
|
|
57
|
-
line = helpers_1.feature(line);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
invariant_1.featureOf(line, "LineString", "line");
|
|
61
|
-
}
|
|
62
|
-
let distance = Infinity;
|
|
63
|
-
const p = pt.geometry.coordinates;
|
|
64
|
-
meta_1.segmentEach(line, (segment) => {
|
|
65
|
-
const a = segment.geometry.coordinates[0];
|
|
66
|
-
const b = segment.geometry.coordinates[1];
|
|
67
|
-
const d = distanceToSegment(p, a, b, options);
|
|
68
|
-
if (d < distance) {
|
|
69
|
-
distance = d;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return helpers_1.convertLength(distance, "degrees", options.units);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns the distance between a point P on a segment AB.
|
|
76
|
-
*
|
|
77
|
-
* @private
|
|
78
|
-
* @param {Array<number>} p external point
|
|
79
|
-
* @param {Array<number>} a first segment point
|
|
80
|
-
* @param {Array<number>} b second segment point
|
|
81
|
-
* @param {Object} [options={}] Optional parameters
|
|
82
|
-
* @returns {number} distance
|
|
83
|
-
*/
|
|
84
|
-
function distanceToSegment(p, a, b, options) {
|
|
85
|
-
const v = [b[0] - a[0], b[1] - a[1]];
|
|
86
|
-
const w = [p[0] - a[0], p[1] - a[1]];
|
|
87
|
-
const c1 = dot(w, v);
|
|
88
|
-
if (c1 <= 0) {
|
|
89
|
-
return calcDistance(p, a, { method: options.method, units: "degrees" });
|
|
90
|
-
}
|
|
91
|
-
const c2 = dot(v, v);
|
|
92
|
-
if (c2 <= c1) {
|
|
93
|
-
return calcDistance(p, b, { method: options.method, units: "degrees" });
|
|
94
|
-
}
|
|
95
|
-
const b2 = c1 / c2;
|
|
96
|
-
const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
|
|
97
|
-
return calcDistance(p, Pb, { method: options.method, units: "degrees" });
|
|
98
|
-
}
|
|
99
|
-
function dot(u, v) {
|
|
100
|
-
return u[0] * v[0] + u[1] * v[1];
|
|
101
|
-
}
|
|
102
|
-
function calcDistance(a, b, options) {
|
|
103
|
-
return options.method === "planar"
|
|
104
|
-
? rhumb_distance_1.default(a, b, options)
|
|
105
|
-
: distance_1.default(a, b, options);
|
|
106
|
-
}
|
|
107
|
-
exports.default = pointToLineDistance;
|