More generic bounding box calculation