List<IntBox> newPartitions = new ArrayList<IntBox>();
for (IntBox b: partitions) {
if (b.xsize() > b.ysize()) {
// Split along x axis
int xmid = (b.xmin() + b.xsize() / 2);
newPartitions.add(new IntBox(b.xmin(), xmid - 1, b.ymin(), b.ymax()));
newPartitions.add(new IntBox(xmid, b.xmax(), b.ymin(), b.ymax()));
}
else {
// Split along y axis
int ymid = (b.ymin() + b.ysize() / 2);
newPartitions.add(new IntBox(b.xmin(), b.xmax(), b.ymin(), ymid - 1));
newPartitions.add(new IntBox(b.xmin(), b.xmax(), ymid, b.ymax()));
}
}
return newPartitions;
}