@turf/point-to-line-distance 6.5.0 → 7.0.0-alpha.1

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
@@ -7,15 +7,18 @@
7
7
  Returns the minimum distance between a [Point][1] and a [LineString][2], being the distance from a line the
8
8
  minimum distance between the point and any segment of the `LineString`.
9
9
 
10
- **Parameters**
10
+ ### Parameters
11
11
 
12
- - `pt` **([Feature][3]<[Point][4]> | [Array][5]<[number][6]>)** Feature or Geometry
13
- - `line` **[Feature][3]<[LineString][7]>** GeoJSON Feature or Geometry
14
- - `options` **[Object][8]** Optional parameters (optional, default `{}`)
15
- - `options.units` **[string][9]** can be anything supported by turf/convertLength, eg degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
16
- - `options.method` **[string][9]** wehther to calculate the distance based on geodesic (spheroid) or planar (flat) method. Valid options are 'geodesic' or 'planar'. (optional, default `'geodesic'`)
12
+ * `pt` **([Feature][3]<[Point][4]> | [Array][5]<[number][6]>)** Feature or Geometry
13
+ * `line` **[Feature][3]<[LineString][7]>** GeoJSON Feature or Geometry
14
+ * `options` **[Object][8]** Optional parameters (optional, default `{}`)
17
15
 
18
- **Examples**
16
+ * `options.units` **[string][9]** can be anything supported by turf/convertLength
17
+ (ex: degrees, radians, miles, or kilometers) (optional, default `"kilometers"`)
18
+ * `options.method` **[string][9]** wether to calculate the distance based on geodesic (spheroid) or
19
+ planar (flat) method. Valid options are 'geodesic' or 'planar'. (optional, default `"geodesic"`)
20
+
21
+ ### Examples
19
22
 
