Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/turf-rhumb-bearing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ function rhumbBearing(
* var d = p1.rhumbBearingTo(p2); // 116.7 m
*/
function calculateRhumbBearing(from: number[], to: number[]) {
// Coincident points have no defined bearing (matches Geodesy reference impl)
if (from[0] === to[0] && from[1] === to[1]) {
return NaN;
}
// φ => phi
// Δλ => deltaLambda
// Δψ => deltaPsi
Expand Down
12 changes: 12 additions & 0 deletions packages/turf-rhumb-bearing/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ test("bearing", (t) => {
);
});

// Coincident points have no defined bearing — must return NaN, not 0
// Regression test for https://github.com/Turfjs/turf/issues/2478
const coincident = point([5, 5]);
t.ok(
isNaN(rhumbBearing(coincident, coincident)),
"coincident points return NaN"
);
t.ok(
isNaN(rhumbBearing(coincident, coincident, { final: true })),
"coincident points return NaN (final bearing)"
);

t.throws(() => {
rhumbBearing(point([12, -54]), "point");
}, "invalid point");
Expand Down
Loading