Quadtree
Check out a live demo of this quadtree being in action with a canvas element.
npm install wbroberts-quadtree
; const canvas = document;const ctx = canvas;canvaswidth = 500;canvasheight = 500; const qTree = x: 0 y: 0 width: canvaswidth height: canvasheight ctx 4;const point = x: 10 y: 10 radius: 10 data: null ; qTree; // Inserts it into the quadtree. If the quadtree has more than 4 points, it divides into four more quadtrees. const area = x: 0 y: 0 width: 20 height: 20;const query = qTree; console; // [{ x: 10, y: 10, radius: 10, data: null }] const area2 = x: 20 y: 20 width: 20 height: 20;const query2 = qTree; console; // []
This was a project to learn more about data structures, specifically quadtrees (obviously). My goal was to successfully create one that I would be able to use in 2d canvas games for the web (primarily mine). Check out the link up above to see it working in action.