Skip to content

Commit 3e7c7a8

Browse files
Merge branch 'master' into proz/fix-destination-coord
2 parents 41d17d0 + 326a96a commit 3e7c7a8

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

.github/workflows/prerelease.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ jobs:
1717
runs-on: ${{matrix.platform}}
1818

1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
2121
with:
2222
fetch-depth: 0
2323

2424
- name: Install pnpm
25-
uses: pnpm/action-setup@v4
25+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # 4.1.0
2626
with:
2727
run_install: false
2828

2929
- name: Use Node.js ${{ matrix.node-version }}
30-
uses: actions/setup-node@v4
30+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # 4.3.0
3131
with:
3232
node-version: ${{ matrix.node-version }}
3333
registry-url: "https://registry.npmjs.org"

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ jobs:
2121
runs-on: ${{matrix.platform}}
2222

2323
steps:
24-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
2525
with:
2626
fetch-depth: 0
2727

2828
- name: Install pnpm
29-
uses: pnpm/action-setup@v4
29+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # 4.1.0
3030
with:
3131
run_install: false
3232

3333
- name: Use Node.js ${{ matrix.node-version }}
34-
uses: actions/setup-node@v4
34+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # 4.3.0
3535
with:
3636
node-version: ${{ matrix.node-version }}
3737
registry-url: "https://registry.npmjs.org"
@@ -51,7 +51,7 @@ jobs:
5151
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5252

5353
- name: Create Github Release
54-
uses: softprops/action-gh-release@v2
54+
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # 2.2.1
5555
with:
5656
make_latest: true
5757
generate_release_notes: true

.github/workflows/turf.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ jobs:
2323

2424
steps:
2525
- name: Checkout
26-
uses: actions/checkout@v4
26+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
2727

2828
- name: Install pnpm
29-
uses: pnpm/action-setup@v4
29+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # 4.1.0
3030
with:
3131
run_install: false
3232

3333
- name: Use Node.js ${{ matrix.node-version }}
34-
uses: actions/setup-node@v4
34+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # 4.3.0
3535
with:
3636
cache: "pnpm"
3737
node-version: ${{ matrix.node-version }}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
8989
let wasEnd: boolean;
9090

9191
// Short circuit if snap point is start or end position of the line
92-
// segment.
92+
// segment or if start is equal to stop position.
9393
if (startPos[0] === ptPos[0] && startPos[1] === ptPos[1]) {
9494
[intersectPos, , wasEnd] = [startPos, undefined, false];
9595
} else if (stopPos[0] === ptPos[0] && stopPos[1] === ptPos[1]) {
9696
[intersectPos, , wasEnd] = [stopPos, undefined, true];
97+
} else if (startPos[0] === stopPos[0] && startPos[1] === stopPos[1]) {
98+
[intersectPos, , wasEnd] = [stopPos, undefined, true];
9799
} else {
98100
// Otherwise, find the nearest point the hard way.
99101
[intersectPos, , wasEnd] = nearestPointOnSegment(

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,21 @@ test("turf-nearest-point-on-line -- issue 965", (t) => {
499499
);
500500
t.end();
501501
});
502+
503+
test("turf-nearest-point-on-line -- issue 2808 redundant point support", (t) => {
504+
// include redundant points in line
505+
const line1 = lineString([
506+
[10.57846, 49.8463959],
507+
[10.57846, 49.8468386],
508+
[10.57846, 49.8468386],
509+
[10.57846, 49.8468386],
510+
[10.57846, 49.8472814],
511+
[10.57846, 49.8472814],
512+
]);
513+
const thePoint = point([10.57846, 49.8468386]);
514+
515+
const nearest = nearestPointOnLine(line1, thePoint); // should not throw
516+
t.equal(nearest.properties.dist, 0, "redundant point should not throw");
517+
518+
t.end();
519+
});

packages/turf-nearest-point/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Feature, FeatureCollection, Point } from "geojson";
1+
import { Feature, FeatureCollection, GeoJsonProperties, Point } from "geojson";
22
import { Coord, Units } from "@turf/helpers";
33
import { clone } from "@turf/clone";
44
import { distance } from "@turf/distance";
55
import { featureEach } from "@turf/meta";
66

7-
interface NearestPoint extends Feature<Point> {
7+
interface NearestPoint<P extends GeoJsonProperties = GeoJsonProperties>
8+
extends Feature<Point> {
89
properties: {
910
featureIndex: number;
1011
distanceToPoint: number;
11-
[key: string]: any;
12-
};
12+
} & P;
1313
}
1414

1515
/**
@@ -38,13 +38,13 @@ interface NearestPoint extends Feature<Point> {
3838
* var addToMap = [targetPoint, points, nearest];
3939
* nearest.properties['marker-color'] = '#F00';
4040
*/
41-
function nearestPoint(
41+
function nearestPoint<P extends GeoJsonProperties = GeoJsonProperties>(
4242
targetPoint: Coord,
43-
points: FeatureCollection<Point>,
43+
points: FeatureCollection<Point, P>,
4444
options: {
4545
units?: Units;
4646
} = {}
47-
): NearestPoint {
47+
): NearestPoint<P> {
4848
// Input validation
4949
if (!targetPoint) throw new Error("targetPoint is required");
5050
if (!points) throw new Error("points is required");

packages/turf-transform-translate/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { rhumbDestination } from "@turf/rhumb-destination";
99
* Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line
1010
* on the provided direction angle.
1111
*
12+
* Note that this moves the points of your shape individually and can therefore change
13+
* the overall shape. How noticable this is depends on the distance and the used projection.
14+
*
1215
* @function
1316
* @param {GeoJSON|GeometryCollection} geojson object to be translated
1417
* @param {number} distance length of the motion; negative values determine motion in opposite direction

0 commit comments

Comments
 (0)