title: Getting the bounding box of a vector of points?
body: <p>I have a vector of points stored in a <code>std::vector</code> instance. I want to calculate the bounding box of these points.  I've tried with this code:</p>
  <pre><code>bool _compare1(ofPoint const &amp;p1, ofPoint const &amp;p2) {
      return p1.x &lt; p2.x &amp;&amp; p1.y &lt; p2.y;
  }
  bool _compare4(ofPoint const &amp;p1, ofPoint const &amp;p2) {
      return p1.x &gt; p2.x &amp;&amp; p1.y &gt; p2.y;
  }
  vector&lt;ofPoint&gt; points;
  
  // ...
  if(points.size()&gt;1) {
      ofPoint p_min = *std::min_element(points.begin(), points.end(), &amp;_compare1);
      ofPoint p_max = *std::min_element(points.begin(), points.end(), &amp;_compare4);
  }
  </code></pre>
  <p>But this code produces weird results.  In reality I'm interested only the first and last points of my bounding box:</p>
  <pre><code>1------2
  |\     |
  | \    |
  |  \   |
  |   \  |
  |    \ |
  |     \|
  3------4
  </code></pre>
  <p>If my points represent the diagonal line I'm interested only in point 1 and 4.</p>
  <p>Are there smart ways to get this with the standard libraries or Boost?</p>
  <hr />
  <h2>CURRENT SOLUTION:</h2>
  <pre><code>bool _compare_min_x(ofPoint const &amp;p1, ofPoint const &amp;p2) { return p1.x &lt; p2.x; }
  bool _compare_min_y(ofPoint const &amp;p1, ofPoint const &amp;p2) { return p1.y &lt; p2.y; }
   
  // ....
   
      if(points.size()&gt;1) {
          min_x = (*std::min_element(points.begin(), points.end(), &amp;_compare_min_x)).x;
          min_y = (*std::min_element(points.begin(), points.end(), &amp;_compare_min_y)).y;
  
          max_x = (*std::max_element(points.begin(), points.end(), &amp;_compare_min_x)).x;
          max_y = (*std::max_element(points.begin(), points.end(), &amp;_compare_min_y)).y;
      }
  </code></pre>