瀏覽代碼

Isolate std.Math usage into hxd.Math abstraction

borisrp 1 月之前
父節點
當前提交
b597bfe5e8
共有 4 個文件被更改,包括 30 次插入6 次删除
  1. 2 2
      h3d/Quat.hx
  2. 25 1
      hxd/Math.hx
  3. 1 1
      hxd/fmt/fbx/BaseLibrary.hx
  4. 2 2
      hxd/fs/FileConverter.hx

+ 2 - 2
h3d/Quat.hx

@@ -265,7 +265,7 @@ class Quat {
 		// ln()
 		var r = Math.sqrt(x*x+y*y+z*z);
 		var t = r > Math.EPSILON ? Math.atan2(r,w)/r : 0;
-		w = 0.5 * std.Math.log(w*w+x*x+y*y+z*z);
+		w = 0.5 * hxd.Math.log(w*w+x*x+y*y+z*z);
 		x *= t;
 		y *= t;
 		z *= t;
@@ -276,7 +276,7 @@ class Quat {
 		w *= v;
 		// exp
 		var r = Math.sqrt(x*x+y*y+z*z);
-		var et = std.Math.exp(w);
+		var et = hxd.Math.exp(w);
 		var s = r > Math.EPSILON ? et *Math.sin(r)/r : 0;
 		w = et * Math.cos(r);
 		x *= s;

+ 25 - 1
hxd/Math.hx

@@ -26,6 +26,10 @@ class Math {
 		return std.Math.isNaN(v);
 	}
 
+	public static inline function isFinite(v:Float) {
+		return std.Math.isFinite(v);
+	}
+
 	// round to 4 significant digits, eliminates < 1e-10
 	public static function fmt( v : Float ) {
 		var neg;
@@ -36,7 +40,7 @@ class Math {
 			neg = 1.0;
 		if( std.Math.isNaN(v) || !std.Math.isFinite(v) )
 			return v;
-		var digits = Std.int(4 - logBase(v, 10));
+		var digits = Std.int(4 - log10(v));
 		if( digits < 1 )
 			digits = 1;
 		else if( digits >= 10 )
@@ -45,10 +49,22 @@ class Math {
 		return std.Math.ffloor(v * exp + .49999) * neg / exp;
 	}
 
+	public static inline function exp( f : Float ) {
+		return std.Math.exp(f);
+	}
+
 	public static inline function log( f : Float ) {
 		return std.Math.log(f);
 	}
 
+	public static inline function log2( f : Float ) {
+		return logBase(f, 2.0);
+	}
+
+	public static inline function log10( f : Float ) {
+		return logBase(f, 10.0);
+	}
+
 	public static inline function logBase( f : Float, base : Float ) {
 		return log(f) / log(base);
 	}
@@ -57,6 +73,10 @@ class Math {
 		return std.Math.floor(f);
 	}
 
+	public static inline function ffloor( f : Float ) {
+		return std.Math.ffloor(f);
+	}
+
 	public static inline function ceil( f : Float ) {
 		return std.Math.ceil(f);
 	}
@@ -65,6 +85,10 @@ class Math {
 		return std.Math.round(f);
 	}
 
+	public static inline function fround( f : Float ) {
+		return std.Math.fround(f);
+	}
+
 	public static inline function clamp( f : Float, min = 0., max = 1. ) {
 		return f < min ? min : f > max ? max : f;
 	}

+ 1 - 1
hxd/fmt/fbx/BaseLibrary.hx

@@ -1402,7 +1402,7 @@ class BaseLibrary {
 
 	function round(v:Float) {
 		if( v != v ) throw '${fileName} : NaN found (could be multiple skin mesh, currently not supported)';
-		return highPrecision ? v : std.Math.fround(v * 131072) / 131072;
+		return highPrecision ? v : hxd.Math.fround(v * 131072) / 131072;
 	}
 
 	function updateDefaultMatrix( model : FbxNode, d : DefaultMatrixes ) {

+ 2 - 2
hxd/fs/FileConverter.hx

@@ -321,9 +321,9 @@ class FileConverter {
 		if( !sys.FileSystem.exists(fullPath) ) throw "Missing "+fullPath;
 
 		var fileTime = getFileTime(fullPath);
-		var time = std.Math.floor(fileTime / FILE_TIME_PRECISION);
+		var time = hxd.Math.floor(fileTime / FILE_TIME_PRECISION);
 		#if js
-		var milliseconds = std.Math.floor(fileTime) - time * FILE_TIME_PRECISION;
+		var milliseconds = hxd.Math.floor(fileTime) - time * FILE_TIME_PRECISION;
 		#else
 		var milliseconds = null;
 		#end