Commit e7b6103c authored by Ell's avatar Ell

app: improve stability of Gaussian elimination in transform-utils

When picking a row whose leading coefficient is nonzero, use fuzzy
comparison against an epsilon, instead of exact comparison against
zero, to minimize the effect of numerical errors.
parent 5cd0ecc9
......@@ -26,6 +26,9 @@
#include "gimp-transform-utils.h"
#define EPSILON 1e-6
void
gimp_transform_get_rotate_center (gint x,
gint y,
......@@ -363,7 +366,7 @@ mod_gauss (gdouble matrix[],
for (r = 0; r < s; r++)
{
/* make sure that (r,r) is not 0 */
if (matrix[p[r] * t + r] == 0.0)
if (fabs (matrix[p[r] * t + r]) <= EPSILON)
{
/* we need to permutate rows */
for (i = r + 1; i <= s; i++)
......@@ -376,7 +379,7 @@ mod_gauss (gdouble matrix[],
return FALSE;
}
if (matrix[p[i] * t + r] != 0.0)
if (fabs (matrix[p[i] * t + r]) > EPSILON)
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment