diff --git a/docs/modules/linalg.md b/docs/modules/linalg.md index b7740e05..fc8c7a4c 100644 --- a/docs/modules/linalg.md +++ b/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: ... diff --git a/include/typings/linalg.pyi b/include/typings/linalg.pyi index 5006a663..08353987 100644 --- a/include/typings/linalg.pyi +++ b/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: ... diff --git a/src/linalg.cpp b/src/linalg.cpp index 9b01f888..72b232f2 100644 --- a/src/linalg.cpp +++ b/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()); diff --git a/tests/80_linalg.py b/tests/80_linalg.py index 2d185be0..fdbf3347 100644 --- a/tests/80_linalg.py +++ b/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):