Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

quatree implementation in javascript. I use the quadtree to optimize collision detection performance

Notifications You must be signed in to change notification settings

jamesearl/quadtree-javascript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

QuadTree Implementation in JavaScript

Author:

  • silflow

Usage

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

Insert

    tree.insert(item)
    // or
    tree.insert(items)

takes arrays or single items. every item must have a .x and .y property. if not, the tree will break. If your items have width and height, these should be .w and .h properties.

Retrieve

    tree.retrieve(selector)

iterates all items that match the selector and returns them in an array. For example:

    var selector = {
        x : selection top left x coordinate,
        y : selection top left y coordinate,
        w : selection width
        h : selection height
    }
    
    var items = tree.retrieve(selector);

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

Clear

    tree.clear()

removes all items from the quadtree.

About

quatree implementation in javascript. I use the quadtree to optimize collision detection performance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 94.1%
  • CSS 5.9%