[Bf-blender-cvs] [59f37adac34] greasepencil-refactor: GPencil: Use bounding box collision instead of radius

Antonio Vazquez noreply at git.blender.org
Sun Feb 2 16:43:56 CET 2020


Commit: 59f37adac34afe32e9115e3884b31dfda7b92615
Author: Antonio Vazquez
Date:   Sun Feb 2 10:37:28 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB59f37adac34afe32e9115e3884b31dfda7b92615

GPencil: Use bounding box collision instead of radius

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

M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/gpencil/gpencil_vertex_paint.c
M	source/blender/editors/gpencil/gpencil_weight_paint.c

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

diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 6654f1eea94..f5f5df1b173 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2567,11 +2567,8 @@ bool ED_gpencil_stroke_check_collision(GP_SpaceConversion *gsc,
   bGPDspoint pt_dummy, pt_dummy_ps;
   float gps_collision_min[2] = {0.0f};
   float gps_collision_max[2] = {0.0f};
-  float collision_center[2] = {0.0f};
   float zerov3[3];
 
-  int mouse[2], center[2];
-
   /* Check we have something to use (only for old files). */
   if (equals_v3v3(zerov3, gps->collision_min)) {
     BKE_gpencil_stroke_collision_get(gps);
@@ -2586,16 +2583,11 @@ 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]);
 
-  /* Calc collision center and radius in 2d. */
-  add_v2_v2v2(collision_center, gps_collision_min, gps_collision_max);
-  mul_v2_v2fl(collision_center, collision_center, 0.5f);
-
-  int collision_radius = (int)(len_v2v2(gps_collision_min, gps_collision_max) * 0.5f);
-  round_v2i_v2fl(center, collision_center);
-  round_v2i_v2fl(mouse, mval);
-
-  if (len_v2v2_int(mouse, center) > radius + collision_radius) {
-    return false;
+  rcti rect1 = {
+      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;
diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c
index 078b32b0e4a..7b590a7c052 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_paint.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c
@@ -843,6 +843,11 @@ static void gp_vertexpaint_select_stroke(tGP_BrushVertexpaintData *gso,
   int index;
   bool include_last = false;
 
+  /* Check if the stroke collide with brush. */
+  if (!ED_gpencil_stroke_check_collision(gsc, gps, gso->mval, radius, diff_mat)) {
+    return;
+  }
+
   if (gps->totpoints == 1) {
     bGPDspoint pt_temp;
     pt = &gps->points[0];
diff --git a/source/blender/editors/gpencil/gpencil_weight_paint.c b/source/blender/editors/gpencil/gpencil_weight_paint.c
index 93047da0933..3d8073ec045 100644
--- a/source/blender/editors/gpencil/gpencil_weight_paint.c
+++ b/source/blender/editors/gpencil/gpencil_weight_paint.c
@@ -447,6 +447,11 @@ static void gp_weightpaint_select_stroke(tGP_BrushWeightpaintData *gso,
   int index;
   bool include_last = false;
 
+  /* Check if the stroke collide with brush. */
+  if (!ED_gpencil_stroke_check_collision(gsc, gps, gso->mval, radius, diff_mat)) {
+    return;
+  }
+
   if (gps->totpoints == 1) {
     bGPDspoint pt_temp;
     pt = &gps->points[0];



More information about the Bf-blender-cvs mailing list