Skip to content

Fix exact-point values in turf-interpolate - #3170

Draft
adiazpar wants to merge 1 commit into
Turfjs:masterfrom
adiazpar:fix/interpolate-exact-match-2743
Draft

adiazpar wants to merge 1 commit into
Turfjs:masterfrom
adiazpar:fix/interpolate-exact-match-2743

Conversation

@adiazpar

@adiazpar adiazpar commented Oct 2, 2026

Copy link
Copy Markdown

Fixes #2743. Related to #1601.

When a grid location exactly matches an input point, interpolate sets the known value but continues into distance weighting. For positive weights this reaches Infinity / Infinity and returns NaN.

Set the accumulated weight to 1 and stop the inner featureEach iteration at the first exact match. This follows the approach discussed by cbbeau in #1601 and the early-exit mechanism noted by lemonig in #2743.

The regression tests cover the exact match first, middle and last; zero and negative elevations; property precedence over the third coordinate; coordinate fallback; different accepted weights; polygon centroids; input immutability; and missing-value validation. The final tests produce 18 failures against the original implementation and pass after the fix.

Validation

Performed on Linux with Node 24.19.0, pnpm 11.19.0 and TypeScript 6.0.3:

  • Reproduced on current master and published 7.4.0
  • Focused interpolation suite: 71 assertions passed
  • pnpm build, pnpm run docs, pnpm run lint and git diff --check passed; documentation generation made no changes
  • All 176 package/consumer test and type-check scripts across 121 workspace projects passed using the same scripts with tsx replaced by its supported node --import tsx launcher

The standard pnpm test command passed lint but could not start the tsx CLI because the cloud environment blocks its IPC socket. The alternate-launcher result is separate from that blocked command. Node 22/26, live browser execution and benchmarks were not run locally.

Behavior notes

An exact input value takes precedence for all currently accepted weights, including zero and negative weights. Conflicting samples at the same coordinates use the first match. Unused later samples are not checked for missing values after early exit; a missing value on the matched sample still raises the existing error.

AI assistance

OpenAI's assistant researched the issue, prepared the code, tests and this description, and executed the checks above. A second AI review checked the patch and suggested additional regression coverage. Submitted as a draft for review.

Stop distance weighting when a grid point coincides with an input sample.
Add regressions for sample order, value sources, weights, and grid types.

Fixes Turfjs#2743. Related to Turfjs#1601.

AI assistance: OpenAI's assistant prepared this patch and tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interpolate should bail early if an exact distance match is found

1 participant