import math


def _rotate(point, angle, origin = (0,0),unit = 'degree'):
    """Rotate a point counterclockwise by a given angle around a given origin.

    Angle can be both in radian or degree. Helper function for rotating a layout.

    Parameters
    ----------
    point : tuple 
        position in (x,y) form
    angle : float
        angle to rotate the point
    origin : tuple in (x,y) form
        point will rotate with respect to the origin.
    unit : 'degree'/'radian' to indicate if the angle is in degrees or radians. 
        if given in degrees angle is converted to radians.


    Returns
    -------
    tuple
        rotated point as (x,y) tuple.
    """
    ox, oy = origin
    px, py = point
    if unit == 'degree':
        angle = math.radians(angle)
    if unit == 'radian':
        angle = angle
    qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy)
    qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)
    return qx, qy