【发布时间】:2012-02-22 13:10:31
【问题描述】:
我不是 C++ 编码员,所以也许这很容易。
我有一个 Point 类的向量,我想找到 AABB 矩形:
- 最小 x - 最小 y
- 最小 x - 最大 y
- 最大 x - 最小 y
- 最大 x - 最大 y
我已经完成了一个 for 循环,保存了最小值和最大值(x 一次,y 一次),并使用一些 if 更新每次迭代的值。
但我确信在 std 或 boost 中有更聪明的东西 .
例如我刚刚尝试过:
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;
}
但我遇到了一个奇怪的错误,例如
错误:'std::cout >, _Compare = bool ()(const ofPoint&, const ofPoint&)](((DrawerWidget)this)->DrawerWidget::points.std::vector<_tp _alloc>:: 以 _Tp = ofVec3f 开头,_Alloc = std::allocator, ((DrawerWidget*)this)->DrawerWidget::points.std::vector<_tp _alloc>::end with _Tp = ofVec3f, _Alloc = std::allocator, _compareX)'
如果我将 min_element 放在 上的其他位置,则会出现类似的错误
【问题讨论】:
标签: c++ std stdvector min aabb