'Returns the distance from the given points, to the boundaries
of a rotated box in pixels.'

def _get_dist_to_box(self, rotation, x0, y0, figure_box):

    if (rotation > 270):
        quad = (rotation - 270)
        h1 = (y0 / math.cos(math.radians(quad)))
        h2 = ((figure_box.x1 - x0) / math.cos(math.radians((90 - quad))))
    elif (rotation > 180):
        quad = (rotation - 180)
        h1 = (x0 / math.cos(math.radians(quad)))
        h2 = (y0 / math.cos(math.radians((90 - quad))))
    elif (rotation > 90):
        quad = (rotation - 90)
        h1 = ((figure_box.y1 - y0) / math.cos(math.radians(quad)))
        h2 = (x0 / math.cos(math.radians((90 - quad))))
    else:
        h1 = ((figure_box.x1 - x0) / math.cos(math.radians(rotation)))
        h2 = ((figure_box.y1 - y0) / math.cos(math.radians((90 - rotation))))
    return min(h1, h2)
