all these changes

This commit is contained in:
Jake Kasper
2026-04-09 13:19:47 -05:00
parent e83a51a051
commit 65315f36d1
39102 changed files with 7932979 additions and 567 deletions

View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2017 TurfJS
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,71 @@
# @turf/point-to-line-distance
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## pointToLineDistance
Returns the minimum distance between a [Point][1] and a [LineString][2], being the distance from a line the
minimum distance between the point and any segment of the `LineString`.
**Parameters**
- `pt` **([Feature][3]&lt;[Point][4]> | [Array][5]&lt;[number][6]>)** Feature or Geometry
- `line` **[Feature][3]&lt;[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'`)
**Examples**
```javascript
var pt = turf.point([0, 0]);
var line = turf.lineString([[1, 1],[-1, 1]]);
var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
//=69.11854715938406
```
Returns **[number][6]** distance between point and line
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[3]: https://tools.ietf.org/html/rfc7946#section-3.2
[4]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->
---
This module is part of the [Turfjs project](http://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.
### Installation
Install this module individually:
```sh
$ npm install @turf/point-to-line-distance
```
Or install the Turf module that includes it as a function:
```sh
$ npm install @turf/turf
```

View File

@@ -0,0 +1,106 @@
// Taken from http://geomalgorithms.com/a02-_lines.html
import getDistance from "@turf/distance";
import { convertLength, feature, lineString, point, } from "@turf/helpers";
import { featureOf } from "@turf/invariant";
import { segmentEach } from "@turf/meta";
import getPlanarDistance from "@turf/rhumb-distance";
/**
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
* minimum distance between the point and any segment of the `LineString`.
*
* @name pointToLineDistance
* @param {Feature<Point>|Array<number>} pt Feature or Geometry
* @param {Feature<LineString>} line GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength
* (ex: degrees, radians, miles, or kilometers)
* @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or
* planar (flat) method. Valid options are 'geodesic' or 'planar'.
* @returns {number} distance between point and line
* @example
* var pt = turf.point([0, 0]);
* var line = turf.lineString([[1, 1],[-1, 1]]);
*
* var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
* //=69.11854715938406
*/
function pointToLineDistance(pt, line, options) {
if (options === void 0) { options = {}; }
// Optional parameters
if (!options.method) {
options.method = "geodesic";
}
if (!options.units) {
options.units = "kilometers";
}
// validation
if (!pt) {
throw new Error("pt is required");
}
if (Array.isArray(pt)) {
pt = point(pt);
}
else if (pt.type === "Point") {
pt = feature(pt);
}
else {
featureOf(pt, "Point", "point");
}
if (!line) {
throw new Error("line is required");
}
if (Array.isArray(line)) {
line = lineString(line);
}
else if (line.type === "LineString") {
line = feature(line);
}
else {
featureOf(line, "LineString", "line");
}
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);
if (d < distance) {
distance = d;
}
});
return convertLength(distance, "degrees", options.units);
}
/**
* Returns the distance between a point P on a segment AB.
*
* @private
* @param {Array<number>} p external point
* @param {Array<number>} a first segment point
* @param {Array<number>} b second segment point
* @param {Object} [options={}] Optional parameters
* @returns {number} distance
*/
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);
if (c1 <= 0) {
return calcDistance(p, a, { method: options.method, units: "degrees" });
}
var 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]];
return calcDistance(p, Pb, { method: options.method, units: "degrees" });
}
function dot(u, v) {
return u[0] * v[0] + u[1] * v[1];
}
function calcDistance(a, b, options) {
return options.method === "planar"
? getPlanarDistance(a, b, options)
: getDistance(a, b, options);
}
export default pointToLineDistance;

View File

@@ -0,0 +1 @@
{"type":"module"}

View File

