Package toxi.math

Class ScaleMap

java.lang.Object
toxi.math.ScaleMap

public class ScaleMap extends Object
This class maps values from one interval into another. By default the mapping is using linear projection, but can be changed by using alternative InterpolateStrategy implementations to achieve a non-regular mapping.
  • Constructor Details

    • ScaleMap

      public ScaleMap(double minIn, double maxIn, double minOut, double maxOut)
      Creates a new instance to map values between the 2 number ranges specified. By default linear projection is used.
      Parameters:
      minIn -
      maxIn -
      minOut -
      maxOut -
  • Method Details

    • getClippedValueFor

      public double getClippedValueFor(double val)
      Computes mapped value in the target interval and ensures the input value is clipped to source interval.
      Parameters:
      val -
      Returns:
      mapped value
    • getInputMedian

      public double getInputMedian()
      Returns:
      the middle value of the input range.
    • getInputRange

      public DoubleRange getInputRange()
      Returns:
      the in
    • getMappedMedian

      public double getMappedMedian()
      Returns:
      the mapped middle value of the output range. Depending on the mapping function used, this value might be different to the one returned by getOutputMedian().
    • getMappedValueFor

      public double getMappedValueFor(double val)
      Computes mapped value in the target interval. Does check if input value is outside the input range.
      Parameters:
      val -
      Returns:
      mapped value
    • getOutputMedian

      public double getOutputMedian()
      Returns:
      the middle value of the output range
    • getOutputRange

      public DoubleRange getOutputRange()
      Returns:
      the output range
    • setInputRange

      public void setInputRange(double min, double max)
      Sets new minimum & maximum values for the input range
      Parameters:
      min -
      max -
    • setMapFunction

      public void setMapFunction(InterpolateStrategy func)
      Overrides the mapping function used for the scale conversion. By default a linear mapping is used: LinearInterpolation.
      Parameters:
      func - interpolate strategy implementation
    • setOutputRange

      public void setOutputRange(double min, double max)
      Sets new minimum & maximum values for the output/target range
      Parameters:
      min - new min output value
      max - new max output value