Skip to content

Instantly share code, notes, and snippets.

@companje
Created May 31, 2012 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/2845908 to your computer and use it in GitHub Desktop.
Save companje/2845908 to your computer and use it in GitHub Desktop.
BoundingBox and Pivot/Anchor point of points
vector<ofPoint*> getAllPointsFromPath() {
vector<ofPoint*> points;
vector<ofSubPath> &subpaths = path.getSubPaths();
for (int i=0; i<subpaths.size(); i++) {
vector<ofSubPath::Command> &commands = subpaths[i].getCommands();
for (int j=0; j<commands.size(); j++) {
points.push_back(&commands[j].to);
}
}
return points;
}
ofPoint getCenterPoint() {
return getBoundingBox().getCenter();
// ---- my previous approach: taking the average of the points ---
//ofPoint sum;
//vector<ofPoint*> points = getAllPointsFromPath();
//if (points.size()==0) return ofPoint(0,0);
//for (int i=0; i<points.size(); i++) sum+=(*points[i]);
//return sum/points.size();
}
ofRectangle getBoundingBox() {
vector<ofPoint*> points = getAllPointsFromPath();
if (points.size()<1) return ofRectangle();
float xMin=9999,xMax=-9999,yMin=9999,yMax=-9999;
for (int i=0; i<points.size(); i++) {
ofPoint &pt = *points[i];
xMin = min(xMin,pt.x);
xMax = max(xMax,pt.x);
yMin = min(yMin,pt.y);
yMax = max(yMax,pt.y);
}
return ofRectangle(xMin,yMin,xMax-xMin,yMax-yMin);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment