From a7232722ecb9113b4a31268eb8a4d16701e1f90f Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 11 May 2023 21:58:08 +0800 Subject: [PATCH] ... --- src/mat3x3.h | 22 +++++++++++++++------- src/mat3x3.pyi | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/mat3x3.h b/src/mat3x3.h index 1836147c..9894907f 100644 --- a/src/mat3x3.h +++ b/src/mat3x3.h @@ -172,13 +172,7 @@ struct Mat3x3{ return true; } - /*************** affine transform ***************/ - bool is_affine() const{ - float det = _11 * _22 - _12 * _21; - if(fabsf(det) < kEpsilon) return false; - return _31 == 0.0f && _32 == 0.0f && _33 == 1.0f; - } - + /*************** affine transformations ***************/ static Mat3x3 translate(Vec2 v){ return Mat3x3(1.0f, 0.0f, v.x, 0.0f, 1.0f, v.y, @@ -213,6 +207,12 @@ struct Mat3x3{ 0.0f, 0.0f, 1.0f); } + bool is_affine() const{ + float det = _11 * _22 - _12 * _21; + if(fabsf(det) < kEpsilon) return false; + return _31 == 0.0f && _32 == 0.0f && _33 == 1.0f; + } + Mat3x3 inverse_affine() const{ Mat3x3 ret; float det = _11 * _22 - _12 * _21; @@ -593,6 +593,14 @@ struct PyMat3x3: Mat3x3{ return VAR_T(PyMat3x3, Mat3x3::trs(t, r, s)); }); + vm->bind_func<4>(type, "ortho", [](VM* vm, ArgsView args){ + f64 left = vm->num_to_float(args[0]); + f64 right = vm->num_to_float(args[1]); + f64 bottom = vm->num_to_float(args[2]); + f64 top = vm->num_to_float(args[3]); + return VAR_T(PyMat3x3, Mat3x3::ortho(left, right, bottom, top)); + }); + 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/src/mat3x3.pyi b/src/mat3x3.pyi index 2260c496..53879114 100644 --- a/src/mat3x3.pyi +++ b/src/mat3x3.pyi @@ -58,6 +58,8 @@ class mat3x3: def ones() -> mat3x3: ... @staticmethod def identity() -> mat3x3: ... + @staticmethod + def ortho(left: float, right: float, bottom: float, top: float) -> mat3x3: ... # affine transformations @staticmethod