def calc_y_cross(p1, p2, y):
    """Given two points of a same line and a y coordinate, calculate x coordinate.

    :param p1: the first point of the line.
    :type p1: Point
    :param p2: the second point of the line.
    :type p2: Point
    :param y: the y coordinate
    :type: float
    :return: x coordinate
    :rtype: float
    """
    if abs(p1.y - p2.y) < 1e-6:
        return -1
    k = (p1.x - p2.x) / (p1.y - p2.y)
    b = p1.x - k * p1.y
    return k * y + b