From eaf4e334c312e5f15a628eb55bf2686b0d7789e9 Mon Sep 17 00:00:00 2001 From: muendlein Date: Sat, 10 May 2025 17:09:24 +0200 Subject: [PATCH 01/12] optimize search if node bbox is inside query box --- index.js | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 30676c7..361a873 100644 --- a/index.js +++ b/index.js @@ -225,11 +225,40 @@ export default class Flatbush { // search through child nodes for (let /** @type number */ pos = nodeIndex; pos < end; pos += 4) { + const nodeMinX = this._boxes[pos + 0]; + const nodeMinY = this._boxes[pos + 1]; + const nodeMaxX = this._boxes[pos + 2]; + const nodeMaxY = this._boxes[pos + 3]; + // check if node bbox intersects with query bbox - if (maxX < this._boxes[pos]) continue; // maxX < nodeMinX - if (maxY < this._boxes[pos + 1]) continue; // maxY < nodeMinY - if (minX > this._boxes[pos + 2]) continue; // minX > nodeMaxX - if (minY > this._boxes[pos + 3]) continue; // minY > nodeMaxY + if (maxX < nodeMinX || maxY < nodeMinY || minX > nodeMaxX || minY > nodeMaxY) { + continue; + } + + // check if node bbox is completely inside query bbox + if (minX <= nodeMinX && minY <= nodeMinY && maxX >= nodeMaxX && maxY >= nodeMaxY) { + let pos_start = pos; + let pos_end = pos; + + // depth search while not leaf + while (pos_start >= this.numItems * 4) { + pos_start = this._indices[pos_start >> 2] | 0; + const pos_end_start = this._indices[pos_end >> 2] | 0; + pos_end = Math.min(pos_end_start + this.nodeSize * 4, upperBound(pos_end_start, this._levelBounds))-4; + } + + for (let /** @type number */ leaf_pos = pos_start; leaf_pos <= pos_end; leaf_pos += 4) { + const nodeMinX = this._boxes[leaf_pos + 0]; + const nodeMinY = this._boxes[leaf_pos + 1]; + const nodeMaxX = this._boxes[leaf_pos + 2]; + const nodeMaxY = this._boxes[leaf_pos + 3]; + const leaf_index = this._indices[leaf_pos >> 2]; + if (filterFn === undefined || filterFn(leaf_index)) { + results.push(leaf_index); // leaf item + } + } + continue; + } const index = this._indices[pos >> 2] | 0; From cbc136d5762bc7ea99937ebfa0d4c8388d0cd0cd Mon Sep 17 00:00:00 2001 From: muendlein Date: Sat, 10 May 2025 17:14:00 +0200 Subject: [PATCH 02/12] fixed naming --- index.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 361a873..ec03efd 100644 --- a/index.js +++ b/index.js @@ -237,24 +237,20 @@ export default class Flatbush { // check if node bbox is completely inside query bbox if (minX <= nodeMinX && minY <= nodeMinY && maxX >= nodeMaxX && maxY >= nodeMaxY) { - let pos_start = pos; - let pos_end = pos; + let posStart = pos; + let posEnd = pos; // depth search while not leaf - while (pos_start >= this.numItems * 4) { - pos_start = this._indices[pos_start >> 2] | 0; - const pos_end_start = this._indices[pos_end >> 2] | 0; - pos_end = Math.min(pos_end_start + this.nodeSize * 4, upperBound(pos_end_start, this._levelBounds))-4; + while (posStart >= this.numItems * 4) { + posStart = this._indices[posStart >> 2] | 0; + const posEndStart = this._indices[posEnd >> 2] | 0; + posEnd = Math.min(posEndStart + this.nodeSize * 4, upperBound(posEndStart, this._levelBounds)) - 4; } - for (let /** @type number */ leaf_pos = pos_start; leaf_pos <= pos_end; leaf_pos += 4) { - const nodeMinX = this._boxes[leaf_pos + 0]; - const nodeMinY = this._boxes[leaf_pos + 1]; - const nodeMaxX = this._boxes[leaf_pos + 2]; - const nodeMaxY = this._boxes[leaf_pos + 3]; - const leaf_index = this._indices[leaf_pos >> 2]; - if (filterFn === undefined || filterFn(leaf_index)) { - results.push(leaf_index); // leaf item + for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { + const leafIndex = this._indices[leafPos >> 2]; + if (filterFn === undefined || filterFn(leafIndex)) { + results.push(leafIndex); // leaf item } } continue; From d00026b9a1dec96c0394f03267604a788ac6ae91 Mon Sep 17 00:00:00 2001 From: muendlein Date: Wed, 14 May 2025 23:17:10 +0200 Subject: [PATCH 03/12] reorder if statements --- index.js | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index ec03efd..f9ae591 100644 --- a/index.js +++ b/index.js @@ -235,32 +235,30 @@ export default class Flatbush { continue; } - // check if node bbox is completely inside query bbox - if (minX <= nodeMinX && minY <= nodeMinY && maxX >= nodeMaxX && maxY >= nodeMaxY) { - let posStart = pos; - let posEnd = pos; - - // depth search while not leaf - while (posStart >= this.numItems * 4) { - posStart = this._indices[posStart >> 2] | 0; - const posEndStart = this._indices[posEnd >> 2] | 0; - posEnd = Math.min(posEndStart + this.nodeSize * 4, upperBound(posEndStart, this._levelBounds)) - 4; - } - - for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { - const leafIndex = this._indices[leafPos >> 2]; - if (filterFn === undefined || filterFn(leafIndex)) { - results.push(leafIndex); // leaf item - } - } - continue; - } - const index = this._indices[pos >> 2] | 0; if (nodeIndex >= this.numItems * 4) { - queue.push(index); // node; add it to the search queue + // check if node bbox is completely inside query bbox + if (minX <= nodeMinX && minY <= nodeMinY && maxX >= nodeMaxX && maxY >= nodeMaxY) { + let posStart = pos; + let posEnd = pos; + + // depth search while not leaf + while (posStart >= this.numItems * 4) { + posStart = this._indices[posStart >> 2] | 0; + const posEndStart = this._indices[posEnd >> 2] | 0; + posEnd = Math.min(posEndStart + this.nodeSize * 4, upperBound(posEndStart, this._levelBounds)) - 4; + } + for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { + const leafIndex = this._indices[leafPos >> 2]; + if (filterFn === undefined || filterFn(leafIndex)) { + results.push(leafIndex); // leaf item + } + } + } else { + queue.push(index); // node; add it to the search queue + } } else if (filterFn === undefined || filterFn(index)) { results.push(index); // leaf item } From d1b015ffed0c909b3ea2f02f2456c0294cbcbcdf Mon Sep 17 00:00:00 2001 From: muendlein Date: Mon, 19 May 2025 23:44:09 +0200 Subject: [PATCH 04/12] split off functions --- index.js | 59 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index f9ae591..d5ac62b 100644 --- a/index.js +++ b/index.js @@ -240,22 +240,7 @@ export default class Flatbush { if (nodeIndex >= this.numItems * 4) { // check if node bbox is completely inside query bbox if (minX <= nodeMinX && minY <= nodeMinY && maxX >= nodeMaxX && maxY >= nodeMaxY) { - let posStart = pos; - let posEnd = pos; - - // depth search while not leaf - while (posStart >= this.numItems * 4) { - posStart = this._indices[posStart >> 2] | 0; - const posEndStart = this._indices[posEnd >> 2] | 0; - posEnd = Math.min(posEndStart + this.nodeSize * 4, upperBound(posEndStart, this._levelBounds)) - 4; - } - - for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { - const leafIndex = this._indices[leafPos >> 2]; - if (filterFn === undefined || filterFn(leafIndex)) { - results.push(leafIndex); // leaf item - } - } + addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, filterFn); } else { queue.push(index); // node; add it to the search queue } @@ -335,6 +320,48 @@ export default class Flatbush { } } +/** + * Add all leaves of a node to the search result. + * @param {number[]} results + * @param {number} pos + * @param {number} numItems + * @param {Uint16Array | Uint32Array} indices + * @param {number} nodeSize + * @param {number[]} levelBounds + * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results. + * @returns {void} + */ +function addAllLeavesOfNode(results, pos, numItems, indices, nodeSize, levelBounds, filterFn) { + let posStart = pos; + let posEnd = pos; + + // depth search while not leaf + while (posStart >= numItems * 4) { + posStart = indices[posStart >> 2] | 0; + const posEndStart = indices[posEnd >> 2] | 0; + posEnd = Math.min(posEndStart + nodeSize * 4, upperBound(posEndStart, levelBounds)) - 4; + } + addLeafSegment(results, posStart, posEnd, indices, filterFn); +} + +/** + * Add consecutive leaves to the search result. + * @param {number[]} results + * @param {number} posStart + * @param {number} posEnd + * @param {Uint16Array | Uint32Array} indices + * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results. + * @returns {void} + */ +function addLeafSegment(results, posStart, posEnd, indices, filterFn) { + for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { + const leafIndex = indices[leafPos >> 2]; + if (filterFn === undefined || filterFn(leafIndex)) { + results.push(leafIndex); // leaf item + } + } +} + /** * Binary search for the first value in the array bigger than the given. * @param {number} value From 2e8995f06e10aa359e7ec56bef23690eddd04b1d Mon Sep 17 00:00:00 2001 From: muendlein Date: Tue, 20 May 2025 21:14:36 +0200 Subject: [PATCH 05/12] inline addLeafSegment --- index.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/index.js b/index.js index d5ac62b..9d849cc 100644 --- a/index.js +++ b/index.js @@ -341,19 +341,7 @@ function addAllLeavesOfNode(results, pos, numItems, indices, nodeSize, levelBoun const posEndStart = indices[posEnd >> 2] | 0; posEnd = Math.min(posEndStart + nodeSize * 4, upperBound(posEndStart, levelBounds)) - 4; } - addLeafSegment(results, posStart, posEnd, indices, filterFn); -} -/** - * Add consecutive leaves to the search result. - * @param {number[]} results - * @param {number} posStart - * @param {number} posEnd - * @param {Uint16Array | Uint32Array} indices - * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results. - * @returns {void} - */ -function addLeafSegment(results, posStart, posEnd, indices, filterFn) { for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { const leafIndex = indices[leafPos >> 2]; if (filterFn === undefined || filterFn(leafIndex)) { From fb78a2e1223820996c3b4850e7bf449596f63852 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Wed, 21 May 2025 00:41:39 +0300 Subject: [PATCH 06/12] microoptimization --- index.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 9d849cc..96505f6 100644 --- a/index.js +++ b/index.js @@ -224,22 +224,18 @@ export default class Flatbush { const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds)); // search through child nodes - for (let /** @type number */ pos = nodeIndex; pos < end; pos += 4) { - const nodeMinX = this._boxes[pos + 0]; - const nodeMinY = this._boxes[pos + 1]; - const nodeMaxX = this._boxes[pos + 2]; - const nodeMaxY = this._boxes[pos + 3]; - + for (let /** @type number */ pos = nodeIndex, boxes = this._boxes; pos < end; pos += 4) { // check if node bbox intersects with query bbox - if (maxX < nodeMinX || maxY < nodeMinY || minX > nodeMaxX || minY > nodeMaxY) { - continue; - } + if (maxX < boxes[pos]) continue; // maxX < nodeMinX + if (maxY < boxes[pos + 1]) continue; // maxY < nodeMinY + if (minX > boxes[pos + 2]) continue; // minX > nodeMaxX + if (minY > boxes[pos + 3]) continue; // minY > nodeMaxY const index = this._indices[pos >> 2] | 0; if (nodeIndex >= this.numItems * 4) { // check if node bbox is completely inside query bbox - if (minX <= nodeMinX && minY <= nodeMinY && maxX >= nodeMaxX && maxY >= nodeMaxY) { + if (minX <= boxes[pos] && minY <= boxes[pos + 1] && maxX >= boxes[pos + 2] && maxY >= boxes[pos + 3]) { addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, filterFn); } else { queue.push(index); // node; add it to the search queue From f54cd2b65128be6001a6b60836b77c07b18722b3 Mon Sep 17 00:00:00 2001 From: Volodymyr Agafonkin Date: Mon, 8 Dec 2025 21:40:09 +0200 Subject: [PATCH 07/12] fixup --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0ac9890..5bd14a2 100644 --- a/index.js +++ b/index.js @@ -230,13 +230,13 @@ export default class Flatbush { // search through child nodes for (let /** @type number */ pos = nodeIndex, boxes = this._boxes; pos < end; pos += 4) { // check if node bbox intersects with query bbox - const x0 = this._boxes[pos]; + const x0 = boxes[pos]; if (maxX < x0) continue; - const y0 = this._boxes[pos + 1]; + const y0 = boxes[pos + 1]; if (maxY < y0) continue; - const x1 = this._boxes[pos + 2]; + const x1 = boxes[pos + 2]; if (minX > x1) continue; - const y1 = this._boxes[pos + 3]; + const y1 = boxes[pos + 3]; if (minY > y1) continue; const index = this._indices[pos >> 2] | 0; From ae203593af9da9cdb15203b525cafb5e5dcc74a9 Mon Sep 17 00:00:00 2001 From: muendlein Date: Thu, 11 Dec 2025 22:25:22 +0100 Subject: [PATCH 08/12] apply filterFn to leaves --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5bd14a2..be07f6c 100644 --- a/index.js +++ b/index.js @@ -244,7 +244,7 @@ export default class Flatbush { if (nodeIndex >= this.numItems * 4) { // check if node bbox is completely inside query bbox if (minX <= x0 && minY <= y0 && maxX >= x1 && maxY >= y1) { - addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, filterFn); + addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, boxes, filterFn); } else { queue.push(index); // node; add it to the search queue } @@ -332,10 +332,11 @@ export default class Flatbush { * @param {Uint16Array | Uint32Array} indices * @param {number} nodeSize * @param {number[]} levelBounds + * @param {number[]} boxes * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results. * @returns {void} */ -function addAllLeavesOfNode(results, pos, numItems, indices, nodeSize, levelBounds, filterFn) { +function addAllLeavesOfNode(results, pos, numItems, indices, nodeSize, levelBounds, boxes, filterFn) { let posStart = pos; let posEnd = pos; @@ -348,7 +349,7 @@ function addAllLeavesOfNode(results, pos, numItems, indices, nodeSize, levelBoun for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { const leafIndex = indices[leafPos >> 2]; - if (filterFn === undefined || filterFn(leafIndex)) { + if (filterFn === undefined || filterFn(leafIndex, boxes[leafPos], boxes[leafPos + 1], boxes[leafPos + 2], boxes[leafPos + 3])) { results.push(leafIndex); // leaf item } } From 626b2cf8a4cc0d315c260a1dfad26dc94378eea6 Mon Sep 17 00:00:00 2001 From: muendlein Date: Thu, 11 Dec 2025 22:34:27 +0100 Subject: [PATCH 09/12] clean up types --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index be07f6c..69de940 100644 --- a/index.js +++ b/index.js @@ -332,8 +332,8 @@ export default class Flatbush { * @param {Uint16Array | Uint32Array} indices * @param {number} nodeSize * @param {number[]} levelBounds - * @param {number[]} boxes - * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results. + * @param {InstanceType} boxes + * @param {(index: number, x0: number, y0: number, x1: number, y1: number) => boolean} [filterFn] An optional function for filtering the results. * @returns {void} */ function addAllLeavesOfNode(results, pos, numItems, indices, nodeSize, levelBounds, boxes, filterFn) { From 83033c118bf9de7173679df54be6951099ed8e10 Mon Sep 17 00:00:00 2001 From: muendlein Date: Sun, 21 Dec 2025 11:58:32 +0100 Subject: [PATCH 10/12] switch to recursive search --- index.js | 73 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 69de940..4dcc7c9 100644 --- a/index.js +++ b/index.js @@ -219,44 +219,53 @@ export default class Flatbush { } /** @type number | undefined */ - let nodeIndex = this._boxes.length - 4; - const queue = []; + const nodeIndex = this._boxes.length - 4; + /** @type number[] | undefined */ const results = []; - while (nodeIndex !== undefined) { - // find the end index of the node - const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds)); - - // search through child nodes - for (let /** @type number */ pos = nodeIndex, boxes = this._boxes; pos < end; pos += 4) { - // check if node bbox intersects with query bbox - const x0 = boxes[pos]; - if (maxX < x0) continue; - const y0 = boxes[pos + 1]; - if (maxY < y0) continue; - const x1 = boxes[pos + 2]; - if (minX > x1) continue; - const y1 = boxes[pos + 3]; - if (minY > y1) continue; - - const index = this._indices[pos >> 2] | 0; + this._searchRecursive(minX, minY, maxX, maxY, results, nodeIndex, filterFn); + return results; + } - if (nodeIndex >= this.numItems * 4) { - // check if node bbox is completely inside query bbox - if (minX <= x0 && minY <= y0 && maxX >= x1 && maxY >= y1) { - addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, boxes, filterFn); - } else { - queue.push(index); // node; add it to the search queue - } - } else if (filterFn === undefined || filterFn(index, x0, y0, x1, y1)) { - results.push(index); // leaf item + /** + * Recursive search the index by a bounding box. + * @param {number} minX + * @param {number} minY + * @param {number} maxX + * @param {number} maxY + * @param {number[]} results + * @param {number} nodeIndex + * @param {(index: number, x0: number, y0: number, x1: number, y1: number) => boolean} [filterFn] An optional function that is called on every found item; if supplied, only items for which this function returns true will be included in the results array. + * @returns {void} + */ + _searchRecursive(minX, minY, maxX, maxY, results, nodeIndex, filterFn) { + const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds)); + + // search through child nodes + for (let /** @type number */ pos = nodeIndex, boxes = this._boxes; pos < end; pos += 4) { + // check if node bbox intersects with query bbox + const x0 = boxes[pos]; + if (maxX < x0) continue; + const y0 = boxes[pos + 1]; + if (maxY < y0) continue; + const x1 = boxes[pos + 2]; + if (minX > x1) continue; + const y1 = boxes[pos + 3]; + if (minY > y1) continue; + + const index = this._indices[pos >> 2] | 0; + + if (nodeIndex >= this.numItems * 4) { + // check if node bbox is completely inside query bbox + if (minX <= x0 && minY <= y0 && maxX >= x1 && maxY >= y1) { + addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, boxes, filterFn); + } else { + this._searchRecursive(minX, minY, maxX, maxY, results, index, filterFn); } + } else if (filterFn === undefined || filterFn(index, x0, y0, x1, y1)) { + results.push(index); // leaf item } - - nodeIndex = queue.pop(); } - - return results; } /** From 796030d0bc4993eec26de1533a30f4c5cb6e81b6 Mon Sep 17 00:00:00 2001 From: muendlein Date: Sun, 21 Dec 2025 22:41:11 +0100 Subject: [PATCH 11/12] move add leaves to class --- index.js | 60 ++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 4dcc7c9..05ffc49 100644 --- a/index.js +++ b/index.js @@ -258,7 +258,8 @@ export default class Flatbush { if (nodeIndex >= this.numItems * 4) { // check if node bbox is completely inside query bbox if (minX <= x0 && minY <= y0 && maxX >= x1 && maxY >= y1) { - addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, boxes, filterFn); + //addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, boxes, filterFn); + this._addAllLeavesOfNode(results, pos, filterFn); } else { this._searchRecursive(minX, minY, maxX, maxY, results, index, filterFn); } @@ -268,6 +269,32 @@ export default class Flatbush { } } + /** + * Add all leaves of a node to the search result. + * @param {number[]} results + * @param {number} pos + * @param {(index: number, x0: number, y0: number, x1: number, y1: number) => boolean} [filterFn] An optional function for filtering the results. + * @returns {void} + */ + _addAllLeavesOfNode(results, pos, filterFn) { + let posStart = pos; + let posEnd = pos; + + // depth search while not leaf + while (posStart >= this.numItems * 4) { + posStart = this._indices[posStart >> 2] | 0; + const posEndStart = this._indices[posEnd >> 2] | 0; + posEnd = Math.min(posEndStart + this.nodeSize * 4, upperBound(posEndStart, this._levelBounds)) - 4; + } + + for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { + const leafIndex = this._indices[leafPos >> 2]; + if (filterFn === undefined || filterFn(leafIndex, this._boxes[leafPos], this._boxes[leafPos + 1], this._boxes[leafPos + 2], this._boxes[leafPos + 3])) { + results.push(leafIndex); // leaf item + } + } + } + /** * Search items in order of distance from the given point. * @param {number} x @@ -333,37 +360,6 @@ export default class Flatbush { } } -/** - * Add all leaves of a node to the search result. - * @param {number[]} results - * @param {number} pos - * @param {number} numItems - * @param {Uint16Array | Uint32Array} indices - * @param {number} nodeSize - * @param {number[]} levelBounds - * @param {InstanceType} boxes - * @param {(index: number, x0: number, y0: number, x1: number, y1: number) => boolean} [filterFn] An optional function for filtering the results. - * @returns {void} - */ -function addAllLeavesOfNode(results, pos, numItems, indices, nodeSize, levelBounds, boxes, filterFn) { - let posStart = pos; - let posEnd = pos; - - // depth search while not leaf - while (posStart >= numItems * 4) { - posStart = indices[posStart >> 2] | 0; - const posEndStart = indices[posEnd >> 2] | 0; - posEnd = Math.min(posEndStart + nodeSize * 4, upperBound(posEndStart, levelBounds)) - 4; - } - - for (let /** @type number */ leafPos = posStart; leafPos <= posEnd; leafPos += 4) { - const leafIndex = indices[leafPos >> 2]; - if (filterFn === undefined || filterFn(leafIndex, boxes[leafPos], boxes[leafPos + 1], boxes[leafPos + 2], boxes[leafPos + 3])) { - results.push(leafIndex); // leaf item - } - } -} - /** * Binary search for the first value in the array bigger than the given. * @param {number} value From 5e3775c6065f3c257862267b81273418eccb63b0 Mon Sep 17 00:00:00 2001 From: muendlein Date: Sun, 15 Mar 2026 22:53:53 +0100 Subject: [PATCH 12/12] clean up --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 05ffc49..fb8f602 100644 --- a/index.js +++ b/index.js @@ -258,7 +258,6 @@ export default class Flatbush { if (nodeIndex >= this.numItems * 4) { // check if node bbox is completely inside query bbox if (minX <= x0 && minY <= y0 && maxX >= x1 && maxY >= y1) { - //addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, boxes, filterFn); this._addAllLeavesOfNode(results, pos, filterFn); } else { this._searchRecursive(minX, minY, maxX, maxY, results, index, filterFn);