i'm not a c++ coder so mayebe it's easy.
i have a vector of Point class and i want to find the AABB rectangle:
- min x - min y
- min x - max y
- max x - min y
- max x - max y
i've done a for loop saving the min and the max (once for x and once for y), and updating the value for each iteration with some ifs.
but i'm sure there is something smarter in std or in boost .
for example i just tried:
vector<ofPoint> points;
// ....
bool _compareX(ofPoint const &p1, ofPoint const &p2) { return p1.x > p2.x; }
bool _compareY(ofPoint const &p1, ofPoint const &p2) { return p1.y > p2.y;}
void DrawerWidget::foo()
{
cout << std::min_element(points.begin(), points.end(), &_compareX) << endl;
}
but i'm getting a strange error like
error: no match for ‘operator<<’ in ‘std::cout << std::min_element [with _FIter = __gnu_cxx::__normal_iterator > >, _Compare = bool ()(const ofPoint&, const ofPoint&)](((DrawerWidget)this)->DrawerWidget::points.std::vector<_Tp, _Alloc>::begin with _Tp = ofVec3f, _Alloc = std::allocator, ((DrawerWidget*)this)->DrawerWidget::points.std::vector<_Tp, _Alloc>::end with _Tp = ofVec3f, _Alloc = std::allocator, _compareX)’
and a similar error if i put min_element somewhere else over the <<
min_element
returns an iterator to the minimum element, you are trying to send that tocout
.Use:
And you would also need to overload
<<
unless the vector element is an type for whichcout
already has an overloaded<<
operator.