Problem with points
Removing and searching points does not work properly. I think the problem is that the width and height of the rectangle for points is 0. For example the rectangle used to insert the point (1 1) is: {x: 1, y: 1, w: 0, h: 0}
<html>
<head>
<script src="RTree/src/rtree.js"></script>
<script type="text/javascript">
var rtee;
function init() {
rtree = new RTree();
var point1 = { 'id': 1,
'bounds': {x: 10, y: 5, w: 0, h: 0}};
var point2 = { 'id': 2,
'bounds': {x: 6, y: 7, w: 0, h: 0}};
rtree.insert(point1.bounds, point1);
rtree.insert(point2.bounds, point2);
var removedCount = rtree.remove(point1.bounds, point1);
console.log(removedCount); // output: []
removedCount = rtree.remove({x: 9.5, y: 4.5, w: 1, h: 1}, point1);
console.log(removedCount); // output: [Object] (leaf containing point1)
var objects = rtree.search({x:6, y: 7, w: 1, h: 1});
console.log(objects); // output: []
objects = rtree.search({x:5.5, y: 6.5, w: 1, h: 1});
console.log(objects[0]); // output: Object (point2)
}
</script>
</head>
<body onload="init()">
</body>
</html>
This is not a bug. RTree searches for erea intresections excluding borders. Points can intersect with other points only at their borders, simply because neither has an area. So it is not possible to find points by searching for points. You can however, search for rectangles using points or search for points using rectangles - because the rectangle will provide an area for intresection. If you do want to explicitly include borders you should change the overlap_rectangle method and change each occurance of > and < there to >= and <= respectively. This will alter how shapes intersect and will include their borders in the intersection test.