Skip to content

Commit fb78a2e

Browse files
committed
microoptimization
1 parent 2e8995f commit fb78a2e

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,18 @@ export default class Flatbush {
224224
const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));
225225

226226
// search through child nodes
227-
for (let /** @type number */ pos = nodeIndex; pos < end; pos += 4) {
228-
const nodeMinX = this._boxes[pos + 0];
229-
const nodeMinY = this._boxes[pos + 1];
230-
const nodeMaxX = this._boxes[pos + 2];
231-
const nodeMaxY = this._boxes[pos + 3];
232-
227+
for (let /** @type number */ pos = nodeIndex, boxes = this._boxes; pos < end; pos += 4) {
233228
// check if node bbox intersects with query bbox
234-
if (maxX < nodeMinX || maxY < nodeMinY || minX > nodeMaxX || minY > nodeMaxY) {
235-
continue;
236-
}
229+
if (maxX < boxes[pos]) continue; // maxX < nodeMinX
230+
if (maxY < boxes[pos + 1]) continue; // maxY < nodeMinY
231+
if (minX > boxes[pos + 2]) continue; // minX > nodeMaxX
232+
if (minY > boxes[pos + 3]) continue; // minY > nodeMaxY
237233

238234
const index = this._indices[pos >> 2] | 0;
239235

240236
if (nodeIndex >= this.numItems * 4) {
241237
// check if node bbox is completely inside query bbox
242-
if (minX <= nodeMinX && minY <= nodeMinY && maxX >= nodeMaxX && maxY >= nodeMaxY) {
238+
if (minX <= boxes[pos] && minY <= boxes[pos + 1] && maxX >= boxes[pos + 2] && maxY >= boxes[pos + 3]) {
243239
addAllLeavesOfNode(results, pos, this.numItems, this._indices, this.nodeSize, this._levelBounds, filterFn);
244240
} else {
245241
queue.push(index); // node; add it to the search queue

0 commit comments

Comments
 (0)