Cleanup: use range2f in `ED_keylist_find_any_between`.

This commit is contained in:
Jeroen Bakker 2021-08-06 09:46:36 +02:00
parent bb8ce95b5e
commit 1ab75c1d49
4 changed files with 15 additions and 14 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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 --------------- */

View File

@ -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