import logging


def cartesian_goals(x, y):
    """
    Use a cartesian coordinate system to calculate goals from given X and Y
    values.

    :param x: x cartesian coordinate
    :param y: y cartesian coordinate
    :return: cartesian derived base, fibia, and tibia servo goal values
    """
    # Convert 2D X and Y into usable numbers
    two_d_y_as_float = float(y)
    two_d_y_as_percent = float(two_d_y_as_float / 100)
    two_d_x_as_float = float(x)
    two_d_x_as_percent = float(two_d_x_as_float / 100)
    # Base maths
    # A - Turn X into a percent
    # B - Multiply X against the total travel of ThreeD_Base
    # C - Take the MAX of ThreeD_Base + B
    three_d_base_max = 780  # Then pad it some (740 + another say 40)
    three_d_base_min = 328  # Then pad it some (288 - another say 40)
    three_d_base_travel = three_d_base_max - three_d_base_min
    bg = int(
        three_d_base_max - (three_d_base_travel * two_d_x_as_percent)) - 60
    logging.info("[cartesian_goals] Base goal position is:{0}".format(bg))
    # Femur maths
    # A - Turn Y into a percent
    # B - Multiply Y against the total travel of ThreeD_Base
    # C - Take the MAX of ThreeD_Elbow - B
    three_d_femur_max = 451  # Then pad it some (550 + another say 40)
    three_d_femur_min = 363  # Then pad it some (420 - another say 40)
    three_d_femur_travel = three_d_femur_max - three_d_femur_min
    fg = int(
        three_d_femur_max - (three_d_femur_travel * two_d_y_as_percent))
    logging.info("[cartesian_goals] Femur goal position is:{0}".format(fg))
    # Tibia maths
    # A - Turn X into a percent
    # B - Multiply X against the total travel of threeD_femur
    # C - Take the MAX of threeD_Elbow + B
    three_d_tibia_max = 420  # Then pad it some (370 + another say 40)
    three_d_tibia_min = 150  # Then pad it some (135 - another say 40)
    three_d_tibia_travel = three_d_tibia_max - three_d_tibia_min
    tg = int(
        three_d_tibia_min + (three_d_tibia_travel * two_d_y_as_percent))
    logging.info("[cartesian_goals] Tibia goal position is:{0}".format(tg))
    return bg, fg, tg