From bfb51b07824bc7e58bb7940714d616aa70e5859f Mon Sep 17 00:00:00 2001 From: Ell Date: Tue, 4 Jul 2017 10:40:32 -0400 Subject: [PATCH] app: don't compute slider values for 0-length lines while dragging ... to avoid getting NaNs. --- app/display/gimptoolline.c | 43 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/app/display/gimptoolline.c b/app/display/gimptoolline.c index 50a61f53d2..aea3adbf1e 100644 --- a/app/display/gimptoolline.c +++ b/app/display/gimptoolline.c @@ -731,28 +731,39 @@ gimp_tool_line_point_motion (GimpToolLine *line, case POINT_SLIDER: { - GimpControllerSlider *slider; - gdouble t; + gdouble length_sqr; - slider = &g_array_index (private->sliders, - GimpControllerSlider, private->slider_index); + length_sqr = SQR (private->x2 - private->x1) + + SQR (private->y2 - private->y1); - /* project the cursor position onto the line */ - t = (private->x2 - private->x1) * (x - private->x1) + - (private->y2 - private->y1) * (y - private->y1); - t /= SQR (private->x2 - private->x1) + SQR (private->y2 - private->y1); + /* don't change slider values of 0-length lines, since we'll just get + * NaN. + */ + if (length_sqr > 0.0) + { + GimpControllerSlider *slider; + gdouble t; - t = CLAMP (t, slider->min, slider->max); - t = CLAMP (t, 0.0, 1.0); + slider = &g_array_index (private->sliders, GimpControllerSlider, + private->slider_index); - if (constrain) - t = RINT (24.0 * t) / 24.0; + /* project the cursor position onto the line */ + 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, - "sliders", private->sliders, - NULL); + if (constrain) + t = RINT (24.0 * t) / 24.0; + + slider->value = t; + + g_object_set (line, + "sliders", private->sliders, + NULL); + } return TRUE; }