def interval_pos(test_x, x0, x1):
    """
    In 1D space:

                  x0                  x1
    ##############  ##################  ##############
    # ---- position            0 position          + position

    :param test_x:
    :param x0:
    :param x1:
    :return:
    """
    assert x1 >= x0

    if test_x < x0:
        return test_x - x0
    if test_x > x1:
        return test_x - x1
    return 0.0