blueloveTH 2 éve
szülő
commit
b9d29dd4da
4 módosított fájl, 49 hozzáadás és 0 törlés
  1. 19 0
      docs/modules/linalg.md
  2. 4 0
      include/typings/linalg.pyi
  3. 21 0
      src/linalg.cpp
  4. 5 0
      tests/80_linalg.py

+ 19 - 0
docs/modules/linalg.md

@@ -20,7 +20,12 @@ class vec2(_StructLike['vec2']):
     def __init__(self, x: float, y: float) -> None: ...
     def __add__(self, other: vec2) -> vec2: ...
     def __sub__(self, other: vec2) -> vec2: ...
+
+    @overload
     def __mul__(self, other: float) -> vec2: ...
+    @overload
+    def __mul__(self, other: vec2) -> vec2: ...
+
     def __rmul__(self, other: float) -> vec2: ...
     def __truediv__(self, other: float) -> vec2: ...
     def dot(self, other: vec2) -> float: ...
@@ -56,7 +61,12 @@ class vec3(_StructLike['vec3']):
     def __init__(self, x: float, y: float, z: float) -> None: ...
     def __add__(self, other: vec3) -> vec3: ...
     def __sub__(self, other: vec3) -> vec3: ...
+
+    @overload
     def __mul__(self, other: float) -> vec3: ...
+    @overload
+    def __mul__(self, other: vec3) -> vec3: ...
+
     def __rmul__(self, other: float) -> vec3: ...
     def __truediv__(self, other: float) -> vec3: ...
     def dot(self, other: vec3) -> float: ...
@@ -77,7 +87,12 @@ class vec4(_StructLike['vec4']):
     def __init__(self, x: float, y: float, z: float, w: float) -> None: ...
     def __add__(self, other: vec4) -> vec4: ...
     def __sub__(self, other: vec4) -> vec4: ...
+
+    @overload
     def __mul__(self, other: float) -> vec4: ...
+    @overload
+    def __mul__(self, other: vec4) -> vec4: ...
+
     def __rmul__(self, other: float) -> vec4: ...
     def __truediv__(self, other: float) -> vec4: ...
     def dot(self, other: vec4) -> float: ...
@@ -140,7 +155,11 @@ class mat3x3(_StructLike['mat3x3']):
     # affine transformations
     @staticmethod
     def trs(t: vec2, r: float, s: vec2) -> mat3x3: ...
+
     def copy_trs_(self, t: vec2, r: float, s: vec2) -> None: ...
+    def copy_t_(self, t: vec2) -> None: ...
+    def copy_r_(self, r: float) -> None: ...
+    def copy_s_(self, s: vec2) -> None: ...
 
     def _t(self) -> vec2: ...
     def _r(self) -> float: ...

+ 4 - 0
include/typings/linalg.pyi

@@ -143,7 +143,11 @@ class mat3x3(_StructLike['mat3x3']):
     # affine transformations
     @staticmethod
     def trs(t: vec2, r: float, s: vec2) -> mat3x3: ...
+
     def copy_trs_(self, t: vec2, r: float, s: vec2) -> None: ...
+    def copy_t_(self, t: vec2) -> None: ...
+    def copy_r_(self, r: float) -> None: ...
+    def copy_s_(self, s: vec2) -> None: ...
 
     def _t(self) -> vec2: ...
     def _r(self) -> float: ...

+ 21 - 0
src/linalg.cpp

@@ -456,6 +456,27 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
             return vm->None;
         });
 
+        vm->bind(type, "copy_t_(self, t: vec2)", [](VM* vm, ArgsView args){
+            PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
+            Vec2 t = CAST(Vec2, args[1]);
+            self = Mat3x3::trs(t, self._r(), self._s());
+            return vm->None;
+        });
+
+        vm->bind(type, "copy_r_(self, r: float)", [](VM* vm, ArgsView args){
+            PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
+            f64 r = CAST_F(args[1]);
+            self = Mat3x3::trs(self._t(), r, self._s());
+            return vm->None;
+        });
+
+        vm->bind(type, "copy_s_(self, s: vec2)", [](VM* vm, ArgsView args){
+            PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
+            Vec2 s = CAST(Vec2, args[1]);
+            self = Mat3x3::trs(self._t(), self._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());

+ 5 - 0
tests/80_linalg.py

@@ -392,6 +392,11 @@ assert mat_to_str_list(mat3x3.trs(test_vec2_copy, radian, test_vec2_2_copy)) ==
 a = mat3x3.zeros()
 a.copy_trs_(test_vec2_copy, radian, test_vec2_2_copy)
 assert a == mat3x3.trs(test_vec2_copy, radian, test_vec2_2_copy)
+b = mat3x3.identity()
+b.copy_t_(test_vec2_copy)
+b.copy_r_(radian)
+b.copy_s_(test_vec2_2_copy)
+assert a == b
 
 # test is_affine
 def mat_is_affine(mat_list):