[Bf-blender-cvs] [1ab75c1d494] master: Cleanup: use range2f in `ED_keylist_find_any_between`.

Jeroen Bakker noreply at git.blender.org
Fri Aug 6 09:56:07 CEST 2021


Commit: 1ab75c1d494422270fa88bbf23cc42f7b203ed4b
Author: Jeroen Bakker
Date:   Fri Aug 6 09:46:36 2021 +0200
Branches: master
https://developer.blender.org/rB1ab75c1d494422270fa88bbf23cc42f7b203ed4b

Cleanup: use range2f in `ED_keylist_find_any_between`.

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

M	source/blender/blenlib/BLI_range.h
M	source/blender/editors/animation/keyframes_keylist.c
M	source/blender/editors/include/ED_keyframes_keylist.h
M	source/blender/editors/space_action/action_select.c

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

diff --git a/source/blender/blenlib/BLI_range.h b/source/blender/blenlib/BLI_range.h
index ad4cd6c162e..e55f443769d 100644
--- a/source/blender/blenlib/BLI_range.h
+++ b/source/blender/blenlib/BLI_range.h
@@ -29,6 +29,11 @@ typedef struct Range2f {
   float max;
 } Range2f;
 
+BLI_INLINE bool range2f_in_range(const Range2f *range, const float value)
+{
+  return IN_RANGE(value, range->min, range->max);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/editors/animation/keyframes_keylist.c b/source/blender/editors/animation/keyframes_keylist.c
index 722edba0473..a869d8d6388 100644
--- a/source/blender/editors/animation/keyframes_keylist.c
+++ b/source/blender/editors/animation/keyframes_keylist.c
@@ -89,14 +89,11 @@ ActKeyColumn *ED_keylist_find_prev(const AnimKeylist *keylist, float cfra)
 
 /* TODO(jbakker): Should we change this to use `ED_keylist_find_next(keys, min_fra)` and only check
  * boundary of `max_fra`. */
-/* TODO(jbakker): Use const Range2f. */
-ActKeyColumn *ED_keylist_find_any_between(const AnimKeylist *keylist,
-                                          const float min_fra,
-                                          const float max_fra)
+ActKeyColumn *ED_keylist_find_any_between(const AnimKeylist *keylist, const Range2f frame_range)
 {
   for (ActKeyColumn *ak = keylist->keys.root; ak;
-       ak = (ak->cfra < min_fra) ? ak->right : ak->left) {
-    if (IN_RANGE(ak->cfra, min_fra, max_fra)) {
+       ak = (ak->cfra < frame_range.min) ? ak->right : ak->left) {
+    if (range2f_in_range(&frame_range, ak->cfra)) {
       return ak;
     }
   }
diff --git a/source/blender/editors/include/ED_keyframes_keylist.h b/source/blender/editors/include/ED_keyframes_keylist.h
index 8ab2dff36e5..86741b67698 100644
--- a/source/blender/editors/include/ED_keyframes_keylist.h
+++ b/source/blender/editors/include/ED_keyframes_keylist.h
@@ -23,6 +23,8 @@
 
 #pragma once
 
+#include "BLI_range.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -37,7 +39,6 @@ struct Scene;
 struct bAnimContext;
 struct bDopeSheet;
 struct bGPDlayer;
-struct Range2f;
 
 /* ****************************** Base Structs ****************************** */
 
@@ -142,11 +143,10 @@ struct ActKeyColumn *ED_keylist_find_exact(const struct AnimKeylist *keylist, fl
 struct ActKeyColumn *ED_keylist_find_next(const struct AnimKeylist *keylist, float cfra);
 struct ActKeyColumn *ED_keylist_find_prev(const struct AnimKeylist *keylist, float cfra);
 struct ActKeyColumn *ED_keylist_find_any_between(const struct AnimKeylist *keylist,
-                                                 float min_fra,
-                                                 float max_fra);
+                                                 const Range2f frame_range);
 bool ED_keylist_is_empty(const struct AnimKeylist *keylist);
 const struct ListBase /* ActKeyColumn */ *ED_keylist_listbase(const struct AnimKeylist *keylist);
-bool ED_keylist_frame_range(const struct AnimKeylist *keylist, struct Range2f *r_frame_range);
+bool ED_keylist_frame_range(const struct AnimKeylist *keylist, Range2f *r_frame_range);
 
 /* Key-data Generation --------------- */
 
diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c
index 64ccca2c907..9dcfc626a50 100644
--- a/source/blender/editors/space_action/action_select.c
+++ b/source/blender/editors/space_action/action_select.c
@@ -170,10 +170,9 @@ static void actkeys_find_key_in_list_element(bAnimContext *ac,
   /* half-size (for either side), but rounded up to nearest int (for easier targeting) */
   key_hsize = roundf(key_hsize / 2.0f);
 
-  float xmin = UI_view2d_region_to_view_x(v2d, region_x - (int)key_hsize);
-  float xmax = UI_view2d_region_to_view_x(v2d, region_x + (int)key_hsize);
-
-  const ActKeyColumn *ak = ED_keylist_find_any_between(keylist, xmin, xmax);
+  const Range2f range = {UI_view2d_region_to_view_x(v2d, region_x - (int)key_hsize),
+                         UI_view2d_region_to_view_x(v2d, region_x + (int)key_hsize)};
+  const ActKeyColumn *ak = ED_keylist_find_any_between(keylist, range);
   if (ak) {
 
     /* set the frame to use, and apply inverse-correction for NLA-mapping



More information about the Bf-blender-cvs mailing list