fix(@turf/line-slice-along): interpolate altitude on sliced endpoints#3084
Open
JSap0914 wants to merge 1 commit into
Open
fix(@turf/line-slice-along): interpolate altitude on sliced endpoints#3084JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
…closes Turfjs#3007) When destination() was updated (Turfjs#2852) to pass through the origin's altitude, lineSliceAlong began emitting wrong altitudes for interpolated start/stop vertices: it copied the near segment endpoint's elevation instead of interpolating linearly between the two segment endpoints. Fix: after computing the 2-D destination, calculate the fractional position of the interpolated vertex along its host segment and derive the altitude as a linear interpolation. When either segment endpoint lacks an altitude, any altitude that destination() may have attached is stripped so the result stays 2-D—matching behaviour before Turfjs#2852. Adds three tests: - stop vertex altitude ≈50 m when slicing midpoint of [0→100 m] segment - start vertex altitude ≈25 m when slicing starts at 25 m - 2-D lines produce 2-D interpolated vertices (no spurious altitude)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3007
Bug
When PR #2852 updated
destination()to pass through its origin's altitude,lineSliceAlongbegan emitting wrong elevations for the interpolated start/stop vertices it creates whenever a slice boundary falls in the middle of a segment.The function calls
destination(coords[i], overshot, bearing)— wherecoords[i]is the far end of the current segment — so the copied altitude was always that of the far endpoint, regardless of where the slice actually fell.Reproduction (from issue #3007):
Fix
After computing the 2-D destination, calculate the fractional position of the interpolated vertex along its host segment and derive the altitude as a linear interpolation between the two segment endpoints:
If either endpoint has no altitude the altitude component is removed from the output, preserving the 2-D behaviour that existed before #2852.
Verification
Three new tests added to
packages/turf-line-slice-along/test.ts:All 21 pre-existing tests continue to pass unchanged.