import math


def __get_pixel_metric_value(dic_pos, img_width, img_height):
    """
    Get the pixel metric value (mm). From the camera to the robot.
    
    Parameters
    ----------
    dic_pos : dict
        Dictionnary of positions.
    img_width : int
        Width size of the image. In pixel.
    img_height : int
        Height size of the image. In pixel.

    Returns
    -------
    pixel_size : float
        The size of a pixel in mm for the robot.
    """
    x1,y1 = dic_pos.get("Top Left")
    x2,y2 = dic_pos.get("Top Right")
    width_metric = math.sqrt((int(x2) - int(x1))**2 + (int(y2) - int(y1))**2) 
    x3,y3 = dic_pos.get("Bottom Left")
    height_metric = math.sqrt((int(x3) - int(x1))**2 + (int(y3) - int(y1))**2) 
    pixel_size = height_metric/img_height
    pixel_size2 = width_metric/img_width
    if pixel_size < pixel_size2-0.01 or pixel_size > pixel_size2+0.01:
        raise ValueError("The positions don't match the image. There's a bad ratio.") #It has to be the same ratio than the camera
    return pixel_size