私はC++コーダーではないので、簡単かもしれません。
Pointクラスのベクトルがあり、AABB長方形を見つけたい:
- min x-min y
- 最小x-最大y
- 最大x-最小y
- max x-max y
最小値と最大値を保存するforループ(xに1回、yに1回)を実行し、各反復の値をいくつかの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 << std :: min_element [with _FIter = __gnu_cxx :: __ normal_iterator >>、_Compare = bool()(const ofPoint&、const ofPoint&)](((DrawerWidget)this)-> DrawingWidget :: points.std :: vector <_Tp、_Alloc> :: begin with _Tp = ofVec3f、_Alloc = std :: allocator、((DrawerWidget *)this)-> DrawingWidget :: points.std: :vector <_Tp、_Alloc> :: end with _Tp = ofVec3f、_Alloc = std :: allocator、_compareX)'</ p>
min_elementを<<のどこかに置いた場合も同様のエラーが発生します