Flood-fill to calculate bounding boxes