20
23
  ```javascript
21
24
  var pt = turf.point([0, 0]);
package/dist/es/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // Taken from http://geomalgorithms.com/a02-_lines.html
2
1
  import getDistance from "@turf/distance";
3
2
  import { convertLength, feature, lineString, point, } from "@turf/helpers";
4
3
  import { featureOf } from "@turf/invariant";
@@ -24,8 +23,7 @@ import getPlanarDistance from "@turf/rhumb-distance";
24
23
  * var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
25
24
  * //=69.11854715938406
26
25
  */
27
- function pointToLineDistance(pt, line, options) {
28
- if (options === void 0) { options = {}; }
26
+ function pointToLineDistance(pt, line, options = {}) {
29
27
  // Optional parameters
30
28
  if (!options.method) {
31
29
  options.method = "geodesic";
@@ -58,12 +56,12 @@ function pointToLineDistance(pt, line, options) {
58
56
  else {
59
57
  featureOf(line, "LineString", "line");
60
58
  }
61
- var distance = Infinity;
62
- var p = pt.geometry.coordinates;
63
- segmentEach(line, function (segment) {
64
- var a = segment.geometry.coordinates[0];
65
- var b = segment.geometry.coordinates[1];
66
- var d = distanceToSegment(p, a, b, options);
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);
67
65
  if (d < distance) {
68
66
  distance = d;
69
67
  }
@@ -81,18 +79,18 @@ function pointToLineDistance(pt, line, options) {
81
79
  * @returns {number} distance
82
80
  */
83
81
  function distanceToSegment(p, a, b, options) {
84
- var v = [b[0] - a[0], b[1] - a[1]];
85
- var w = [p[0] - a[0], p[1] - a[1]];
86
- var c1 = dot(w, v);
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);
87
85
  if (c1 <= 0) {
88
86
  return calcDistance(p, a, { method: options.method, units: "degrees" });
89
87
  }
90
- var c2 = dot(v, v);
88
+ const c2 = dot(v, v);
91
89
  if (c2 <= c1) {
92
90
  return calcDistance(p, b, { method: options.method, units: "degrees" });
93
91
  }
94
- var b2 = c1 / c2;
95
- var Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
92
+ const b2 = c1 / c2;
93
+ const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
96
94
  return calcDistance(p, Pb, { method: options.method, units: "degrees" });
97
95
  }
98
96
  function dot(u, v) {
@@ -1,4 +1,5 @@
1
- import { Coord, Feature, LineString, Units } from "@turf/helpers";
1
+ import { Feature, LineString } from "geojson";
2
+ import { Coord, Units } from "@turf/helpers";
2
3
  /**
3
4
  * Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
4
5
  * minimum distance between the point and any segment of the `LineString`.
package/dist/js/index.js CHANGED
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- // Taken from http://geomalgorithms.com/a02-_lines.html
7
- var distance_1 = __importDefault(require("@turf/distance"));
8
- var helpers_1 = require("@turf/helpers");
9
- var invariant_1 = require("@turf/invariant");
10
- var meta_1 = require("@turf/meta");
11
- var rhumb_distance_1 = __importDefault(require("@turf/rhumb-distance"));
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"));
12
9
  /**
13
10
  * Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
14
11
  * minimum distance between the point and any segment of the `LineString`.
@@ -29,8 +26,7 @@ var rhumb_distance_1 = __importDefault(require("@turf/rhumb-distance"));
29
26
  * var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
30
27
  * //=69.11854715938406
31
28
  */
32
- function pointToLineDistance(pt, line, options) {
33
- if (options === void 0) { options = {}; }
29
+ function pointToLineDistance(pt, line, options = {}) {
34
30
  // Optional parameters
35
31
  if (!options.method) {
36
32
  options.method = "geodesic";
@@ -63,12 +59,12 @@ function pointToLineDistance(pt, line, options) {
63
59
  else {
64
60
  invariant_1.featureOf(line, "LineString", "line");
65
61
  }
66
- var distance = Infinity;
67
- var p = pt.geometry.coordinates;
68
- meta_1.segmentEach(line, function (segment) {
69
- var a = segment.geometry.coordinates[0];
70
- var b = segment.geometry.coordinates[1];
71
- var d = distanceToSegment(p, a, b, options);
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);
72
68
  if (d < distance) {
73
69
  distance = d;
74
70
  }
@@ -86,18 +82,18 @@ function pointToLineDistance(pt, line, options) {
86
82
  * @returns {number} distance
87
83
  */
88
84
  function distanceToSegment(p, a, b, options) {
89
- var v = [b[0] - a[0], b[1] - a[1]];
90
- var w = [p[0] - a[0], p[1] - a[1]];
91
- var c1 = dot(w, v);
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);
92
88
  if (c1 <= 0) {
93
89
  return calcDistance(p, a, { method: options.method, units: "degrees" });
94
90
  }
95
- var c2 = dot(v, v);
91
+ const c2 = dot(v, v);
96
92
  if (c2 <= c1) {
97
93
  return calcDistance(p, b, { method: options.method, units: "degrees" });
98
94
  }
99
- var b2 = c1 / c2;
100
- var Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
95
+ const b2 = c1 / c2;
96
+ const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]];
101
97
  return calcDistance(p, Pb, { method: options.method, units: "degrees" });
102
98
  }
103
99
  function dot(u, v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/point-to-line-distance",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.1",
4
4
  "description": "turf point-to-line-distance module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -29,6 +29,7 @@
29
29
  "exports": {
30
30
  "./package.json": "./package.json",
31
31
  ".": {
32
+ "types": "./dist/js/index.d.ts",
32
33
  "import": "./dist/es/index.js",
33
34
  "require": "./dist/js/index.js"
34
35
  }
@@ -39,36 +40,37 @@
39
40
  "dist"
40
41
  ],
41
42
  "scripts": {
42
- "bench": "ts-node bench.js",
43
+ "bench": "tsx bench.js",
43
44
  "build": "npm-run-all build:*",
44
45
  "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
45
46
  "build:js": "tsc",
46
- "docs": "node ../../scripts/generate-readmes",
47
+ "docs": "tsx ../../scripts/generate-readmes",
47
48
  "test": "npm-run-all test:*",
48
- "test:tape": "ts-node -r esm test.js",
49
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
49
+ "test:tape": "tsx test.js",
50
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
50
51
  },
51
52
  "devDependencies": {
52
- "@turf/circle": "^6.5.0",
53
+ "@turf/circle": "^7.0.0-alpha.1",
53
54
  "@types/tape": "*",
54
55
  "benchmark": "*",
55
56
  "load-json-file": "*",
56
57
  "npm-run-all": "*",
57
58
  "tape": "*",
58
- "ts-node": "*",
59
59
  "tslint": "*",
60
+ "tsx": "*",
60
61
  "typescript": "*",
61
62
  "write-json-file": "*"
62
63
  },
63
64
  "dependencies": {
64
- "@turf/bearing": "^6.5.0",
65
- "@turf/distance": "^6.5.0",
66
- "@turf/helpers": "^6.5.0",
67
- "@turf/invariant": "^6.5.0",
68
- "@turf/meta": "^6.5.0",
69
- "@turf/projection": "^6.5.0",
70
- "@turf/rhumb-bearing": "^6.5.0",
71
- "@turf/rhumb-distance": "^6.5.0"
65
+ "@turf/bearing": "^7.0.0-alpha.1",
66
+ "@turf/distance": "^7.0.0-alpha.1",
67
+ "@turf/helpers": "^7.0.0-alpha.1",
68
+ "@turf/invariant": "^7.0.0-alpha.1",
69
+ "@turf/meta": "^7.0.0-alpha.1",
70
+ "@turf/projection": "^7.0.0-alpha.1",
71
+ "@turf/rhumb-bearing": "^7.0.0-alpha.1",
72
+ "@turf/rhumb-distance": "^7.0.0-alpha.1",
73
+ "tslib": "^2.3.0"
72
74
  },
73
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
75
+ "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
74
76
  }