Created
May 31, 2012 20:12
-
-
Save companje/2845908 to your computer and use it in GitHub Desktop.
BoundingBox and Pivot/Anchor point of points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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