@turf/point-to-line-distance
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -1,2 +0,1 @@ | ||
// Taken from http://geomalgorithms.com/a02-_lines.html | ||
import getDistance from "@turf/distance"; | ||
@@ -27,4 +26,3 @@ import { convertLength, feature, lineString, point, } from "@turf/helpers"; | ||
*/ | ||
function pointToLineDistance(pt, line, options) { | ||
if (options === void 0) { options = {}; } | ||
function pointToLineDistance(pt, line, options = {}) { | ||
// Optional parameters | ||
@@ -62,8 +60,8 @@ if (!options.method) { | ||
} | ||
var distance = Infinity; | ||
var p = pt.geometry.coordinates; | ||
segmentEach(line, function (segment) { | ||
var a = segment.geometry.coordinates[0]; | ||
var b = segment.geometry.coordinates[1]; | ||
var d = distanceToSegment(p, a, b, options); | ||
let distance = Infinity; | ||
const p = pt.geometry.coordinates; | ||
segmentEach(line, (segment) => { | ||
const a = segment.geometry.coordinates[0]; | ||
const b = segment.geometry.coordinates[1]; | ||
const d = distanceToSegment(p, a, b, options); | ||
if (d < distance) { | ||
@@ -86,14 +84,14 @@ distance = d; | ||
function distanceToSegment(p, a, b, options) { | ||
var v = [b[0] - a[0], b[1] - a[1]]; | ||
var w = [p[0] - a[0], p[1] - a[1]]; | ||
var c1 = dot(w, v); | ||
const v = [b[0] - a[0], b[1] - a[1]]; | ||
const w = [p[0] - a[0], p[1] - a[1]]; | ||
const c1 = dot(w, v); | ||
if (c1 <= 0) { | ||
return calcDistance(p, a, { method: options.method, units: "degrees" }); | ||
} | ||
var c2 = dot(v, v); | ||
const c2 = dot(v, v); | ||
if (c2 <= c1) { | ||
return calcDistance(p, b, { method: options.method, units: "degrees" }); | ||
} | ||
var b2 = c1 / c2; | ||
var Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]]; | ||
const b2 = c1 / c2; | ||
const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]]; | ||
return calcDistance(p, Pb, { method: options.method, units: "degrees" }); | ||
@@ -100,0 +98,0 @@ } |
@@ -1,2 +0,3 @@ | ||
import { Coord, Feature, LineString, Units } from "@turf/helpers"; | ||
import { Feature, LineString } from "geojson"; | ||
import { Coord, Units } from "@turf/helpers"; | ||
/** | ||
@@ -3,0 +4,0 @@ * Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Taken from http://geomalgorithms.com/a02-_lines.html | ||
var distance_1 = __importDefault(require("@turf/distance")); | ||
var helpers_1 = require("@turf/helpers"); | ||
var invariant_1 = require("@turf/invariant"); | ||
var meta_1 = require("@turf/meta"); | ||
var rhumb_distance_1 = __importDefault(require("@turf/rhumb-distance")); | ||
const tslib_1 = require("tslib"); | ||
const distance_1 = tslib_1.__importDefault(require("@turf/distance")); | ||
const helpers_1 = require("@turf/helpers"); | ||
const invariant_1 = require("@turf/invariant"); | ||
const meta_1 = require("@turf/meta"); | ||
const rhumb_distance_1 = tslib_1.__importDefault(require("@turf/rhumb-distance")); | ||
/** | ||
@@ -32,4 +29,3 @@ * Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the | ||
*/ | ||
function pointToLineDistance(pt, line, options) { | ||
if (options === void 0) { options = {}; } | ||
function pointToLineDistance(pt, line, options = {}) { | ||
// Optional parameters | ||
@@ -67,8 +63,8 @@ if (!options.method) { | ||
} | ||
var distance = Infinity; | ||
var p = pt.geometry.coordinates; | ||
meta_1.segmentEach(line, function (segment) { | ||
var a = segment.geometry.coordinates[0]; | ||
var b = segment.geometry.coordinates[1]; | ||
var d = distanceToSegment(p, a, b, options); | ||
let distance = Infinity; | ||
const p = pt.geometry.coordinates; | ||
meta_1.segmentEach(line, (segment) => { | ||
const a = segment.geometry.coordinates[0]; | ||
const b = segment.geometry.coordinates[1]; | ||
const d = distanceToSegment(p, a, b, options); | ||
if (d < distance) { | ||
@@ -91,14 +87,14 @@ distance = d; | ||
function distanceToSegment(p, a, b, options) { | ||
var v = [b[0] - a[0], b[1] - a[1]]; | ||
var w = [p[0] - a[0], p[1] - a[1]]; | ||
var c1 = dot(w, v); | ||
const v = [b[0] - a[0], b[1] - a[1]]; | ||
const w = [p[0] - a[0], p[1] - a[1]]; | ||
const c1 = dot(w, v); | ||
if (c1 <= 0) { | ||
return calcDistance(p, a, { method: options.method, units: "degrees" }); | ||
} | ||
var c2 = dot(v, v); | ||
const c2 = dot(v, v); | ||
if (c2 <= c1) { | ||
return calcDistance(p, b, { method: options.method, units: "degrees" }); | ||
} | ||
var b2 = c1 / c2; | ||
var Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]]; | ||
const b2 = c1 / c2; | ||
const Pb = [a[0] + b2 * v[0], a[1] + b2 * v[1]]; | ||
return calcDistance(p, Pb, { method: options.method, units: "degrees" }); | ||
@@ -105,0 +101,0 @@ } |
{ | ||
"name": "@turf/point-to-line-distance", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf point-to-line-distance module", | ||
@@ -49,6 +49,6 @@ "author": "Turf Authors", | ||
"test:tape": "ts-node -r esm test.js", | ||
"test:types": "tsc --esModuleInterop --noEmit types.ts" | ||
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts" | ||
}, | ||
"devDependencies": { | ||
"@turf/circle": "^6.5.0", | ||
"@turf/circle": "^7.0.0-alpha.0", | ||
"@types/tape": "*", | ||
@@ -65,12 +65,13 @@ "benchmark": "*", | ||
"dependencies": { | ||
"@turf/bearing": "^6.5.0", | ||
"@turf/distance": "^6.5.0", | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/invariant": "^6.5.0", | ||
"@turf/meta": "^6.5.0", | ||
"@turf/projection": "^6.5.0", | ||
"@turf/rhumb-bearing": "^6.5.0", | ||
"@turf/rhumb-distance": "^6.5.0" | ||
"@turf/bearing": "^7.0.0-alpha.0", | ||
"@turf/distance": "^7.0.0-alpha.0", | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/invariant": "^7.0.0-alpha.0", | ||
"@turf/meta": "^7.0.0-alpha.0", | ||
"@turf/projection": "^7.0.0-alpha.0", | ||
"@turf/rhumb-bearing": "^7.0.0-alpha.0", | ||
"@turf/rhumb-distance": "^7.0.0-alpha.0", | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -10,12 +10,15 @@ # @turf/point-to-line-distance | ||
**Parameters** | ||
### Parameters | ||
- `pt` **([Feature][3]<[Point][4]> | [Array][5]<[number][6]>)** Feature or Geometry | ||
- `line` **[Feature][3]<[LineString][7]>** GeoJSON Feature or Geometry | ||
- `options` **[Object][8]** Optional parameters (optional, default `{}`) | ||
- `options.units` **[string][9]** can be anything supported by turf/convertLength, eg degrees, radians, miles, or kilometers (optional, default `'kilometers'`) | ||
- `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'`) | ||
* `pt` **([Feature][3]<[Point][4]> | [Array][5]<[number][6]>)** Feature or Geometry | ||
* `line` **[Feature][3]<[LineString][7]>** GeoJSON Feature or Geometry | ||
* `options` **[Object][8]** Optional parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.units` **[string][9]** can be anything supported by turf/convertLength | ||
(ex: degrees, radians, miles, or kilometers) (optional, default `"kilometers"`) | ||
* `options.method` **[string][9]** wether to calculate the distance based on geodesic (spheroid) or | ||
planar (flat) method. Valid options are 'geodesic' or 'planar'. (optional, default `"geodesic"`) | ||
### Examples | ||
```javascript | ||
@@ -22,0 +25,0 @@ var pt = turf.point([0, 0]); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75
14223
9
238
1
+ Addedtslib@^2.3.0
+ Added@turf/bearing@7.1.0(transitive)
+ Added@turf/clone@7.1.0(transitive)
+ Added@turf/distance@7.1.0(transitive)
+ Added@turf/helpers@7.1.0(transitive)
+ Added@turf/invariant@7.1.0(transitive)
+ Added@turf/meta@7.1.0(transitive)
+ Added@turf/projection@7.1.0(transitive)
+ Added@turf/rhumb-bearing@7.1.0(transitive)
+ Added@turf/rhumb-distance@7.1.0(transitive)
+ Added@types/geojson@7946.0.15(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/bearing@6.5.0(transitive)
- Removed@turf/clone@6.5.0(transitive)
- Removed@turf/distance@6.5.0(transitive)
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/invariant@6.5.0(transitive)
- Removed@turf/meta@6.5.0(transitive)
- Removed@turf/projection@6.5.0(transitive)
- Removed@turf/rhumb-bearing@6.5.0(transitive)
- Removed@turf/rhumb-distance@6.5.0(transitive)
Updated@turf/bearing@^7.0.0-alpha.0
Updated@turf/helpers@^7.0.0-alpha.0
Updated@turf/meta@^7.0.0-alpha.0