Package com.diozero.util
Class RangeUtil
- java.lang.Object
-
- com.diozero.util.RangeUtil
-
public class RangeUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description RangeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods 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.
-
-
-
Method Detail
-
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 mapfromLow
- low end of originating rangefromHigh
- high end of originating rangetoLow
- low end of target rangetoHigh
- 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 mapfromLow
- low end of originating rangefromHigh
- high end of originating rangetoLow
- low end of target rangetoHigh
- high end of target rangeconstrain
- 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 mapfromLow
- low end of originating rangefromHigh
- high end of originating rangetoLow
- low end of target rangetoHigh
- 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 mapfromLow
- low end of originating rangefromHigh
- high end of originating rangetoLow
- low end of target rangetoHigh
- high end of target rangeconstrain
- 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 mapfromLow
- low end of originating rangefromHigh
- high end of originating rangetoLow
- low end of target rangetoHigh
- 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)
-
-