def _s_dist(circ_val1: float, circ_val2: float, r: float) -> float:
    """
    Returns the length of the directed walk from circ_val1 to circ_val2, with the lowest
    value length as distance. based on
    https://www.codeproject.com/Articles/190833/Circular-Values-Math-and-Statistics-with-Cplusplus

    :param circ_val1: the starting circular value.
    :param circ_val2: the ending circular value.
    :param r: max angle.
    :return: the directed walk.
    """
    distance = circ_val2 - circ_val1
    if distance < -r / 2:
        return distance + r
    if distance >= r / 2:
        return distance - r
    return distance