From 206f29c12c59f13f5815701dd7ceeee4ff8d3a64 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Mon, 18 May 2015 02:03:15 +1200 Subject: Fix T44685 - In grease pencil stroke editing, selecting points is offset by a few pixels The problem was that it was aborting too early after stumbling across a point which might fit within the bounds required. This commit improves the logic here to solve this and a few other little bugs like that. Disclaimer: There are still a few cases where it randomly ends up picking something way off. However, this only seems to occur very sporadically, so it's hard to say how bad the problem may be. --- source/blender/editors/gpencil/gpencil_select.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index 9d0cb6d711a..1b66f366b70 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -775,6 +775,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) bGPDstroke *hit_stroke = NULL; bGPDspoint *hit_point = NULL; + int hit_distance = radius_squared; /* sanity checks */ if (sa == NULL) { @@ -797,7 +798,6 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) { bGPDspoint *pt; int i; - int hit_index = -1; /* firstly, check for hit-point */ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { @@ -807,18 +807,19 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) /* do boundbox check first */ if (!ELEM(V2D_IS_CLIPPED, x0, x0)) { - /* only check if point is inside */ - if (((x0 - mx) * (x0 - mx) + (y0 - my) * (y0 - my)) <= radius_squared) { - hit_stroke = gps; - hit_point = pt; - break; + const int pt_distance = ((x0 - mx) * (x0 - mx) + (y0 - my) * (y0 - my)); + + /* check if point is inside */ + if (pt_distance <= radius_squared) { + /* only use this point if it is a better match than the current hit - T44685 */ + if (pt_distance < hit_distance) { + hit_stroke = gps; + hit_point = pt; + hit_distance = pt_distance; + } } } } - - /* skip to next stroke if nothing found */ - if (hit_index == -1) - continue; } CTX_DATA_END; -- cgit v1.2.3