Reputation: 7724
Suppose I have a NxN matrix, where each cell is a 1x1 white square.
Suppose I have a position P and a radius R. I want to paint all the cells of the circle of radius R centered in P.
Of course I could do this:
for(int i = P.x - R; i < P.x + R; i++)
for(int j = P.y - R; j < P.y + R; j++)
if (distance from P to (i,j) < R)
Paint(i,j)
But as I will run this code on a shader that will execute every frame, I'd like to know a faster way to find the correct cells instead of asking the distance for each cell, which is slow.
Is there a smarter way?
Upvotes: 2
Views: 158