Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed multiple modules that were performing scalar instead of spherical calculations #2717

Merged
merged 5 commits into from
Sep 25, 2024

Conversation

smallsaucepan
Copy link
Member

Fixed multiple modules that were performing scalar (2D) calculations when they should have been doing spherical (3D).

Most changes were to nearestPointOnLine. pointToLineDistance now uses nearestPointOnLine for spherical calculations. Flow on corrections impacted lineSlice and nearestPointToLine as well.

Should fix some long standing issues, and be a step towards Turf being internally consistent. For example, a point returned by nearestPointOnLine should have a pointToLineDistance of 0. Or (eventually) return true for booleanPointOnLine.

Resolves #965
Resolves #1156
Resolves #1514
Resolves #1878
Resolves #2023
Resolves #2234
Resolves #2270

…ns when they should have been doing spherical (3D). Most changes were to nearestPointOnLine. pointToLineDistance now uses nearestPointOnLine for spherical calculations. Flow on corrections impacted lineSlice and nearestPointToLine as well.

Tidied up some tests - fixed module name in test definitions, added a benchmark overall time in a few places for easier comparisons.
@smallsaucepan
Copy link
Member Author

Btw, benchmark performance tests for nearestPointOnLine were unchanged.

Copy link
Collaborator

@twelch twelch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor feedback, otherwise looks good on scan review. I don't follow the vector math deeply, but trust that you faithfully reimplemented the source. And I see that all of the added tests demonstrate improvement.

packages/turf-point-to-line-distance/index.ts Outdated Show resolved Hide resolved
packages/turf-point-to-line-distance/index.ts Outdated Show resolved Hide resolved
packages/turf-nearest-point-on-line/index.ts Outdated Show resolved Hide resolved
Comment on lines 189 to 191
posA: Position,
posB: Position,
posC: Position
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth clarifying what each parameter is expected to be? I see you passing the posA - start point of segment, posB - end point of segment, posC - point to find nearest point on segment.

packages/turf-nearest-point-on-line/index.ts Outdated Show resolved Hide resolved
@smallsaucepan
Copy link
Member Author

Thanks @twelch. Will implement all those suggestions and merge shortly.

…ans and toDegrees functions from turf-helpers.
…iansToDegress and degreesToRadians from turf-helpers. It seems (degrees * Math.PI) / 180 can sometimes differ slightly from degrees * (Math.PI / 180).
@smallsaucepan smallsaucepan merged commit 5692841 into Turfjs:master Sep 25, 2024
3 checks passed
@axelvestinsmhi
Copy link

Nice, this is just what i needed!

@thorseye
Copy link

thorseye commented Oct 2, 2024

Just what I was looking for! :)
@smallsaucepan When can we expect this in a release available on npm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants