Skip to content

feat: add and remove points#6

Merged
sanDer153 merged 12 commits into
mainfrom
sander/add-and-remove
Aug 31, 2025
Merged

feat: add and remove points#6
sanDer153 merged 12 commits into
mainfrom
sander/add-and-remove

Conversation

@sanDer153
Copy link
Copy Markdown
Member

No description provided.

@sanDer153 sanDer153 marked this pull request as ready for review August 31, 2025 14:24
Copy link
Copy Markdown

@Max-Verbinnen Max-Verbinnen left a comment

Choose a reason for hiding this comment

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

awesome work! just left minor comments/suggestions

Comment thread index.js
const timerId = `prepare ${points.length} points`;
if (log) console.time(timerId);

this.trees = new Array(maxZoom + 2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why +2 instead of +1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is something that should have actually been +2 from the start, because that's the amount of space we need, but previously we just increased the length by 1 afterwards. We need space for each zoom level: 0...maxZoom and one extra: maxZoom + 1, which is a total of maxZoom + 2.

Comment thread index.js Outdated
return expansionZoom;
}

printClusterData() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe _printClusterData or do we want to expose this more publicly too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done 👍

Comment thread index.js
() => new Array(),
);
ancestorRemovals[maxZoom + 1].push(removedNode);
this._removeAncestors(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i will pretend to know what exactly is going on here 😅

Comment thread index.js
// encode both zoom and point index on which the cluster originated -- offset by total length of features
const id = (((i / stride) | 0) << 5) + (zoom + 1) + this.points.length;
// encode both zoom and point index on which the cluster originated
const id = -((((i / stride) | 0) << 5) + (zoom + 1));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a comment to explain why we use negative ids might be useful here!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done 👍

Comment thread index.js Outdated
Comment on lines +621 to +623
for (let i = idx * stride; i < (idx + 1) * stride; i++) {
this.clusterData[zoom][i] = null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe you can use the array fill() method instead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done 👍

Comment thread index.js Outdated
}
}

while (notVisited.length > 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this section looks very similar to the nonIndexedNodes check above. maybe extract into a helper? if it's too annoying, don't bother

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Extracted common part into a lambda!

Comment thread index.js Outdated
_linearSearchInPoints(id) {
const index = this.points.findIndex((p) => this.getId(p) === id);
const index = this.points.findIndex((p) =>
p ? this.getId(p) === id : false,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this ternary necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We do need some way to verify p is not null before calling getId() on it, because now with point removal, null can occur in the point list. I changed it to be a bit more concise though.

Comment thread index.js Outdated
_removeAncestors(firstZoom, descendantNodes, removals) {
const { minZoom } = this.options;
for (let zoom = firstZoom; zoom >= minZoom; zoom--) {
if (descendantNodes.length === 0) break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you could add this as a condition in the for-loop itself if you want

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done 👍

@sanDer153 sanDer153 merged commit 8402df9 into main Aug 31, 2025
2 checks passed
@sanDer153 sanDer153 deleted the sander/add-and-remove branch August 31, 2025 19:09
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.

2 participants