Spacial Partitioning - Pretty efficient

I wish the header image was what I did. It looks stunning and so much more useful that what my implementation is for a little renderer that just draws circles...

Above is spacial partitioning using a 3 x 3 grid, so it consists of nine individually rendered quadrants.

While below is just rendering the colour per pixel, so it's extremely inefficient.

For the grids to be set up along with storing the circles. I created a dictionary with the key being a pair of ints and the value being a Grid class, so it looks something like this: std::map<std::pair<int, int>, Grid> grids;
Then it creates the 3 x 3 or whatever dimension grid by simply using the pair of ints as the x and y coordinates of the grid, and it stores the top left and bottom right boundary coordinates for later use.

After that it generates the circles, stores their boundaries as well, and loops over each grid quadrant, and their pixels inside. Then all the circles inside that quadrant. So that's more or less how that's executed, but I probably missed something or explained it wrong. But you can check out the repo below and all is good! It's licenced under MIT so anyone can tinker with it.

Tom Lynn

Read more posts by this author.