-
Notifications
You must be signed in to change notification settings - Fork 35
API Reference
RTree ( [ Number max_node_width ] )
max_node_width : optional : The maximum width of a node before a split is performed1.
An empty RTree object.
Make a new RTree with a max node width of 10:
var myRTree = new RTree(10);
RTree.insert ( Rectangle2 bounds, Object element )
bounds : required : A minimally bounding box for element.
element : required : An object to add to the R-Tree.
Nothing.
Insert a 10×10 object that starts at position 10×10:
myRTree.insert({x:10, y:10, w:10, h:10}, myObject);
RTree.remove ( Rectangle2 area [, Object element ] )
area : required : An area to search within.
element : optional : An object to remove from the R-Tree. If no object is specified, all elements that touch area are deleted.
An array of leafs deleted from the R-Tree.
Deletes all object that touch the 10×10 rectangle starting at position 10×10:
var myDelCount = myRTree.delete({x:10, y:10, w:10, h:10});
Delete only specific_object if it touches the 10×10 rectangle starting at position 10×10:
var myDelCount = myRTree.delete({x:10, y:10, w:10, h:10}, specific_object);
RTree.search ( Rectangle2 area )
area : required : An area to search within.
An array of objects that overlap or touch area.
Search a 10×10 area that starts at position 10×10:
var myObjects = myRTree.search({x:10, y:10, w:10, h:10});
1 Default max node width is currently 6.
2 A Rectangle is any object with public x, y, w, h properties. The object itself is not saved or used directly but copies are made of its x, y, w, h properties.