app: don't compute slider values for 0-length lines while dragging

... to avoid getting NaNs.
This commit is contained in:
Ell
2017-07-04 10:40:32 -04:00
parent 76644b7367
commit bfb51b0782

View File

@ -731,28 +731,39 @@ gimp_tool_line_point_motion (GimpToolLine *line,
case POINT_SLIDER: case POINT_SLIDER:
{ {
GimpControllerSlider *slider; gdouble length_sqr;
gdouble t;
slider = &g_array_index (private->sliders, length_sqr = SQR (private->x2 - private->x1) +
GimpControllerSlider, private->slider_index); SQR (private->y2 - private->y1);
/* project the cursor position onto the line */ /* don't change slider values of 0-length lines, since we'll just get
t = (private->x2 - private->x1) * (x - private->x1) + * NaN.
(private->y2 - private->y1) * (y - private->y1); */
t /= SQR (private->x2 - private->x1) + SQR (private->y2 - private->y1); if (length_sqr > 0.0)
{
GimpControllerSlider *slider;
gdouble t;
t = CLAMP (t, slider->min, slider->max); slider = &g_array_index (private->sliders, GimpControllerSlider,
t = CLAMP (t, 0.0, 1.0); private->slider_index);
if (constrain) /* project the cursor position onto the line */
t = RINT (24.0 * t) / 24.0; t = (private->x2 - private->x1) * (x - private->x1) +
(private->y2 - private->y1) * (y - private->y1);
t /= length_sqr;
slider->value = t; t = CLAMP (t, slider->min, slider->max);
t = CLAMP (t, 0.0, 1.0);
g_object_set (line, if (constrain)
"sliders", private->sliders, t = RINT (24.0 * t) / 24.0;
NULL);
slider->value = t;
g_object_set (line,
"sliders", private->sliders,
NULL);
}
return TRUE; return TRUE;
} }