Skip to content

Instantly share code, notes, and snippets.

@companje
Created December 2, 2019 19:05
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/a1cab8bd67ef98ec101366de0e7b1895 to your computer and use it in GitHub Desktop.
Save companje/a1cab8bd67ef98ec101366de0e7b1895 to your computer and use it in GitHub Desktop.
getBounds from points
Rectangle getBounds(ArrayList<PVector> vv) {
if (vv.size()==0) return new Rectangle();
float xMin = Float.POSITIVE_INFINITY;
float yMin = Float.POSITIVE_INFINITY;
float xMax = Float.NEGATIVE_INFINITY;
float yMax = Float.NEGATIVE_INFINITY;
for (int i=1; i<vv.size(); i++) {
xMin = min(xMin,vv.get(i).x);
yMin = min(yMin,vv.get(i).y);
xMax = max(xMax,vv.get(i).x);
yMax = max(yMax,vv.get(i).y);
}
Rectangle r = new Rectangle();
r.setFrame(xMin,yMin,xMax-xMin,yMax-yMin);
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment