mirror of https://github.com/GNOME/gimp.git
app: improve num. stability of gimp_gradient_segment_range_compress()
When using gimp_gradient_segment_range_compress() to expand a 0- length segment, redistribute the range's endpoints and midpoints uniformly, rather than using the regular code path, which would result in NaN values. Make sure that the left and right endpoints of the range are *exactly* equal to the new left and right values. Previously, they could be slightly off due to numerical errors.
This commit is contained in:
parent
3aff0a1a0e
commit
1b2a395e88
|
@ -1182,7 +1182,6 @@ gimp_gradient_segment_range_compress (GimpGradient *gradient,
|
|||
gdouble new_r)
|
||||
{
|
||||
gdouble orig_l, orig_r;
|
||||
gdouble scale;
|
||||
GimpGradientSegment *seg, *aseg;
|
||||
|
||||
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
|
||||
|
@ -1196,6 +1195,10 @@ gimp_gradient_segment_range_compress (GimpGradient *gradient,
|
|||
orig_l = range_l->left;
|
||||
orig_r = range_r->right;
|
||||
|
||||
if (orig_r - orig_l > EPSILON)
|
||||
{
|
||||
gdouble scale;
|
||||
|
||||
scale = (new_r - new_l) / (orig_r - orig_l);
|
||||
|
||||
seg = range_l;
|
||||
|
@ -1214,6 +1217,32 @@ gimp_gradient_segment_range_compress (GimpGradient *gradient,
|
|||
seg = seg->next;
|
||||
}
|
||||
while (aseg != range_r);
|
||||
}
|
||||
else
|
||||
{
|
||||
gint n;
|
||||
gint i;
|
||||
|
||||
n = gimp_gradient_segment_range_get_n_segments (gradient,
|
||||
range_l, range_r);
|
||||
|
||||
for (i = 0, seg = range_l; i < n; i++, seg = seg->next)
|
||||
{
|
||||
if (seg->prev)
|
||||
seg->left = new_l + (new_r - new_l) * (i + 0.0) / n;
|
||||
seg->middle = new_l + (new_r - new_l) * (i + 0.5) / n;;
|
||||
if (seg->next)
|
||||
seg->right = new_l + (new_r - new_l) * (i + 1.0) / n;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure that the left and right endpoints of the range are *exactly*
|
||||
* equal to new_l and new_r; the above computations can introduce
|
||||
* numerical inaccuracies.
|
||||
*/
|
||||
|
||||
range_l->left = new_l;
|
||||
range_l->right = new_r;
|
||||
|
||||
gimp_data_thaw (GIMP_DATA (gradient));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue