浏览代码

Math: Add inverseLerp function.

clenhof 1 年之前
父节点
当前提交
aee52200d5
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      hxd/Math.hx

+ 7 - 0
hxd/Math.hx

@@ -135,6 +135,13 @@ class Math {
 		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.
 	**/