二维vector的遍历
turnPoints是一个二维vector容器,下面代码实现了二维vector的逐个遍历,类似于以为数组
float distance = 100; for(int i = 0; i < points.size()-1; i++) for(int j = i+1; j<points.size(); j++) { if(distance < (points[i]-points[j]).distance())) distance = (points[i]-points[j]).distance()); }
vector<vector<Point>>turnPoints;
for(int i = 0; i < turnPoints.size()-1; i++) for(int j = 0; j < turnPoints[i].size()-1; j++) for(int m = i; m < turnPoints.size(); m++) { int n; if( m == i) n = j+1; else n = 0; for( ; n < turnPoints[m].size(); n++) { FPoint3 p = turnPoints[i][j] - turnPoints[m][n]; if(p.Length() < distance) distance = p.Length(); if(p.Length() < 10) { FPoint3 midP = (turnPoints[i][j] + turnPoints[m][n])/2; turnPoints[i][j] = midP; turnPoints[m][n] = midP; } } }