functions to calculate min and max bounding boxes