def compute_scale_coef(ai_extremum, ai_canvas_size):
    """ compute the four scale coefficient to apply to the outlines to make it fit into a canvas
  """
    min_x, min_y, max_x, max_y = ai_extremum
    canvas_width, canvas_height, margin_x, margin_y = ai_canvas_size
    r_scale_coef = 1, 0, 1, 0
    if max_x - min_x > 0 and max_y - min_y > 0:
        lx = (canvas_width - 2 * margin_x) / float(max_x - min_x)
        ly = (canvas_height - 2 * margin_y) / float(max_y - min_y)
        lxy = min(lx, ly)
        lx = 1 * lxy
        ly = -1 * lxy
        kx = (canvas_width - (max_x - min_x) * lx) / 2 - min_x * lx
        ky = (canvas_height - (max_y - min_y) * abs(ly)) / 2 - max_y * ly
        r_scale_coef = lx, kx, ly, ky
    return r_scale_coef
