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

RTree ( max_node_width )

Parameters:

max_node_width : optional : The maximum width of a node before a split is forced. Defaults to 6.

Returns:

A new and empty RTree object.

Usage:

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

RTree.count ( area_to_search )

Parameters:

area_to_search : required : An area to search within.

Returns:

The number of objects that overlap or touch area_to_search.

Usage:

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

RTree.search ( area_to_search )

Parameters:

area_to_search : required : An area to search within.

Returns:

An array of objects that overlap or touch area_to_search.

Usage:

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

RTree.insert ( bounding_box, object_to_insert )

Parameters:

bounding_box : required : A minimally bounding box for object_to_insert.
object_to_insert : 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 ( area_to_search, object_to_remove )

Parameters:

area_to_search : required : An area to search within.
object_to_remove : optional : An object to remove from the R-Tree. If no object is specified, all objects touching area_to_search are deleted.

Returns:

The number of objects deleted from the R-Tree.

Usage:

Deletes all object that touch the 10×10 rectangle starting at position 10×10:
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:
myRTree.delete({x:10, y:10, w:10, h:10}, specific_object);

Clone this wiki locally