def get_x_intersection(y, polygon):
    """
    For a given 2D polygon, return a list of x-coordinates which crosses a given y.
    The 2D polygon is assumed closed, but the last point should not be repeated.

    :param float y: a given y coordinate
    :param polygon: a list of points, in the form [[x0,y0], [x1,y1], ...  [xn,yn]]

    :returns: a list of x coordinates.
    """
    intersections = []
    x1 = polygon[0][0]
    y1 = polygon[0][1]
    n = len(polygon)
    for i in range(n + 1):
        x2 = polygon[i % n][0]
        y2 = polygon[i % n][1]
        if y > min(y1, y2):
            if y <= max(y1, y2):
                x = (x2 - x1) / (y2 - y1) * (y - y1) + x1
                intersections.append(x)
        x1 = x2
        y1 = y2
    return intersections
