This commit is contained in:
blueloveTH 2023-05-11 21:58:08 +08:00
parent 764c699ce4
commit a7232722ec
2 changed files with 17 additions and 7 deletions

View File

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

View File

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