def _verify_shape_bounds(shape, bounds):
    """Verify that shape corresponds to bounds apect ratio."""
    if not isinstance(shape, (tuple, list)) or len(shape) != 2:
        raise TypeError(
            "shape must be a tuple or list with two elements: %s" % str(shape)
        )
    if not isinstance(bounds, (tuple, list)) or len(bounds) != 4:
        raise TypeError(
            "bounds must be a tuple or list with four elements: %s" % str(bounds)
        )
    shape = Shape(*shape)
    bounds = Bounds(*bounds)
    shape_ratio = shape.width / shape.height
    bounds_ratio = (bounds.right - bounds.left) / (bounds.top - bounds.bottom)
    if abs(shape_ratio - bounds_ratio) > DELTA:
        min_length = min([
            (bounds.right - bounds.left) / shape.width,
            (bounds.top - bounds.bottom) / shape.height
        ])
        proposed_bounds = Bounds(
            bounds.left,
            bounds.bottom,
            bounds.left + shape.width * min_length,
            bounds.bottom + shape.height * min_length
        )
        raise ValueError(
            "shape ratio (%s) must equal bounds ratio (%s); try %s" % (
                shape_ratio, bounds_ratio, proposed_bounds
            )
        )
def _verify_shape_bounds ( shape , bounds ) : if not isinstance ( shape , ( tuple , list ) ) or len ( shape ) != 2 : raise TypeError ( "shape must be a tuple or list with two elements: %s" % str ( shape ) ) if not isinstance ( bounds , ( tuple , list ) ) or len ( bounds ) != 4 : raise TypeError ( "bounds must be a tuple or list with four elements: %s" % str ( bounds ) ) shape = Shape ( * shape ) bounds = Bounds ( * bounds ) shape_ratio = shape . width / shape . height bounds_ratio = ( bounds . right - bounds . left ) / ( bounds . top - bounds . bottom ) if abs ( shape_ratio - bounds_ratio ) > DELTA : min_length = min ( [ ( bounds . right - bounds . left ) / shape . width , ( bounds . top - bounds . bottom ) / shape . height ] ) proposed_bounds = Bounds ( bounds . left , bounds . bottom , bounds . left + shape . width * min_length , bounds . bottom + shape . height * min_length ) raise ValueError ( "shape ratio (%s) must equal bounds ratio (%s); try %s" % ( shape_ratio , bounds_ratio , proposed_bounds ) )
Verify that shape corresponds to bounds apect ratio.