mourner / rbush

RBush — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
MIT License
2.48k stars 237 forks source link

Ensure _chooseSplitIndex always return a number #94

Closed DiogoDoreto closed 5 years ago

DiogoDoreto commented 5 years ago

Fix #69

Current implementation of _chooseSplitIndex may return undefined when all children have infinity area.

When all inserted rects are infinity, they will be all inserted in a single node, instead of properly balancing the tree (updated test to validate this).

When data is random, an incorrect split may occur in a non-leaf node, causing a non-leaf node to have 0 children and causing error #69 when the tree will try to insert new data in its path.

This fix ensure that _chooseSplitIndex always return a number.

borodaev commented 5 years ago

Great!