From bb55200ea28e30923a75c53e3196a9c65c176dc4 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 14 Jan 2024 17:25:11 +0800 Subject: [PATCH] ... --- include/pocketpy/common.h | 4 ++-- include/typings/linalg.pyi | 2 ++ src/linalg.cpp | 13 +++++++++++-- tests/80_linalg.py | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/pocketpy/common.h b/include/pocketpy/common.h index a69ffd4a..80bf4816 100644 --- a/include/pocketpy/common.h +++ b/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; diff --git a/include/typings/linalg.pyi b/include/typings/linalg.pyi index a8504c98..83d4618a 100644 --- a/include/typings/linalg.pyi +++ b/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: ... diff --git a/src/linalg.cpp b/src/linalg.cpp index 366f08f6..7e262624 100644 --- a/src/linalg.cpp +++ b/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()); diff --git a/tests/80_linalg.py b/tests/80_linalg.py index eadcc114..e3c5aec9 100644 --- a/tests/80_linalg.py +++ b/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):