Missing intersections?
mikolalysenko opened this issue · comments
I'm comparing a couple of different approaches for finding all intersections in a set of boxes and am having some trouble with rbush. What I would like to do for this benchmark is just count the number of unique pairs of intersecting boxes in a data set. Here is the code which I am using:
var tree = rbush(9).load(boxes)
var count = 0
for(var i=0, n=boxes.length; i<n; ++i) {
count += tree.search(boxes[i]).length - 1
}
console.log('num intersections =', count >>> 1)
I think this is correct based on my understanding of the API (though maybe I made a mistake). However it doesn't produce the expected result. The problem is that rbush seems to be missing a bunch of intersections. For example, if I run it on this set of boxes (using the [minX, minY, maxX, maxY] convention):
var boxes= [ [ 0.34745634417049587,
0.19826999702490866,
0.4911531714024022,
0.31181562286801634 ],
[ 0.3350245540495962,
0.08664853242225945,
0.5047857862198726,
0.24504178347997368 ],
[ 0.5165957966819406,
0.8958366981241852,
0.654163204645738,
0.9974054682301358 ],
[ 0.31746723409742117,
0.05729875573888421,
0.4619402693584561,
0.16601366791874173 ],
[ 0.48703365214169025,
0.06490733567625284,
0.591369220148772,
0.16663535516709088 ],
[ 0.22250890382565558,
0.8383511677384377,
0.35378385097719733,
0.9443910819012672 ],
[ 0.1840909782331437,
0.32956261769868433,
0.35404338778462263,
0.4312351857777685 ],
[ 0.1586302185896784,
0.4483339211437851,
0.3295042036101222,
0.643072936614044 ],
[ 0.3659458786714822,
0.9313615325372666,
0.4676822068169713,
1.1038383034523576 ],
[ 0.731653404654935,
0.9573151601944119,
0.8854661131510511,
1.0714723680866882 ] ]
rbush reports only 3 intersections, but by brute force I can find 11.
Is there something I am doing wrong here?
Never mind, just too tired this morning. There was a bug in my brute force implementation.
@mikolalysenko excited to see you playing with my library :)
FYI @mourner we use rbush to great effect in https://github.com/bokeh/bokeh
@bryevdv yes, saw that — great work! Always nice to see my work being used in successful projects.