Skip to content

Ignore invalid points in mixed addAll batches - #52

Merged
mbostock merged 1 commit into
d3:mainfrom
Zhuyuyangyy:fix/addall-invalid-coordinates-20261031
Nov 3, 2026
Merged

mbostock merged 1 commit into
d3:mainfrom
Zhuyuyangyy:fix/addall-invalid-coordinates-20261031

Conversation

@Zhuyuyangyy

Copy link
Copy Markdown
Contributor

addAll skips invalid coordinates during extent calculation, but the skipped slots in its Float64Array coordinate buffers remain zero. When the batch contains at least one valid point, the insertion pass therefore adds those invalid data as though their coordinates were (0, 0).

For example:

const data = [[1, 1], [NaN, 2]];
quadtree().addAll(data).size(); // 2, but should be 1

Adding the same data individually ignores the invalid point. This is inconsistent with the existing ignore-NaN behavior and the documented relationship between addAll and repeated add calls.

This stores a NaN marker in the skipped x-coordinate slot, so the existing add guard ignores it during insertion. It does not allocate another buffer or re-evaluate accessors. Valid-coordinate handling, extent calculation, input order, and short-circuiting the y accessor for an invalid x are unchanged.

Six additional tests cover mixed invalid x/y coordinates, an invalid point before a valid point, iterables, appending to an existing tree, accessor short-circuiting, and preservation of valid coerced-zero/coincident points. No generated distributions, versions, lockfiles, or dependencies are changed.

Local validation

With the existing yarn.lock installed using Yarn 1.22.22, --frozen-lockfile, and installation scripts disabled, on Node 24.19.0:

  • Unmodified baseline: 64 passing, ESLint passes.
  • New tests against the old implementation: 5 failing, 65 passing; the valid-zero control passes.
  • npm test: 70 passing, ESLint passes (locked Mocha 8.4.0 and ESLint 7.28.0).
  • 136 valid-data controls match the baseline exactly for tree structure, extent, data order, and size, including array/Set inputs and existing trees.
  • git diff --check: passes.

These are local results, not a claim that upstream CI has passed. The workflow's Node 14 matrix was not run locally.

AI assistance

This change and its tests were prepared with AI assistance on behalf of the account owner. It has not received an independent human review.

@mbostock
mbostock merged commit 133b0de into d3:main Nov 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants