MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / normalize

Method normalize

src/com/cloudream/ishow/util/MathUtils.java:94–109  ·  view source on GitHub ↗

Normalizes a value from [min, max] to [0, 1]

(float val, float min, float max)

Source from the content-addressed store, hash-verified

92 * Normalizes a value from [min, max] to [0, 1]
93 */
94 public static float normalize(float val, float min, float max)
95 {
96 if(min >= max || Float.isNaN(min) || Float.isNaN(max))
97 throw new InvalidParameterException("invalid parameter min and max");
98
99 if(Math.abs(max - min) < 0.01f)
100 return 0.5f;
101
102 if(val <= min)
103 return 0;
104 else if(val >= max)
105 return 1;
106
107 float scale = 1 / (max - min);
108 return (val - min) * scale;
109 }
110
111 public static float distance(float x1, float y1, float x2, float y2)
112 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected