DEV Community

Add00
Add00

Posted on

Quadtrees!

Greetings,

Having spent most of the past week working on Procedural Generation and Noise. I needed to find another topic for a second issue. So I was scrolling the list of issues available for Litecanvas and noticed one for creating Quadtrees.

I had many questions, what was a Quadtree? Where do they go? How many are ideal? And do they taste good? I was able to find satisfactory answers to all but one of my questions in my search. So I asked the repo owner if I could work on the issue.

A Quadtree is a tree type data structure which is an an efficient way to store spacial information. Each node in the tree has 4 child trees within it, this is a recursive relation ship. Visually a Quadtree looks something like this:
Image description

Where points can be found based on where they are located in the Quadtree. To create a Quadtree I first created a point and rectangle class, points would be stored in the tree, and a rectangle would be used to check for points within an area.

Then I created the Quadtree class which would hold the points and automatically subdivide into more Quadtrees as required. For debuging and testing reasons I also made a show function to visualize the changes. Once complete, I made my PR.

This concludes release 0.3, 0.4 is on the horizon!

Top comments (0)