def _normalize_bbox(self, bbox, size):
bbox_ratio = float(bbox.width) / float(bbox.height)<EOL>size_ratio = float(size[<NUM_LIT:0>]) / float(size[<NUM_LIT:1>])<EOL>if round(size_ratio, <NUM_LIT:4>) == round(bbox_ratio, <NUM_LIT:4>):<EOL><INDENT>return bbox<EOL><DEDENT>else:<EOL><INDENT>if bbox.height * size_ratio >= bbox.width:<EOL><INDENT>diff = bbox.height*size_ratio - bbox.width<EOL>return BBox((bbox.xmin - diff/<NUM_LIT:2>, bbox.ymin, bbox.xmax + diff/<NUM_LIT:2>, bbox.ymax), bbox.projection)<EOL><DEDENT>else:<EOL><INDENT>diff = abs(bbox.width/size_ratio - bbox.height)<EOL>return BBox((bbox.xmin, bbox.ymin - diff/<NUM_LIT:2>, bbox.xmax, bbox.ymax + diff/<NUM_LIT:2>), bbox.projection)<EOL><DEDENT><DEDENT>
Returns this bbox normalized to match the ratio of the given size.