[Bf-blender-cvs] [fa405209e62] greasepencil-refactor: GPencil: Improve collision rectangle size

Antonio Vazquez noreply at git.blender.org
Sun Feb 2 16:44:02 CET 2020


Commit: fa405209e62a8910efcaf4cbd582ba5957fcd697
Author: Antonio Vazquez
Date:   Sun Feb 2 16:43:46 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBfa405209e62a8910efcaf4cbd582ba5957fcd697

GPencil: Improve collision rectangle size

The problem was the rectangle for mouse it was using the internal rectangle, but must be the external rectangle, or the corners will not be detected.

Also some code cleanup.

===================================================================

M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index f5f5df1b173..66724cc3625 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2560,10 +2560,11 @@ void ED_gpencil_sbuffer_vertex_color_set(ToolSettings *ts, Brush *brush, bGPdata
 /* Check if the stroke collides with brush. */
 bool ED_gpencil_stroke_check_collision(GP_SpaceConversion *gsc,
                                        bGPDstroke *gps,
-                                       float mval[2],
+                                       float mouse[2],
                                        const int radius,
                                        const float diff_mat[4][4])
 {
+  const int offset = (int)ceil(sqrt((radius * radius) * 2));
   bGPDspoint pt_dummy, pt_dummy_ps;
   float gps_collision_min[2] = {0.0f};
   float gps_collision_max[2] = {0.0f};
@@ -2583,12 +2584,12 @@ bool ED_gpencil_stroke_check_collision(GP_SpaceConversion *gsc,
   gp_point_to_parent_space(&pt_dummy, diff_mat, &pt_dummy_ps);
   gp_point_to_xy_fl(gsc, gps, &pt_dummy_ps, &gps_collision_max[0], &gps_collision_max[1]);
 
-  rcti rect1 = {
+  rcti rect_stroke = {
       gps_collision_min[0], gps_collision_max[0], gps_collision_min[1], gps_collision_max[1]};
-  rcti rect2 = {mval[0] - radius, mval[0] + radius, mval[1] - radius, mval[1] + radius};
-  if (BLI_rcti_isect(&rect1, &rect2, NULL)) {
-    return true;
-  }
 
-  return true;
+  /* For mouse, add a small offet to avoid false negative in corners. */
+  rcti rect_mouse = {mouse[0] - offset, mouse[0] + offset, mouse[1] - offset, mouse[1] + offset};
+
+  /* Check collision between both rectangles. */
+  return BLI_rcti_isect(&rect_stroke, &rect_mouse, NULL);
 }
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index b5d53045ca2..937ca83899f 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -306,7 +306,7 @@ void ED_gpencil_sbuffer_vertex_color_set(struct ToolSettings *ts,
 
 bool ED_gpencil_stroke_check_collision(struct GP_SpaceConversion *gsc,
                                        struct bGPDstroke *gps,
-                                       float mval[2],
+                                       float mouse[2],
                                        const int radius,
                                        const float diff_mat[4][4]);



More information about the Bf-blender-cvs mailing list