import math


def rotate(origin, point, angle, invert_y=True):
    """
    Rotate a point counterclockwise by a given angle around a given origin.

    The angle should be given in degrees.
    modified for origin at top left (increasing y proceeding downward)
    """
    angle = angle * math.pi / 180.
    ox, oy = origin
    px, py = point
    if px is -1 and py is -1:
        return px, py

    ox = float(ox)
    oy = float(oy)

    if invert_y:
        # flip y axis
        oy = -oy
        py = -py

    s = math.sin(angle)
    c = math.cos(angle)

    # translate point back to origin:
    px -= ox
    py -= oy

    # rotate point
    xnew = px * c - py * s
    ynew = px * s + py * c

    # translate point back:
    qx = xnew + ox
    qy = ynew + oy
    if invert_y:
        qy = -qy
    return qx, qy