Class RangeUtil

java.lang.Object
com.diozero.util.RangeUtil

public class RangeUtil
extends Object
  • Constructor Summary

    Constructors
    Constructor Description
    RangeUtil()  
  • Method Summary

    Modifier and Type Method Description
    static double constrain​(double value, double min, double max)  
    static float constrain​(float value, float min, float max)  
    static int constrain​(int value, int min, int max)  
    static double map​(double value, double fromLow, double fromHigh, double toLow, double toHigh)
    Map a number from one range to another.
    static double map​(double value, double fromLow, double fromHigh, double toLow, double toHigh, boolean constrain)  
    static float map​(float value, float fromLow, float fromHigh, float toLow, float toHigh)
    Map a number from one range to another.
    static float map​(float value, float fromLow, float fromHigh, float toLow, float toHigh, boolean constrain)
    Map a number from one range to another.
    static int map​(float value, float fromLow, float fromHigh, int toLow, int toHigh)
    Map a number from one range to another.
    static int map​(float value, float fromLow, float fromHigh, int toLow, int toHigh, boolean constrain)
    Map a number from one range to another.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RangeUtil

      public RangeUtil()
  • Method Details

    • constrain

      public static int constrain​(int value, int min, int max)
    • constrain

      public static float constrain​(float value, float min, float max)
    • constrain

      public static double constrain​(double value, double min, double max)
    • map

      public static int map​(float value, float fromLow, float fromHigh, int toLow, int toHigh)
      Map a number from one range to another. Based on Arduino's map(). Example: RangeUtil.map(500, 0, 1000, 0, 255);
      Parameters:
      value - value to map
      fromLow - low end of originating range
      fromHigh - high end of originating range
      toLow - low end of target range
      toHigh - high end of target range
      Returns:
      mapped value
    • map

      public static int map​(float value, float fromLow, float fromHigh, int toLow, int toHigh, boolean constrain)
      Map a number from one range to another. Based on Arduino's map(). Example: RangeUtil.map(500, 0, 1000, 0, 255, true);
      Parameters:
      value - value to map
      fromLow - low end of originating range
      fromHigh - high end of originating range
      toLow - low end of target range
      toHigh - high end of target range
      constrain - whether to constrain the returned value to the speceified range
      Returns:
      mapped value
    • map

      public static float map​(float value, float fromLow, float fromHigh, float toLow, float toHigh)
      Map a number from one range to another. Based on Arduino's map(). Example: RangeUtil.map(500, 0, 1000, 0, 255);
      Parameters:
      value - value to map
      fromLow - low end of originating range
      fromHigh - high end of originating range
      toLow - low end of target range
      toHigh - high end of target range
      Returns:
      mapped value
    • map

      public static float map​(float value, float fromLow, float fromHigh, float toLow, float toHigh, boolean constrain)
      Map a number from one range to another. Based on Arduino's map(). Example: RangeUtil.map(500, 0, 1000, 0, 255);
      Parameters:
      value - value to map
      fromLow - low end of originating range
      fromHigh - high end of originating range
      toLow - low end of target range
      toHigh - high end of target range
      constrain - whether to constrain the returned value to the speceified range
      Returns:
      mapped value
    • map

      public static double map​(double value, double fromLow, double fromHigh, double toLow, double toHigh)
      Map a number from one range to another. Based on Arduino's map(). Example: RangeUtil.map(500, 0, 1000, 0, 255);
      Parameters:
      value - value to map
      fromLow - low end of originating range
      fromHigh - high end of originating range
      toLow - low end of target range
      toHigh - high end of target range
      Returns:
      mapped value
    • map

      public static double map​(double value, double fromLow, double fromHigh, double toLow, double toHigh, boolean constrain)