def LinearlyScaled(value, maximum, minimum=0.0, offset=0.0):
  """Returns a value scaled linearly between 0 and 1.

  Args:
    value (float): the value to be scaled.
    maximum (float): the maximum value to consider. Must be strictly
      positive and finite (i.e., can't be zero nor infinity).

  Returns:
    A ``float`` between 0 and 1. When the value is 0 we return 1. When
    the value is greater than the maximum, we return 0. With intermediate
    values scaled linearly.
  """
  delta = (maximum - max(minimum, min(maximum, value))) / (maximum - minimum)
  return delta + offset