mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2025-12-25 06:00:10 +01:00
[matrix] Optimise invert for simple scaling|translation matrices.
The matrix is quite often just a simple scale and translate (or even identity!). For this class of matrix, we can skip the full adjoint rearrangement and determinant calculation and just compute the inverse directly.
This commit is contained in:
parent
74876b00cd
commit
0d0c6a199c
1 changed files with 25 additions and 1 deletions
|
|
@ -525,9 +525,33 @@ _cairo_matrix_compute_adjoint (cairo_matrix_t *matrix)
|
|||
cairo_status_t
|
||||
cairo_matrix_invert (cairo_matrix_t *matrix)
|
||||
{
|
||||
/* inv (A) = 1/det (A) * adj (A) */
|
||||
double det;
|
||||
|
||||
/* Simple scaling|translation matrices are quite common... */
|
||||
if (matrix->xy == 0. && matrix->yx == 0.) {
|
||||
matrix->x0 = -matrix->x0;
|
||||
matrix->y0 = -matrix->y0;
|
||||
|
||||
if (matrix->xx != 1.) {
|
||||
if (matrix->xx == 0.)
|
||||
return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
|
||||
|
||||
matrix->xx = 1. / matrix->xx;
|
||||
matrix->x0 *= matrix->xx;
|
||||
}
|
||||
|
||||
if (matrix->yy != 1.) {
|
||||
if (matrix->yy == 0.)
|
||||
return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
|
||||
|
||||
matrix->yy = 1. / matrix->yy;
|
||||
matrix->y0 *= matrix->yy;
|
||||
}
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* inv (A) = 1/det (A) * adj (A) */
|
||||
det = _cairo_matrix_compute_determinant (matrix);
|
||||
|
||||
if (! ISFINITE (det))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue