4#include "testing/testing.h"
18using namespace blender::animrig;
49 float time_epsilon = 0.00008f;
120 fcu->
bezt[0].
vec[0][0] = 0.71855f;
121 fcu->
bezt[0].
vec[0][1] = 6.22482f;
122 fcu->
bezt[0].
vec[2][0] = 1.35148f;
123 fcu->
bezt[0].
vec[2][1] = 7.96806f;
125 fcu->
bezt[1].
vec[0][0] = 1.66667f;
126 fcu->
bezt[1].
vec[0][1] = 10.4136f;
127 fcu->
bezt[1].
vec[2][0] = 2.33333f;
128 fcu->
bezt[1].
vec[2][1] = 15.5864f;
209 fcu->
bezt[0].
vec[0][0] = 0.71855f;
210 fcu->
bezt[0].
vec[0][1] = 6.22482f;
211 fcu->
bezt[0].
vec[2][0] = 1.35148f;
212 fcu->
bezt[0].
vec[2][1] = 7.96806f;
214 fcu->
bezt[1].
vec[0][0] = 1.66667f;
215 fcu->
bezt[1].
vec[0][1] = 10.4136f;
216 fcu->
bezt[1].
vec[2][0] = 2.33333f;
217 fcu->
bezt[1].
vec[2][1] = 15.5864f;
254 fcu->
bezt[0].
vec[0][0] = -5.0f;
260 fcu->
bezt[1].
vec[0][0] = 13.0f;
261 fcu->
bezt[1].
vec[0][1] = -2.0f;
262 fcu->
bezt[1].
vec[2][0] = 16.0f;
263 fcu->
bezt[1].
vec[2][1] = -3.0f;
267 const float x = 7.375f;
268 const float y = 1.000f;
269 beztr.
vec[0][0] =
x - 1.0f;
273 beztr.
vec[2][0] =
x + 1.0f;
282 EXPECT_FLOAT_EQ(y_delta, 0.0f);
284 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[0][0], -5.0f);
285 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[0][1], 0.0f);
286 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[1][0], 1.0f);
287 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[1][1], 0.0f);
288 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[2][0], 1.5f);
289 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[2][1], 2.0f);
291 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 13.0f);
292 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 0.0f);
293 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 13.0f);
294 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 2.0f);
295 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 16.0f);
296 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], -3.0f);
298 EXPECT_FLOAT_EQ(beztr.
vec[0][0], 4.5f);
299 EXPECT_FLOAT_EQ(beztr.
vec[0][1], 1.5f);
300 EXPECT_FLOAT_EQ(beztr.
vec[1][0], 7.375f);
301 EXPECT_FLOAT_EQ(beztr.
vec[1][1], 1.0f);
302 EXPECT_FLOAT_EQ(beztr.
vec[2][0], 10.250);
303 EXPECT_FLOAT_EQ(beztr.
vec[2][1], 0.5);
345 "active keyframe must be selected");
351 <<
"Setting out-of-bounds value via the API should result in valid active_keyframe_index";
356 <<
"Even with active_keyframe_index out of bounds, getting it via the API should produce a "
362 <<
"Setting out-of-bounds value via the API should result in valid active_keyframe_index";
367 <<
"Even with active_keyframe_index out of bounds, getting it via the API should produce a "
384 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 5.2671194f);
385 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 15.0f);
387 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 8.0f);
388 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 15.0f);
390 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 10.342469f);
391 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 15.0f);
395 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 5.2671194f) <<
"Left handle should not move in time";
396 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 47.0f) <<
"Left handle value should have been updated";
398 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 8.0f) <<
"Frame should not move in time";
399 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 47.0f) <<
"Frame value should have been updated";
401 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 10.342469f) <<
"Right handle should not move in time";
402 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 47.0f) <<
"Right handle value should have been updated";
416 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 5.2671194f);
417 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 15.0f);
419 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 8.0f);
420 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 15.0f);
422 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 10.342469f);
423 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 15.0f);
427 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 44.2671194f) <<
"Left handle time should be updated";
428 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 15.0f) <<
"Left handle should not move in value";
430 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 47.0f) <<
"Frame time should have been updated";
431 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 15.0f) <<
"Frame should not move in value";
433 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 49.342469f) <<
"Right handle time should be updated";
434 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 15.0f) <<
"Right handle should not move in value";
450 for (
int i = 0; i < fcu->
totvert; i++) {
461 EXPECT_TRUE(success) <<
"A non-empty FCurve should have a range.";
468 <<
"Using selected keyframes only should not find a range if nothing is selected.";
474 EXPECT_TRUE(success) <<
"Range of selected keyframes should have been found.";
479 const int sample_start = 1;
480 const int sample_end = 20;
484 EXPECT_TRUE(success) <<
"FCurve samples should have a range.";
486 EXPECT_FLOAT_EQ(sample_start,
min);
487 EXPECT_FLOAT_EQ(sample_end,
max);
503 for (
int i = 0; i < fcu->
totvert; i++) {
509 fcu->
bezt[0].
vec[0][0] = -5.0f;
510 fcu->
bezt[4].
vec[2][0] = 25.0f;
521 EXPECT_TRUE(success) <<
"A non-empty FCurve should have bounds.";
534 <<
"Using selected keyframes only should not find bounds if nothing is selected.";
544 EXPECT_TRUE(success) <<
"Selected keys should have been found.";
556 EXPECT_TRUE(success) <<
"A non-empty FCurve should have bounds including handles.";
568 fcu,
false ,
false , range , &
bounds);
569 EXPECT_FALSE(success) <<
"A frame range outside the range of keyframes should not find bounds.";
574 fcu,
false ,
false , range , &
bounds);
575 EXPECT_TRUE(success) <<
"A frame range within the range of keyframes should find bounds.";
583 fcu,
false ,
true , range , &
bounds);
585 <<
"A frame range within the range of keyframes should find bounds with handles.";
595 fcu,
true ,
true , range , &
bounds);
597 <<
"A frame range within the range of keyframes should find bounds of selected keyframes.";
604 const int sample_start = 1;
605 const int sample_end = 20;
613 EXPECT_TRUE(success) <<
"FCurve samples should have a range.";
615 EXPECT_FLOAT_EQ(sample_start,
bounds.xmin);
616 EXPECT_FLOAT_EQ(sample_end,
bounds.xmax);
617 EXPECT_FLOAT_EQ(-20.0f,
bounds.ymin);
618 EXPECT_FLOAT_EQ(15.0f,
bounds.ymax);
623 fcu,
false ,
false , range , &
bounds);
624 EXPECT_TRUE(success) <<
"FCurve samples should have a range.";
626 EXPECT_FLOAT_EQ(range[0],
bounds.xmin);
627 EXPECT_FLOAT_EQ(range[1],
bounds.xmax);
628 EXPECT_FLOAT_EQ(-20.0f,
bounds.ymin);
629 EXPECT_FLOAT_EQ(15.0f,
bounds.ymax);
634 fcu,
false ,
false , range , &
bounds);
636 <<
"A frame range outside the range of keyframe samples should not have bounds.";
659 set_key(fcu, 1, 327.16f, 1.0f);
680 ASSERT_EQ(fcu->
totvert, 10) <<
"sorting should not influence number of keys";
Functions to modify FCurves.
#define BEZT_BINARYSEARCH_THRESH
#define FCURVE_ACTIVE_KEYFRAME_NONE
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
#define EXPECT_NEAR(result, expect, threshold)
KeyframeSettings get_keyframe_settings(bool from_userprefs)
SingleKeyingResult insert_vert_fcurve(FCurve *fcu, const float2 position, const KeyframeSettings &settings, eInsertKeyFlags flag)
Main Key-framing API call.
static const float EPSILON
static void set_key(FCurve *fcu, const int index, const float x, const float y)
static FCurve * testcurve_with_duplicates()
TEST_F(AnimDataTest, BKE_fcurves_id_cb_test)
bool BKE_fcurve_calc_range(const FCurve *fcu, float *r_min, float *r_max, bool selected_keys_only)
void ED_keyframes_add(FCurve *fcu, int num_keys_to_add)
void BKE_fcurve_keyframe_move_value_with_handles(BezTriple *keyframe, float new_value)
bool BKE_fcurve_bezt_subdivide_handles(BezTriple *bezt, BezTriple *prev, BezTriple *next, float *r_pdelta)
void BKE_fcurve_keyframe_move_time_with_handles(BezTriple *keyframe, const float new_time)
VecBase< float, 2 > float2
bool BKE_fcurve_calc_bounds(const FCurve *fcu, bool selected_keys_only, bool include_handles, const float frame_range[2], rctf *r_bounds)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void BKE_fcurve_free(FCurve *fcu)
void BKE_fcurve_active_keyframe_set(FCurve *fcu, const BezTriple *active_bezt)
int BKE_fcurve_active_keyframe_index(const FCurve *fcu)
void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
void BKE_fcurve_deduplicate_keys(FCurve *fcu)
float fcurve_samplingcb_evalcurve(FCurve *fcu, void *data, float evaltime)
@ FCURVE_EXTRAPOLATE_CONSTANT
@ FCURVE_EXTRAPOLATE_LINEAR
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
FCurve * BKE_fcurve_create()
void sort_time_fcurve(FCurve &fcu)
float evaluate_fcurve(const FCurve *fcu, float evaltime)
eBezTriple_Interpolation ipo
int active_keyframe_index