From 0592564264fff57ccfd9677957196951f9f1c6cf Mon Sep 17 00:00:00 2001 From: RblSb Date: Sun, 26 Jan 2025 23:22:33 +0300 Subject: Video upload feature And you can play video as soon as upload starts! This is pretty useful for thicc ones. Video will be keeped in cache and will comply cache size limit. I'm also implemented system storage check to change cache limit if it's lower than config value, so upload will be blocked if there is lower than 10MiB available on disk. --- src/tools/MathTools.hx | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/tools/MathTools.hx (limited to 'src/tools/MathTools.hx') diff --git a/src/tools/MathTools.hx b/src/tools/MathTools.hx new file mode 100644 index 0000000..087748a --- /dev/null +++ b/src/tools/MathTools.hx @@ -0,0 +1,55 @@ +package tools; + +class MathTools { + public static inline function clamp(v:T, min:T, max:T):T { + return v < min ? min : v > max ? max : v; + } + + public static inline function lerp(ratio:Float, a:Float, b:Float):Float { + return a + ratio * (b - a); + } + + public static inline function sign(v:Float):Int { + if (v == 0) return 0; + return v < 0 ? -1 : 1; + } + + public static inline function abs(v:T):T { + return cast Math.abs(v); + } + + public static inline function pow(v:T, exp:T):T { + return cast Math.pow(v, exp); + } + + public static inline function limitMin(a:T, b:T):T { + return a < b ? b : a; + } + + public static inline function limitMax(a:T, b:T):T { + return a > b ? b : a; + } + + public static inline function wrapAround(v:T, min:T, max:T):T { + if (min == max) return min; + final range = max - min + 1; + return min + (((v - min) % range) + range) % range; + } + + public static function toFixed(v:Float, digits = 2):Float { + if (digits > 8) throw 'digits is $digits, but cannot be bigger than 8 (for value $v)'; + final ratio = Math.pow(10, digits); + return Std.int(v * ratio) / ratio; + } + + public static function toBitString(value:Int):String { + var result = ""; + var mask = 1; + for (i in 0...32) { // 32-bit integer + result = (value & mask != 0 ? "1" : "0") + result; + mask <<= 1; + } + final i = result.indexOf("1"); + return i > 0 ? result.substr(i) : result; + } +} -- cgit v1.2.3