def square_to_quad(xy, base_pts):
    """Transforms a square in [0,1]^2 to a (possibly skew) quadrilateral
    defined by base_pts.

    Args:
        xy: Array, shape [..., 2]. The 2d coordinates of the point.
        base_pts: Array, shape [4, ...]. The coordinates of the quadrilateral.
            Should be in counterclockwise order to maintain orientation.
    Returns:
        Coordinates in whatever space base_pts was defined in.

    >>> square_to_quad(_TEST_XY[:, np.newaxis], _TEST_SKEW_Q)
    array([[ 0.70710678,  0.        ,  0.70710678],
           [ 0.        ,  0.70710678,  0.70710678],
           [-0.70710678,  0.        ,  0.70710678],
           [ 0.        , -1.        ,  0.        ],
           [ 0.35355339,  0.35355339,  0.70710678],
           [ 0.        , -0.0732233 ,  0.53033009],
           [-0.35355339, -0.5       ,  0.35355339],
           [ 0.49497475,  0.21213203,  0.70710678],
           [ 0.14142136, -0.24393398,  0.45961941],
           [-0.21213203, -0.7       ,  0.21213203]])

    """
    a, b, c, d = base_pts[0], base_pts[1], base_pts[2], base_pts[3]
    x, y = xy[..., 0], xy[..., 1]
    return a + (b-a)*x + (d-a)*y + (a-b+c-d)*x*y