I have a vector of points stored in a std::vector instance. I want to calculate the bounding box of these points. I\'ve tried with this code:
bo
If you don't have c++11, you can use boost::algorithm::minmax_element.
#include
bool compareX(ofPoint lhs, ofPoint rhs) { return lhs.x < rhs.x; };
bool compareY(ofPoint lhs, ofPoint rhs) { return lhs.y < rhs.y; };
// ....
pair::iterator, vector::iterator> xExtremes, yExtremes;
xExtremes = boost::minmax_element(overlap_point.begin(), overlap_point.end(), compareX);
yExtremes = boost::minmax_element(overlap_point.begin(), overlap_point.end(), compareY);
ofPoint upperLeft(xExtremes.first->x, yExtremes.first->y);
ofPoint lowerRight(xExtremes.second->x, yExtremes.second->y);