mirror of https://github.com/GNOME/gimp.git
libgimpmath: add various GimpMatrix2 functions
Add gimp_matrix2_{determinant,invert,transform_point}().
This commit is contained in:
parent
c0552de62b
commit
edfc837e7d
|
@ -20,6 +20,9 @@ GimpMatrix3
|
||||||
GimpMatrix4
|
GimpMatrix4
|
||||||
gimp_matrix2_identity
|
gimp_matrix2_identity
|
||||||
gimp_matrix2_mult
|
gimp_matrix2_mult
|
||||||
|
gimp_matrix2_determinant
|
||||||
|
gimp_matrix2_invert
|
||||||
|
gimp_matrix2_transform_point
|
||||||
gimp_matrix3_identity
|
gimp_matrix3_identity
|
||||||
gimp_matrix3_mult
|
gimp_matrix3_mult
|
||||||
gimp_matrix3_translate
|
gimp_matrix3_translate
|
||||||
|
|
|
@ -244,6 +244,66 @@ gimp_matrix2_mult (const GimpMatrix2 *matrix1,
|
||||||
*matrix2 = tmp;
|
*matrix2 = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix2_determinant:
|
||||||
|
* @matrix: The input matrix.
|
||||||
|
*
|
||||||
|
* Calculates the determinant of the given matrix.
|
||||||
|
*
|
||||||
|
* Returns: The determinant.
|
||||||
|
*/
|
||||||
|
|
||||||
|
gdouble
|
||||||
|
gimp_matrix2_determinant (const GimpMatrix2 *matrix)
|
||||||
|
{
|
||||||
|
return matrix->coeff[0][0] * matrix->coeff[1][1] -
|
||||||
|
matrix->coeff[0][1] * matrix->coeff[1][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix2_invert:
|
||||||
|
* @matrix: The matrix that is to be inverted.
|
||||||
|
*
|
||||||
|
* Inverts the given matrix.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gimp_matrix2_invert (GimpMatrix2 *matrix)
|
||||||
|
{
|
||||||
|
gdouble det = gimp_matrix2_determinant (matrix);
|
||||||
|
gdouble temp;
|
||||||
|
|
||||||
|
if (fabs (det) <= EPSILON)
|
||||||
|
return;
|
||||||
|
|
||||||
|
temp = matrix->coeff[0][0];
|
||||||
|
|
||||||
|
matrix->coeff[0][0] = matrix->coeff[1][1] / det;
|
||||||
|
matrix->coeff[0][1] /= -det;
|
||||||
|
matrix->coeff[1][0] /= -det;
|
||||||
|
matrix->coeff[1][1] = temp / det;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix2_transform_point:
|
||||||
|
* @matrix: The transformation matrix.
|
||||||
|
* @x: The source X coordinate.
|
||||||
|
* @y: The source Y coordinate.
|
||||||
|
* @newx: The transformed X coordinate.
|
||||||
|
* @newy: The transformed Y coordinate.
|
||||||
|
*
|
||||||
|
* Transforms a point in 2D as specified by the transformation matrix.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gimp_matrix2_transform_point (const GimpMatrix2 *matrix,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
gdouble *newx,
|
||||||
|
gdouble *newy)
|
||||||
|
{
|
||||||
|
*newx = matrix->coeff[0][0] * x + matrix->coeff[0][1] * y;
|
||||||
|
*newy = matrix->coeff[1][0] * x + matrix->coeff[1][1] * y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static GimpMatrix3 * matrix3_copy (const GimpMatrix3 *matrix);
|
static GimpMatrix3 * matrix3_copy (const GimpMatrix3 *matrix);
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,15 @@ void gimp_matrix2_identity (GimpMatrix2 *matrix);
|
||||||
void gimp_matrix2_mult (const GimpMatrix2 *matrix1,
|
void gimp_matrix2_mult (const GimpMatrix2 *matrix1,
|
||||||
GimpMatrix2 *matrix2);
|
GimpMatrix2 *matrix2);
|
||||||
|
|
||||||
|
gdouble gimp_matrix2_determinant (const GimpMatrix2 *matrix);
|
||||||
|
void gimp_matrix2_invert (GimpMatrix2 *matrix);
|
||||||
|
|
||||||
|
void gimp_matrix2_transform_point (const GimpMatrix2 *matrix,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
gdouble *newx,
|
||||||
|
gdouble *newy);
|
||||||
|
|
||||||
|
|
||||||
/*****************/
|
/*****************/
|
||||||
/* GimpMatrix3 */
|
/* GimpMatrix3 */
|
||||||
|
|
Loading…
Reference in New Issue