Skip to content

Commit 4994d88

Browse files
committed
nearest-point-on-line Rename some internal variables
1 parent cd34656 commit 4994d88

File tree

1 file changed

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

1 file changed

+18
-18
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
7171
pointDistance: Infinity,
7272
});
7373

74-
let length = 0.0;
75-
let multiFeatureLength = 0.0;
76-
let currentMultiFeatureIndex = -1;
74+
let totalDistance = 0.0;
75+
let lineDistance = 0.0;
76+
let currentLineStringIndex = -1;
7777
flattenEach(
7878
lines,
79-
function (line: any, _featureIndex: number, multiFeatureIndex: number) {
80-
//reset multiFeatureLength at each changed multiFeatureIndex
81-
if (currentMultiFeatureIndex !== multiFeatureIndex) {
82-
currentMultiFeatureIndex = multiFeatureIndex;
83-
multiFeatureLength = 0.0;
79+
function (line: any, _featureIndex: number, lineStringIndex: number) {
80+
//reset lineDistance at each changed lineStringIndex
81+
if (currentLineStringIndex !== lineStringIndex) {
82+
currentLineStringIndex = lineStringIndex;
83+
lineDistance = 0.0;
8484
}
8585

8686
const coords: any = getCoords(line);
@@ -94,8 +94,8 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
9494
const stop: Feature<Point, { dist: number }> = point(coords[i + 1]);
9595
const stopPos = getCoord(stop);
9696

97-
// sectionLength
98-
const sectionLength = distance(start, stop, options);
97+
// segmentLength
98+
const segmentLength = distance(start, stop, options);
9999
let intersectPos: Position;
100100
let wasEnd: boolean;
101101

@@ -118,22 +118,22 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
118118
const pointDistance = distance(inputPoint, intersectPos, options);
119119

120120
if (pointDistance < closestPt.properties.pointDistance) {
121-
const lineLocationDist = distance(start, intersectPos, options);
121+
const segmentDistance = distance(start, intersectPos, options);
122122
closestPt = point(intersectPos, {
123-
lineStringIndex: multiFeatureIndex,
123+
lineStringIndex: lineStringIndex,
124124
// Legacy behaviour where index progresses to next segment
125125
// if we went with the end point this iteration.
126126
segmentIndex: wasEnd ? i + 1 : i,
127-
totalDistance: length + lineLocationDist,
128-
lineDistance: multiFeatureLength + lineLocationDist,
129-
segmentDistance: lineLocationDist,
127+
totalDistance: totalDistance + segmentDistance,
128+
lineDistance: lineDistance + segmentDistance,
129+
segmentDistance: segmentDistance,
130130
pointDistance: pointDistance,
131131
});
132132
}
133133

134-
// update length and multiFeatureLength
135-
length += sectionLength;
136-
multiFeatureLength += sectionLength;
134+
// update totalDistance and lineDistance
135+
totalDistance += segmentLength;
136+
lineDistance += segmentLength;
137137
}
138138
}
139139
);

0 commit comments

Comments
 (0)