Skip to content

Fix lineSliceAlong() dropping altitude of the line's vertices - #1637

Merged
natiginfo merged 2 commits into
mainfrom
nb/fix-lineSliceAlong
Jul 31, 2026
Merged

Fix lineSliceAlong() dropping altitude of the line's vertices#1637
natiginfo merged 2 commits into
mainfrom
nb/fix-lineSliceAlong

Conversation

@natiginfo

@natiginfo natiginfo commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes MAPSAND-2853 / #1636.

Problem

TurfMisc.lineSliceAlong() returns 2D points for a 3D input LineString since v7.10.0; v7.9.0 preserved altitude on the vertices.

Root cause

The flat-coordinate rewrite (#1630) changed lineSliceAlong() to read FlattenListOfPoints#getFlattenLngLatArray() and rebuild every point with the 2-arg Point.fromLngLat(lng, lat). The altitudes live in a parallel array (FlattenListOfPoints#getAltitudes()) that the rewrite never read. The previous implementation used line.coordinates() and passed the Points straight through, so altitude survived.

Fix

Read the altitudes alongside the flat array and rebuild the emitted vertices through a small private helper that mirrors the null/NaN handling in FlattenListOfPoints#points().

The interpolated start and stop points stay 2D: they come from TurfMeasurement#destination(), which has always been 2D, and bearing()/distance() ignore altitude. With the vertices restored the output matches v7.9.0 exactly, which is the behaviour the report asks for.

getFlattenLngLatArray() has exactly one call site outside services-geojson, so no other Turf method is affected. TurfMeasurement.along()/length() never use the flatten path.

Verification

New TurfMiscTest#testLineSliceAlongPreservesAltitude slices a 3D line from 0 to its full length, so every returned point is an original vertex, and asserts altitude on each. Confirmed failing before the fix and passing after; :services-turf:test and :services-geojson:test are green.

Note: checkstyleMain could not be run locally — it fails the same way on unmodified main (SuppressionFilter - Unable to find: config/checkstyle/suppressions.xml), so CI gates it here.

🤖 Generated with Claude Code

The flat coordinate rewrite made lineSliceAlong() rebuild every point from
FlattenListOfPoints#getFlattenLngLatArray() only, ignoring the parallel
altitudes array, so 3D input lines came back as 2D. Read the altitudes and
rebuild the emitted vertices through them.

The interpolated start and stop points remain 2D: they are computed by
TurfMeasurement#destination(), which has always been 2D. With the vertices
restored the output matches v7.9.0 exactly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@natiginfo
natiginfo requested a review from jush July 29, 2026 20:23
@natiginfo natiginfo added the ai AI coding agents co-authored the code label Jul 29, 2026
@natiginfo
natiginfo marked this pull request as ready for review July 29, 2026 20:26
@natiginfo
natiginfo requested a review from a team as a code owner July 29, 2026 20:26
@natiginfo natiginfo self-assigned this Jul 30, 2026
jush
jush previously approved these changes Jul 30, 2026
yuryybk
yuryybk previously approved these changes Jul 31, 2026
@natiginfo
natiginfo dismissed stale reviews from yuryybk and jush via 3c245c9 July 31, 2026 11:01
@ox-security

ox-security Bot commented Jul 31, 2026

Copy link
Copy Markdown

OX Security Logo

Successfully scanned changes introduced in a pull request into main from nb/fix-lineSliceAlong.

Internal scan identifier: 1cd85dfb-346b-4010-b575-1b036c868192.

Total issues Blocking issues Scan status
1 0 ✔️
Category Issues
Secret/PII Scan 1

See all issues found during this scan in the OX Security Application.

Detailed information
Issue #1
NameGeneric Key • Public Repo
StatusOld
EnforcementMonitor
SeverityHigh
CategorySecret/PII Scan
Source toolsOX Secret/PII Scan
RecommendationPlease verify if the Generic Key in the code is in use. Then do the following:

1. If the secret is in use, please revoke it.
2. Moving forward, store secrets in an environment variable or secret manager.
3. Change the code to access secrets using the method chosen above.

WARNING: The found Generic Key will still be visible in the Git History. Ensure it is revoked/disabled.
1 aggregation
FileMatch
scripts/coverage.shd56942c32a1bb70af75bf972302b6114********************************

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.36%. Comparing base (53a24f5) to head (3c245c9).

Files with missing lines Patch % Lines
...s-turf/src/main/java/com/mapbox/turf/TurfMisc.java 90.00% 0 Missing and 1 partial ⚠️

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #1637   +/-   ##
=========================================
  Coverage     79.35%   79.36%           
- Complexity     1129     1131    +2     
=========================================
  Files           162      162           
  Lines          4698     4705    +7     
  Branches        659      660    +1     
=========================================
+ Hits           3728     3734    +6     
  Misses          702      702           
- Partials        268      269    +1     
Files with missing lines Coverage Δ
...s-turf/src/main/java/com/mapbox/turf/TurfMisc.java 88.57% <90.00%> (-0.12%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@natiginfo
natiginfo merged commit c6c8947 into main Jul 31, 2026
5 of 6 checks passed
@natiginfo
natiginfo deleted the nb/fix-lineSliceAlong branch July 31, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai AI coding agents co-authored the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants