Skip to content

Latest commit

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

quadtree

A simple quadtree implementation.

alt quadtree

live demo

live demo

install

npm i @floorplanner/quadtree

api

exports

  • QuadTree The QuadTree
  • QuadTreeBoundary A bounding box to be used with QuadTree::retreive

static methods

  • QuadTree.create(x, y, width, height, capacity, max_level) Creates the quadtree.

instance methods

QuadTree
  • insert(x, y, data = null) Inserts an item at the specified coordinates.
  • traverse(cb = null) Traverses the tree, takes an optional callback method.
  • query(bounds) Retreives all data inside the specified bounds
QuadTreeBoundary
  • new QuadTreeBoundary(x0, y0, x1, y1) - Constructor

example

import{Quadtree,QuadTreeBoundary}from'@floorplanner/quadtree';letwidth=800;// width of the treeletheight=600;// height of the treeletcapacity=10;// capacity of a nodeletmax_level=5;// maximum recursion depthlettree=QuadTree.create(0,0,width,height,capacity,max_level);tree.insert(100,100,{text: 'some data'});tree.traverse(function(node){console.log(node.level,node.data);});letdata=tree.query(newnewQuadTreeBoundary(0,0,200,200));console.log(data);

About

A simple quadtree implementation

Topics

Resources

Stars

3 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages