2023-10-26 09:46:22 +00:00
|
|
|
package funkin.util.tools;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utilities for performing common math operations.
|
|
|
|
*/
|
|
|
|
class FloatTools
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constrain a float between a minimum and maximum value.
|
|
|
|
*/
|
|
|
|
public static function clamp(value:Float, min:Float, max:Float):Float
|
|
|
|
{
|
|
|
|
return Math.max(min, Math.min(max, value));
|
|
|
|
}
|
2024-03-03 04:49:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Round a float to a certain number of decimal places.
|
|
|
|
**/
|
|
|
|
public static function round(number:Float, ?precision = 2):Float
|
|
|
|
{
|
|
|
|
number *= Math.pow(10, precision);
|
|
|
|
return Math.round(number) / Math.pow(10, precision);
|
|
|
|
}
|
2023-10-26 09:46:22 +00:00
|
|
|
}
|