@@ -0,0 +1,26 @@
import { Coord, Feature, LineString, Units } from "@turf/helpers";
/**
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
* minimum distance between the point and any segment of the `LineString`.
*
* @name pointToLineDistance
* @param {Feature<Point>|Array<number>} pt Feature or Geometry
* @param {Feature<LineString>} line GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength
* (ex: degrees, radians, miles, or kilometers)
* @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or
* planar (flat) method. Valid options are 'geodesic' or 'planar'.
* @returns {number} distance between point and line
* @example
* var pt = turf.point([0, 0]);
* var line = turf.lineString([[1, 1],[-1, 1]]);
*
* var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
* //=69.11854715938406
*/
declare function pointToLineDistance(pt: Coord, line: Feature<LineString> | LineString, options?: {
units?: Units;
method?: "geodesic" | "planar";
}): number;
export default pointToLineDistance;

View File

@@ -0,0 +1,111 @@
"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"));
/**
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
* minimum distance between the point and any segment of the `LineString`.
*
* @name pointToLineDistance
* @param {Feature<Point>|Array<number>} pt Feature or Geometry
* @param {Feature<LineString>} line GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength
* (ex: degrees, radians, miles, or kilometers)
* @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or
* planar (flat) method. Valid options are 'geodesic' or 'planar'.
* @returns {number} distance between point and line
* @example
* var pt = turf.point([0, 0]);
* var line = turf.lineString([[1, 1],[-1, 1]]);
*
* var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
* //=69.11854715938406
*/
function pointToLineDistance(pt, line, options) {
if (options === void 0) { options = {}; }
// Optional parameters
if (!options.method) {
options.method = "geodesic";
}
if (!options.units) {
options.units = "kilometers";
}
// validation
if (!pt) {
throw new Error("pt is required");
}
if (Array.isArray(pt)) {
pt = helpers_1.point(pt);
}
else if (pt.type === "Point") {
pt = helpers_1.feature(pt);
}
else {
invariant_1.featureOf(pt, "Point", "point");
}
if (!line) {
throw new Error("line is required");
}
if (Array.isArray(line)) {
line = helpers_1.lineString(line);
}
else if (line.type === "LineString") {
line = helpers_1.feature(line);
}
else {
invariant_1.featureOf(line, "LineString", "line");
}
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);
if (d < distance) {
distance = d;
}
});
return helpers_1.convertLength(distance, "degrees", options.units);
}
/**
* Returns the distance between a point P on a segment AB.
*
* @private
* @param {Array<number>} p external point
* @param {Array<number>} a first segment point
* @param {Array<number>} b second segment point
* @param {Object} [options={}] Optional parameters
* @returns {number} distance
*/
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);
if (c1 <= 0) {
return calcDistance(p, a, { method: options.method, units: "degrees" });
}
var 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]];
return calcDistance(p, Pb, { method: options.method, units: "degrees" });
}
function dot(u, v) {
return u[0] * v[0] + u[1] * v[1];
}
function calcDistance(a, b, options) {
return options.method === "planar"
? rhumb_distance_1.default(a, b, options)
: distance_1.default(a, b, options);
}
exports.default = pointToLineDistance;

View File

@@ -0,0 +1,74 @@
{
"name": "@turf/point-to-line-distance",
"version": "6.5.0",
"description": "turf point-to-line-distance module",
"author": "Turf Authors",
"contributors": [
"Stefano Borghi <@stebogit>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/Turfjs/turf/issues"
},
"homepage": "https://github.com/Turfjs/turf",
"repository": {
"type": "git",
"url": "git://github.com/Turfjs/turf.git"
},
"funding": "https://opencollective.com/turf",
"publishConfig": {
"access": "public"
},
"keywords": [
"turf",
"point-to-line-distance",
"distance"
],
"main": "dist/js/index.js",
"module": "dist/es/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
}
},
"types": "dist/js/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"bench": "ts-node bench.js",
"build": "npm-run-all build:*",
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
"build:js": "tsc",
"docs": "node ../../scripts/generate-readmes",
"test": "npm-run-all test:*",
"test:tape": "ts-node -r esm test.js",
"test:types": "tsc --esModuleInterop --noEmit types.ts"
},
"devDependencies": {
"@turf/circle": "^6.5.0",
"@types/tape": "*",
"benchmark": "*",
"load-json-file": "*",
"npm-run-all": "*",
"tape": "*",
"ts-node": "*",
"tslint": "*",
"typescript": "*",
"write-json-file": "*"
},
"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"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
}