aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/MathTools.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2025-01-26 23:22:33 +0300
committerRblSb <msrblsb@gmail.com>2025-01-28 15:46:30 +0300
commit0592564264fff57ccfd9677957196951f9f1c6cf (patch)
treec360c2e5d45d9ac8706f836b0466b88221e1f10d /src/tools/MathTools.hx
parentc7518e58788c17ad2ca8340ab5c7633489aa9518 (diff)
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.
Diffstat (limited to 'src/tools/MathTools.hx')
-rw-r--r--src/tools/MathTools.hx55
1 files changed, 55 insertions, 0 deletions
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<T:Float>(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<T:Float>(v:T):T {
+ return cast Math.abs(v);
+ }
+
+ public static inline function pow<T:Float>(v:T, exp:T):T {
+ return cast Math.pow(v, exp);
+ }
+
+ public static inline function limitMin<T:Float>(a:T, b:T):T {
+ return a < b ? b : a;
+ }
+
+ public static inline function limitMax<T:Float>(a:T, b:T):T {
+ return a > b ? b : a;
+ }
+
+ public static inline function wrapAround<T:Float>(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;
+ }
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage