title: Iterating over all (i,j)-elements in a circle
body: <p>Given two (very simplified) classes:</p>
  
  <pre><code>class Rectangle {
    public:
      int iL,jL; // lower left point of rectangle
      int width, length; // width: in i-direction, length: in j-direction
  };
  
  class Circle {
    public:
      int iC,jC; // center-point of circle
      int radius;
  };
  </code></pre>
  
  <p>If I want to iterate over all elements in a <code>Rectangle</code>, I can simply do that by:</p>
  
  <pre><code>for (int i = iL; i &lt; iL-width; i--)
    for (int j = jL; j &lt; jL+length; j++)
      doSomething();
  </code></pre>
  
  <p>My problem is to implement a smart way of iterating over all elements in <code>Circle</code>. My current solution looks as follows:</p>
  
  <pre><code>for (int i = iC-radius; i &lt;= iC+radius; i++)
    for (int j = jC-radius; j &lt;= jC+radius; j++)
      if ( sqrt(pow(i-iC,2)+pow(j-jC,2)) &lt;= r ) // checking if (i,j) lies within the circle (or its boundary)
        doSomething();
  </code></pre>
  
  <p>However, for <code>radius</code> getting large my current solution is very time-expensive (since I touch many elements which aren't in the <code>Circle</code> and since I always need to evaluate <code>pow</code>). Can you think of a more intelligent and efficient way of iteration over all <code>Circle</code>-elements?</p>