blueloveTH преди 2 години
родител
ревизия
bb55200ea2
променени са 4 файла, в които са добавени 18 реда и са изтрити 4 реда
  1. 2 2
      include/pocketpy/common.h
  2. 2 0
      include/typings/linalg.pyi
  3. 11 2
      src/linalg.cpp
  4. 3 0
      tests/80_linalg.py

+ 2 - 2
include/pocketpy/common.h

@@ -76,7 +76,7 @@ struct NumberTraits<4> {
 
 	static constexpr int_t kMaxSmallInt = (1 << 28) - 1;
 	static constexpr int_t kMinSmallInt = - (1 << 28);
-	static constexpr float_t kEpsilon = 1e-4;
+	static constexpr float_t kEpsilon = (float_t)1e-4;
 };
 
 template <>
@@ -86,7 +86,7 @@ struct NumberTraits<8> {
 
 	static constexpr int_t kMaxSmallInt = (1ll << 60) - 1;
 	static constexpr int_t kMinSmallInt = - (1ll << 60);
-	static constexpr float_t kEpsilon = 1e-8;
+	static constexpr float_t kEpsilon = (float_t)1e-8;
 };
 
 using Number = NumberTraits<sizeof(void*)>;

+ 2 - 0
include/typings/linalg.pyi

@@ -118,6 +118,8 @@ class mat3x3(_StructLike['mat3x3']):
     # affine transformations
     @staticmethod
     def trs(t: vec2, r: float, s: vec2) -> mat3x3: ...
+    
+    def set_trs(self, t: vec2, r: float, s: vec2) -> None: ...
 
     def is_affine(self) -> bool: ...
 

+ 11 - 2
src/linalg.cpp

@@ -453,12 +453,21 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
         /*************** affine transformations ***************/
         // @staticmethod
         vm->bind(type, "trs(t: vec2, r: float, s: vec2)", [](VM* vm, ArgsView args){
-            PyVec2& t = CAST(PyVec2&, args[0]);
+            Vec2 t = CAST(Vec2, args[0]);
             f64 r = CAST_F(args[1]);
-            PyVec2& s = CAST(PyVec2&, args[2]);
+            Vec2 s = CAST(Vec2, args[2]);
             return VAR_T(PyMat3x3, Mat3x3::trs(t, r, s));
         }, {}, BindType::STATICMETHOD);
 
+        vm->bind(type, "set_trs(self, t: vec2, r: float, s: vec2)", [](VM* vm, ArgsView args){
+            PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
+            Vec2 t = CAST(Vec2, args[1]);
+            f64 r = CAST_F(args[2]);
+            Vec2 s = CAST(Vec2, args[3]);
+            self = Mat3x3::trs(t, r, s);
+            return vm->None;
+        });
+
         vm->bind_method<0>(type, "is_affine", [](VM* vm, ArgsView args){
             PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
             return VAR(self.is_affine());

+ 3 - 0
tests/80_linalg.py

@@ -424,6 +424,9 @@ radian = random.uniform(-10*math.pi, 10*math.pi)
 
 assert mat_to_str_list(mat3x3.trs(test_vec2_copy, radian, test_vec2_2_copy)) == mat_list_to_str_list(trs(test_vec2_list, radian, test_vec2_2_list))
 
+a = mat3x3.zeros()
+a.set_trs(test_vec2_copy, radian, test_vec2_2_copy)
+assert a == mat3x3.trs(test_vec2_copy, radian, test_vec2_2_copy)
 
 # test is_affine
 def mat_is_affine(mat_list):