This commit is contained in:
blueloveTH 2024-01-14 17:25:11 +08:00
parent 46eadebfc0
commit bb55200ea2
4 changed files with 18 additions and 4 deletions

View File

@ -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*)>;

View File

@ -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: ...

View File

@ -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());

View File

@ -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):