add matrix_is_invertible

This commit is contained in:
lixianjing 2021-06-29 08:23:47 +08:00
parent 775b4f479f
commit 493376c767
2 changed files with 25 additions and 0 deletions

15
src/tkc/matrix.c Executable file → Normal file
View File

@ -145,3 +145,18 @@ matrix_t* matrix_transform_pointf(matrix_t* m, float x, float y, float* ox, floa
return m;
}
static double matrix_compute_determinant(matrix_t* m) {
double a = m->a0;
double b = m->a1;
double c = m->a2;
double d = m->a3;
return a * d - b * c;
}
bool_t matrix_is_invertible(matrix_t* m) {
double det = matrix_compute_determinant(m);
return TK_ISFINITE(det) && det != 0.;
}

View File

@ -159,6 +159,16 @@ matrix_t* matrix_transform_point(matrix_t* m, xy_t x, xy_t y, xy_t* out_x, xy_t*
*/
matrix_t* matrix_transform_pointf(matrix_t* m, float x, float y, float* ox, float* oy);
/**
* @method matrix_is_invertible
* matrix是否可逆
*
* @param {matrix_t*} m
*
* @return {bool_t} TRUE表示可逆
*/
bool_t matrix_is_invertible(matrix_t* m);
END_C_DECLS
#endif /*TK_MATRIX_H*/