import numpy as np

def coord(contours, x_offset, y_offset, x_scale, y_scale):
    new_contours = []
    for i in range(len(contours)):
        for j in range(len(contours[i])):
            x = contours[i][j][0][0]*x_scale + x_offset
            y = contours[i][j][0][1]*y_scale + y_offset
            new_contours.append([x, y])
    return new_contours

def scale_calculator(contours, size):
    x_max = contours[0][0][0][0]
    x_min = contours[0][0][0][0]
    y_max = contours[0][0][0][1]
    y_min = contours[0][0][0][1]

    for i in range(len(contours)):
        for j in range(len(contours[i])):
            x = contours[i][j][0][0]
            y = contours[i][j][0][1]
            if x_min > x:
                x_min = x
            if x > x_max:
                x_max = x
            if y_min > y:
                y_min = y
            if y > y_max:
                y_max = y
    # print([[x_min, x_max], [y_min, y_max]])            #display max and min in x and y

    x_scale = 1.0
    y_scale = 1.0
    if size[0] != 0:
        x_scale = size[0]/(x_max - x_min)
    if size[1] != 0:
        y_scale = size[1]/(y_max - y_min)
    if size[0] == 0:
        x_scale = y_scale
    if size[1] == 0:
        y_scale = x_scale

    x_min = x_min*x_scale
    y_min = y_min*y_scale

    return [x_min, y_min, x_scale, y_scale]


def get_size(coords):
    x_max = coords[0][0]
    x_min = coords[0][0]
    y_max = coords[0][1]
    y_min = coords[0][1]

    for i in range(len(coords)):
        x = coords[i][0]
        y = coords[i][1]
        if x_min > x:
            x_min = x
        if x > x_max:
            x_max = x
        if y_min > y:
            y_min = y
        if y > y_max:
            y_max = y

    return [[x_min, x_max], [y_min, y_max]]         #display max and min in x and y