def linear_threshold_reward(distance, threshold, coefficient):
    """
    Linear reward with respect to distance, cut of at threshold.
    :param distance: current distance to the goal
    :param threshold: maximum distance at which some bonus is given
    :param coefficient: NEGATIVE --> slope of the linear bonus
    """
    assert distance >= 0 and threshold > 0 and coefficient < 0
    constant = -threshold * coefficient
    return max(distance * coefficient + constant, 0)