title: Polygon in rectangle algorithm?
body: <p>I have an algorithm which can find if a point is in a given polygon:</p>
  
  <pre><code> int CGlEngineFunctions::PointInPoly(int npts, float *xp, float *yp, float x, float y)
   {
       int i, j, c = 0;
       for (i = 0, j = npts-1; i &lt; npts; j = i++) {
           if ((((yp[i] &lt;= y) &amp;&amp; (y &lt; yp[j])) ||
               ((yp[j] &lt;= y) &amp;&amp; (y &lt; yp[i]))) &amp;&amp;
               (x &lt; (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
               c = !c;
       }
       return c;
   }
  </code></pre>
  
  <p>given this, how could I make it check if its within a rectangle defind by Ptopleft and Pbottomright instead of a single point?</p>
  
  <p>Thanks</p>
  
  <p>Basically you know how in Adobe Illustrator you can drag to select all objects that fall within the selection rectangle? well I mean that. –</p>