static L gridOfRectangles(Rectangle r, int cols, int rows) { new L l; for row to rows: { int y1 = r.y+(int) Math.round(r.height*(double) row/rows); int y2 = r.y+(int) Math.round(r.height*(double) (row+1)/rows); for col to cols: { int x1 = r.x+(int) Math.round(r.width*(double) col/cols); int x2 = r.x+(int) Math.round(r.width*(double) (col+1)/cols); l.add(new Rectangle(x1, y1, x2-x1, y2-y1)); } } ret l; }