quatree implementation in javascript
JavaScript CSS
Switch branches/tags
Nothing to show
Clone or download
Latest commit 0c9ad09 May 14, 2014
Failed to load latest commit information.
examples fixed drawing bug in ex1 Sep 20, 2013
test updated documentation Feb 6, 2013
README.md updated readme to be more precise Sep 20, 2013
quadtree.js resolved merge conflicts May 14, 2014


QuadTree Implementation in JavaScript


  • silflow


To create a new empty Quadtree, do this:

args = {
   // mandatory fields
   x : x coordinate
   y : y coordinate
   w : width
   h : height
   // optional fields
   maxChildren : max children per node
   maxDepth : max depth of the tree

var tree = QUAD.init(args);

Available methods


takes arrays or single items. every item must contain the following properties:

var item = {
	// mandatory fields
	x : x coordinate
	y : y coordinate
	w : width
	h : height

if the item does not contain all of those fields, the behaviour of the tree is not defined

tree.retrieve(selector, callback)

iterates all items that match the selector and invokes the supplied callback on them.

var selector = {
	// mandatory fields
    x : topLeft coordinate,
    y : topRight coordinate,
    w : selection width
    h : selection height

tree.retrieve(selector, function(item) {

NOTE: The result contains all items in quadtree-regions that are overlapping with the selector.


removes all items from the quadtree.