Browse Source

Math: Add inverseLerp function.

clenhof 1 year ago
parent
commit
aee52200d5
1 changed files with 7 additions and 0 deletions
  1. 7 0
      hxd/Math.hx

+ 7 - 0
hxd/Math.hx

@@ -135,6 +135,13 @@ class Math {
 		return a + k * (b - a);
 		return a + k * (b - a);
 	}
 	}
 
 
+	/**
+		Returns a value between 0 and 1, that determines where val lies between a and b.
+	 */
+	 public inline static function inverseLerp(a:Float, b:Float, val:Float) {
+		return (val - a) / (b - a);
+	}
+
 	/**
 	/**
 	 	Similar to linear interpolation (k is between [0,1]), but can be controled with easing parameter. When easing is 0 it's linear.
 	 	Similar to linear interpolation (k is between [0,1]), but can be controled with easing parameter. When easing is 0 it's linear.
 	**/
 	**/