Source
Rectangle<num> getBounds() { num maxX = double.NEGATIVE_INFINITY; num minX = double.INFINITY; num maxY = double.NEGATIVE_INFINITY; num minY = double.INFINITY; for(int i = 0; i < points.length; i++) { Point<num> point = points[i]; maxX = max(maxX, point.x); minX = min(minX, point.x); maxY = max(maxY, point.y); minY = min(minY, point.y); } return new Rectangle<num>(minX, minY, maxX - minX, maxY - minY); }