Find Distance between x, y by means of a n-length cycle.

    :param x:
    :param y:
    :param perimeter:

    Example:

        >>> cycle_dist(1, 23, 24) = 2
        >>> cycle_dist(5, 13, 24) = 8
        >>> cycle_dist(0.0, 2.4, 1.0) = 0.4
        >>> cycle_dist(0.0, 2.6, 1.0) = 0.4

    **中文文档**

    假设坐标轴是一个环, 计算两点之间在环上的最短距离。

def cycle_dist(x, y, perimeter):
    """Find Distance between x, y by means of a n-length cycle.

    :param x:
    :param y:
    :param perimeter:

    Example:

        >>> cycle_dist(1, 23, 24) = 2
        >>> cycle_dist(5, 13, 24) = 8
        >>> cycle_dist(0.0, 2.4, 1.0) = 0.4
        >>> cycle_dist(0.0, 2.6, 1.0) = 0.4

    **中文文档**

    假设坐标轴是一个环, 计算两点之间在环上的最短距离。
    """
    dist = abs(x - y) % perimeter
    if dist > 0.5 * perimeter:
        dist = perimeter - dist
    return dist