Skip to content
imbcmdth edited this page Sep 13, 2010 · 31 revisions

RTree

RTree ( [ Number max_node_width ] )

Parameters:

max_node_width : optional : The maximum width of a node before a split is performed1.

Returns:

An empty RTree object.

Usage:

Make a new RTree with a max node width of 10:
var myRTree = new RTree(10);

RTree.insert

RTree.insert ( Rectangle2 bounds, Object element )

Parameters:

bounds : required : A minimally bounding box for element.
element : required : An object to add to the R-Tree.

Returns:

Nothing.

Usage:

Insert a 10×10 object that starts at position 10×10:
myRTree.insert({x:10, y:10, w:10, h:10}, myObject);

RTree.remove

RTree.remove ( Rectangle2 area [, Object element ] )

Parameters:

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.

Returns:

An array of leafs deleted from the R-Tree.

Usage:

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

RTree.search ( Rectangle2 area )

Parameters:

area : required : An area to search within.

Returns:

An array of objects that overlap or touch area.

Usage:

Search a 10×10 area that starts at position 10×10:
var myObjects = myRTree.search({x:10, y:10, w:10, h:10});

Notes

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.