diff --git a/ChangeLog b/ChangeLog index 2e032c434d..8ee1035be4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-03-20 Sven Neumann + + * app/core/gimp-transform-utils.c (gimp_transform_matrix_perspective): + cosmetic changes. + + * libgimpmath/gimpmatrix.[ch] + * libgimpmath/gimpmath.def: added gimp_matrix_is_affine(). + 2005-03-19 Michael Natterer * app/core/gimpimage-sample-points.c diff --git a/app/core/gimp-transform-utils.c b/app/core/gimp-transform-utils.c index fbc706ecce..7c5c746d7c 100644 --- a/app/core/gimp-transform-utils.c +++ b/app/core/gimp-transform-utils.c @@ -232,26 +232,12 @@ gimp_transform_matrix_perspective (gint x, matrix.coeff[1][2] = t_y1; matrix.coeff[2][0] = 0.0; matrix.coeff[2][1] = 0.0; + matrix.coeff[2][2] = 1.0; } else { gdouble det1, det2; - det1 = dx3 * dy2 - dy3 * dx2; - det2 = dx1 * dy2 - dy1 * dx2; - - if (det1 == 0.0 && det2 == 0.0) - matrix.coeff[2][0] = 1.0; - else - matrix.coeff[2][0] = det1 / det2; - - det1 = dx1 * dy3 - dy1 * dx3; - - if (det1 == 0.0 && det2 == 0.0) - matrix.coeff[2][1] = 1.0; - else - matrix.coeff[2][1] = det1 / det2; - matrix.coeff[0][0] = t_x2 - t_x1 + matrix.coeff[2][0] * t_x2; matrix.coeff[0][1] = t_x3 - t_x1 + matrix.coeff[2][1] * t_x3; matrix.coeff[0][2] = t_x1; @@ -259,9 +245,18 @@ gimp_transform_matrix_perspective (gint x, matrix.coeff[1][0] = t_y2 - t_y1 + matrix.coeff[2][0] * t_y2; matrix.coeff[1][1] = t_y3 - t_y1 + matrix.coeff[2][1] * t_y3; matrix.coeff[1][2] = t_y1; - } - matrix.coeff[2][2] = 1.0; + det1 = dx3 * dy2 - dy3 * dx2; + det2 = dx1 * dy2 - dy1 * dx2; + + matrix.coeff[2][0] = (det2 == 0.0) ? 1.0 : det1 / det2; + + det1 = dx1 * dy3 - dy1 * dx3; + + matrix.coeff[2][1] = (det2 == 0.0) ? 1.0 : det1 / det2; + + matrix.coeff[2][2] = 1.0; + } } gimp_matrix3_identity (result); diff --git a/devel-docs/libgimpmath/libgimpmath-sections.txt b/devel-docs/libgimpmath/libgimpmath-sections.txt index d8e37084cc..60f142dfc8 100644 --- a/devel-docs/libgimpmath/libgimpmath-sections.txt +++ b/devel-docs/libgimpmath/libgimpmath-sections.txt @@ -35,8 +35,9 @@ gimp_matrix3_affine gimp_matrix3_transform_point gimp_matrix3_determinant gimp_matrix3_invert -gimp_matrix3_is_diagonal gimp_matrix3_is_identity +gimp_matrix3_is_diagonal +gimp_matrix3_is_affine gimp_matrix3_is_simple gimp_matrix4_to_deg GIMP_TYPE_MATRIX2 diff --git a/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml b/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml index 96c1679275..1a152c193d 100644 --- a/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml +++ b/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml @@ -169,6 +169,15 @@ A four by four matrix. @matrix: + + + + + +@matrix: +@Returns: + + @@ -178,7 +187,7 @@ A four by four matrix. @Returns: - + diff --git a/libgimpmath/gimpmath.def b/libgimpmath/gimpmath.def index bd2a5e6721..1060865895 100644 --- a/libgimpmath/gimpmath.def +++ b/libgimpmath/gimpmath.def @@ -6,6 +6,7 @@ EXPORTS gimp_matrix3_determinant gimp_matrix3_identity gimp_matrix3_invert + gimp_matrix3_is_affine gimp_matrix3_is_diagonal gimp_matrix3_is_identity gimp_matrix3_is_simple diff --git a/libgimpmath/gimpmatrix.c b/libgimpmath/gimpmatrix.c index 177e3d637e..e8c6131733 100644 --- a/libgimpmath/gimpmatrix.c +++ b/libgimpmath/gimpmatrix.c @@ -443,7 +443,6 @@ gimp_matrix3_yshear (GimpMatrix3 *matrix, matrix->coeff[1][2] += amount * matrix->coeff[0][2]; } - /** * gimp_matrix3_affine: * @matrix: The input matrix. @@ -488,7 +487,6 @@ gimp_matrix3_affine (GimpMatrix3 *matrix, gimp_matrix3_mult (&affine, matrix); } - /** * gimp_matrix3_determinant: * @matrix: The input matrix. @@ -567,39 +565,13 @@ gimp_matrix3_invert (GimpMatrix3 *matrix) /* functions to test for matrix properties */ - -/** - * gimp_matrix3_is_diagonal: - * @matrix: The matrix that is to be tested. - * - * Checks if the given matrix is diagonal. - * - * Returns: TRUE if the matrix is diagonal. - */ -gboolean -gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix) -{ - gint i, j; - - for (i = 0; i < 3; i++) - { - for (j = 0; j < 3; j++) - { - if (i != j && fabs (matrix->coeff[i][j]) > EPSILON) - return FALSE; - } - } - - return TRUE; -} - /** * gimp_matrix3_is_identity: * @matrix: The matrix that is to be tested. * * Checks if the given matrix is the identity matrix. * - * Returns: TRUE if the matrix is the identity matrix. + * Returns: %TRUE if the matrix is the identity matrix, %FALSE otherwise */ gboolean gimp_matrix3_is_identity (const GimpMatrix3 *matrix) @@ -626,11 +598,49 @@ gimp_matrix3_is_identity (const GimpMatrix3 *matrix) return TRUE; } -/* Check if we'll need to interpolate when applying this matrix. - This function returns TRUE if all entries of the upper left - 2x2 matrix are either 0 or 1 +/** + * gimp_matrix3_is_diagonal: + * @matrix: The matrix that is to be tested. + * + * Checks if the given matrix is diagonal. + * + * Returns: %TRUE if the matrix is diagonal, %FALSE otherwise */ +gboolean +gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix) +{ + gint i, j; + for (i = 0; i < 3; i++) + { + for (j = 0; j < 3; j++) + { + if (i != j && fabs (matrix->coeff[i][j]) > EPSILON) + return FALSE; + } + } + + return TRUE; +} + +/** + * gimp_matrix3_is_affine: + * @matrix: The matrix that is to be tested. + * + * Checks if the given matrix defines an affine transformation. + * + * Returns: %TRUE if the matrix defines an affine transformation, + * %FALSE otherwise + * + * Since: GIMP 2.4 + */ +gboolean +gimp_matrix3_is_affine (const GimpMatrix3 *matrix) +{ + return (fabs (matrix->coeff[2][0]) < EPSILON && + fabs (matrix->coeff[2][1]) < EPSILON && + fabs (matrix->coeff[2][2] - 1.0) < EPSILON); +} /** * gimp_matrix3_is_simple: @@ -639,8 +649,8 @@ gimp_matrix3_is_identity (const GimpMatrix3 *matrix) * Checks if we'll need to interpolate when applying this matrix as * a transformation. * - * Returns: TRUE if all entries of the upper left 2x2 matrix are either - * 0 or 1 + * Returns: %TRUE if all entries of the upper left 2x2 matrix are + * either 0 or 1, %FALSE otherwise */ gboolean gimp_matrix3_is_simple (const GimpMatrix3 *matrix) diff --git a/libgimpmath/gimpmatrix.h b/libgimpmath/gimpmatrix.h index 7ac4be95bd..e49d7d5190 100644 --- a/libgimpmath/gimpmatrix.h +++ b/libgimpmath/gimpmatrix.h @@ -90,8 +90,9 @@ void gimp_matrix3_affine (GimpMatrix3 *matrix, gdouble gimp_matrix3_determinant (const GimpMatrix3 *matrix); void gimp_matrix3_invert (GimpMatrix3 *matrix); -gboolean gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix); gboolean gimp_matrix3_is_identity (const GimpMatrix3 *matrix); +gboolean gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix); +gboolean gimp_matrix3_is_affine (const GimpMatrix3 *matrix); gboolean gimp_matrix3_is_simple (const GimpMatrix3 *matrix); void gimp_matrix3_transform_point (const GimpMatrix3 *matrix,