def fit_to(img_width, img_height, target_width, target_height):
    """
    Return new dimensions for img such that it fits completely
    in target_width/target_height
    Actually returns (new_width, new_height, -1) to be compatible with tvtk
    """
    width_factor = target_width / float(img_width)
    height_factor = target_height / float(img_height)
    if width_factor < height_factor:
        return (target_width, width_factor * img_height, -1)
    else:
        return (height_factor * img_width, target_height, -1)