1<?php 2 3 4namespace ComboStrap; 5 6 7class Math 8{ 9 10 11 /** 12 * Linear interpolation 13 * @param $x 14 * @param $y 15 * @param $weight 16 * @return float 17 */ 18 public static function unlerp($x, $y, $weight): float 19 { 20 $x2 = ($weight / 100) * $x; 21 return ($y - $x2) / (1 - $weight / 100); 22 } 23 24 /** 25 * Linear interpolation back if x and weight are the same 26 * @param $x 27 * @param $y 28 * @param $weight 29 * @return float|int 30 */ 31 public static function lerp($x, $y, $weight) 32 { 33 34 $X = ($weight / 100) * $x; 35 $Y = (1 - $weight / 100) * $y; 36 return $X + $Y; 37 38 } 39} 40