Skip to content

Commit 2cf5f71

Browse files
committed
nearest-point-on-line Rename param pt to inputPoint
1 parent 5d16fe8 commit 2cf5f71

File tree

1 file changed

+13
-13
lines changed
  • packages/turf-nearest-point-on-line

1 file changed

+13
-13
lines changed

packages/turf-nearest-point-on-line/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { getCoord, getCoords } from "@turf/invariant";
1818
* on the line.
1919
*
2020
* @function
21-
* @param {Geometry|Feature<LineString|MultiLineString>} lines lines to snap to
22-
* @param {Geometry|Feature<Point>|number[]} pt point to snap from
21+
* @param {Geometry|Feature<LineString|MultiLineString>} lines Lines to snap to
22+
* @param {Geometry|Feature<Point>|number[]} inputPoint Point to snap from
2323
* @param {Object} [options={}] Optional parameters
2424
* @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
2525
* @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point, `multiFeatureLocation`: distance along the line between start of the `MultiLineString` where closest point was found and the closest point.
@@ -32,17 +32,17 @@ import { getCoord, getCoords } from "@turf/invariant";
3232
* [-77.021884, 38.889563],
3333
* [-77.019824, 38.892368]
3434
* ]);
35-
* var pt = turf.point([-77.037076, 38.884017]);
35+
* var inputPoint = turf.point([-77.037076, 38.884017]);
3636
*
37-
* var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});
37+
* var snapped = turf.nearestPointOnLine(line, inputPoint, {units: 'miles'});
3838
*
3939
* //addToMap
40-
* var addToMap = [line, pt, snapped];
40+
* var addToMap = [line, inputPoint, snapped];
4141
* snapped.properties['marker-color'] = '#00f';
4242
*/
4343
function nearestPointOnLine<G extends LineString | MultiLineString>(
4444
lines: Feature<G> | G,
45-
pt: Coord,
45+
inputPoint: Coord,
4646
options: { units?: Units } = {}
4747
): Feature<
4848
Point,
@@ -55,11 +55,11 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
5555
[key: string]: any;
5656
}
5757
> {
58-
if (!lines || !pt) {
59-
throw new Error("lines and pt are required arguments");
58+
if (!lines || !inputPoint) {
59+
throw new Error("lines and inputPoint are required arguments");
6060
}
6161

62-
const ptPos = getCoord(pt);
62+
const inputPos = getCoord(inputPoint);
6363

6464
let closestPt: Feature<
6565
Point,
@@ -109,22 +109,22 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
109109
// Short circuit if snap point is start or end position of the line
110110
// Test the end position first for consistency in case they are
111111
// coincident
112-
if (stopPos[0] === ptPos[0] && stopPos[1] === ptPos[1]) {
112+
if (stopPos[0] === inputPos[0] && stopPos[1] === inputPos[1]) {
113113
[intersectPos, wasEnd] = [stopPos, true];
114-
} else if (startPos[0] === ptPos[0] && startPos[1] === ptPos[1]) {
114+
} else if (startPos[0] === inputPos[0] && startPos[1] === inputPos[1]) {
115115
[intersectPos, wasEnd] = [startPos, false];
116116
} else {
117117
// Otherwise, find the nearest point the hard way.
118118
[intersectPos, wasEnd] = nearestPointOnSegment(
119119
startPos,
120120
stopPos,
121-
ptPos
121+
inputPos
122122
);
123123
}
124124

125125
const lineLocationDist = distance(start, intersectPos, options);
126126
const intersectPt = point(intersectPos, {
127-
dist: distance(pt, intersectPos, options),
127+
dist: distance(inputPoint, intersectPos, options),
128128
multiFeatureIndex: multiFeatureIndex,
129129
location: length + lineLocationDist,
130130
multiFeatureLocation: multiFeatureLength + lineLocationDist,

0 commit comments

Comments
 (0)