def angle_diff(x, y, period):
    """Get the smallest angle difference between 2 angles: the angle from y to x.

    Parameters
    ----------
    x: float
        To angle.
    y: float
        From angle.
    period: float
        Periodicity in radians for assessing angle difference.

    Returns:
    ----------
    diff: float
        Signed smallest between-angle difference in range (-pi, pi).
    """

    # calculate angle difference, modulo to [0, 2*pi]
    diff = (x - y + period / 2) % period - period / 2
    if diff > np.pi:
        diff = diff - (2 * np.pi)  # shift (pi, 2*pi] to (-pi, 0]

    return diff
Get the smallest angle difference between 2 angles: the angle from y to x.

    Parameters
    ----------
    x: float
        To angle.
    y: float
        From angle.
    period: float
        Periodicity in radians for assessing angle difference.

    Returns:
    ----------
    diff: float
        Signed smallest between-angle difference in range (-pi, pi).
    
tridet/evaluators/kitti_3d_evaluator.py