4#include "testing/testing.h"
17using namespace blender::animrig;
46 float time_epsilon = 0.00008f;
117 fcu->
bezt[0].
vec[0][0] = 0.71855f;
118 fcu->
bezt[0].
vec[0][1] = 6.22482f;
119 fcu->
bezt[0].
vec[2][0] = 1.35148f;
120 fcu->
bezt[0].
vec[2][1] = 7.96806f;
122 fcu->
bezt[1].
vec[0][0] = 1.66667f;
123 fcu->
bezt[1].
vec[0][1] = 10.4136f;
124 fcu->
bezt[1].
vec[2][0] = 2.33333f;
125 fcu->
bezt[1].
vec[2][1] = 15.5864f;
206 fcu->
bezt[0].
vec[0][0] = 0.71855f;
207 fcu->
bezt[0].
vec[0][1] = 6.22482f;
208 fcu->
bezt[0].
vec[2][0] = 1.35148f;
209 fcu->
bezt[0].
vec[2][1] = 7.96806f;
211 fcu->
bezt[1].
vec[0][0] = 1.66667f;
212 fcu->
bezt[1].
vec[0][1] = 10.4136f;
213 fcu->
bezt[1].
vec[2][0] = 2.33333f;
214 fcu->
bezt[1].
vec[2][1] = 15.5864f;
249 fcu->
bezt[0].
vec[0][0] = -5.0f;
255 fcu->
bezt[1].
vec[0][0] = 13.0f;
256 fcu->
bezt[1].
vec[0][1] = -2.0f;
257 fcu->
bezt[1].
vec[2][0] = 16.0f;
258 fcu->
bezt[1].
vec[2][1] = -3.0f;
262 const float x = 7.375f;
263 const float y = 1.000f;
264 beztr.
vec[0][0] =
x - 1.0f;
268 beztr.
vec[2][0] =
x + 1.0f;
277 EXPECT_FLOAT_EQ(y_delta, 0.0f);
279 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[0][0], -5.0f);
280 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[0][1], 0.0f);
281 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[1][0], 1.0f);
282 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[1][1], 0.0f);
283 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[2][0], 1.5f);
284 EXPECT_FLOAT_EQ(fcu->
bezt[0].
vec[2][1], 2.0f);
286 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 13.0f);
287 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 0.0f);
288 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 13.0f);
289 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 2.0f);
290 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 16.0f);
291 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], -3.0f);
293 EXPECT_FLOAT_EQ(beztr.
vec[0][0], 4.5f);
294 EXPECT_FLOAT_EQ(beztr.
vec[0][1], 1.5f);
295 EXPECT_FLOAT_EQ(beztr.
vec[1][0], 7.375f);
296 EXPECT_FLOAT_EQ(beztr.
vec[1][1], 1.0f);
297 EXPECT_FLOAT_EQ(beztr.
vec[2][0], 10.250);
298 EXPECT_FLOAT_EQ(beztr.
vec[2][1], 0.5);
303TEST(fcurve_active_keyframe, ActiveKeyframe)
338 "active keyframe must be selected");
344 <<
"Setting out-of-bounds value via the API should result in valid active_keyframe_index";
349 <<
"Even with active_keyframe_index out of bounds, getting it via the API should produce a "
355 <<
"Setting out-of-bounds value via the API should result in valid active_keyframe_index";
360 <<
"Even with active_keyframe_index out of bounds, getting it via the API should produce a "
375 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 5.2671194f);
376 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 15.0f);
378 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 8.0f);
379 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 15.0f);
381 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 10.342469f);
382 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 15.0f);
386 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 5.2671194f) <<
"Left handle should not move in time";
387 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 47.0f) <<
"Left handle value should have been updated";
389 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 8.0f) <<
"Frame should not move in time";
390 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 47.0f) <<
"Frame value should have been updated";
392 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 10.342469f) <<
"Right handle should not move in time";
393 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 47.0f) <<
"Right handle value should have been updated";
407 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 5.2671194f);
408 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 15.0f);
410 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 8.0f);
411 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 15.0f);
413 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 10.342469f);
414 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 15.0f);
418 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][0], 44.2671194f) <<
"Left handle time should be updated";
419 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[0][1], 15.0f) <<
"Left handle should not move in value";
421 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][0], 47.0f) <<
"Frame time should have been updated";
422 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[1][1], 15.0f) <<
"Frame should not move in value";
424 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][0], 49.342469f) <<
"Right handle time should be updated";
425 EXPECT_FLOAT_EQ(fcu->
bezt[1].
vec[2][1], 15.0f) <<
"Right handle should not move in value";
452 EXPECT_TRUE(success) <<
"A non-empty FCurve should have a range.";
458 EXPECT_FALSE(success)
459 <<
"Using selected keyframes only should not find a range if nothing is selected.";
465 EXPECT_TRUE(success) <<
"Range of selected keyframes should have been found.";
470 const int sample_start = 1;
471 const int sample_end = 20;
475 EXPECT_TRUE(success) <<
"FCurve samples should have a range.";
477 EXPECT_FLOAT_EQ(sample_start,
min);
478 EXPECT_FLOAT_EQ(sample_end,
max);
500 fcu->
bezt[0].
vec[0][0] = -5.0f;
501 fcu->
bezt[4].
vec[2][0] = 25.0f;
512 EXPECT_TRUE(success) <<
"A non-empty FCurve should have bounds.";
524 EXPECT_FALSE(success)
525 <<
"Using selected keyframes only should not find bounds if nothing is selected.";
535 EXPECT_TRUE(success) <<
"Selected keys should have been found.";
547 EXPECT_TRUE(success) <<
"A non-empty FCurve should have bounds including handles.";
559 fcu,
false ,
false , range , &
bounds);
560 EXPECT_FALSE(success) <<
"A frame range outside the range of keyframes should not find bounds.";
565 fcu,
false ,
false , range , &
bounds);
566 EXPECT_TRUE(success) <<
"A frame range within the range of keyframes should find bounds.";
574 fcu,
false ,
true , range , &
bounds);
576 <<
"A frame range within the range of keyframes should find bounds with handles.";
586 fcu,
true ,
true , range , &
bounds);
588 <<
"A frame range within the range of keyframes should find bounds of selected keyframes.";
595 const int sample_start = 1;
596 const int sample_end = 20;
604 EXPECT_TRUE(success) <<
"FCurve samples should have a range.";
606 EXPECT_FLOAT_EQ(sample_start,
bounds.xmin);
607 EXPECT_FLOAT_EQ(sample_end,
bounds.xmax);
608 EXPECT_FLOAT_EQ(-20.0f,
bounds.ymin);
609 EXPECT_FLOAT_EQ(15.0f,
bounds.ymax);
614 fcu,
false ,
false , range , &
bounds);
615 EXPECT_TRUE(success) <<
"FCurve samples should have a range.";
617 EXPECT_FLOAT_EQ(range[0],
bounds.xmin);
618 EXPECT_FLOAT_EQ(range[1],
bounds.xmax);
619 EXPECT_FLOAT_EQ(-20.0f,
bounds.ymin);
620 EXPECT_FLOAT_EQ(15.0f,
bounds.ymax);
625 fcu,
false ,
false , range , &
bounds);
626 EXPECT_FALSE(success)
627 <<
"A frame range outside the range of keyframe samples should not have bounds.";
634 fcu->
bezt[index].
vec[0][0] =
x - 0.5f;
636 fcu->
bezt[index].
vec[2][0] =
x + 0.5f;
650 set_key(fcu, 1, 327.16f, 1.0f);
662TEST(BKE_fcurve, sort_time_fcurve_stability)
671 ASSERT_EQ(fcu->
totvert, 10) <<
"sorting should not influence number of keys";
705TEST(BKE_fcurve, BKE_fcurve_deduplicate_keys_edge_cases)
728TEST(BKE_fcurve, BKE_fcurve_deduplicate_keys_prefer_whole_frames)
Functions to modify FCurves.
void BKE_fcurve_deduplicate_keys(FCurve *fcu)
void BKE_fcurve_keyframe_move_time_with_handles(BezTriple *keyframe, const float new_time)
FCurve * BKE_fcurve_create()
int BKE_fcurve_active_keyframe_index(const FCurve *fcu)
void BKE_fcurve_active_keyframe_set(FCurve *fcu, const BezTriple *active_bezt)
#define BEZT_BINARYSEARCH_THRESH
bool BKE_fcurve_bezt_subdivide_handles(BezTriple *bezt, BezTriple *prev, BezTriple *next, float *r_pdelta)
void BKE_fcurve_keyframe_move_value_with_handles(BezTriple *keyframe, float new_value)
float evaluate_fcurve(const FCurve *fcu, float evaltime)
void BKE_fcurve_free(FCurve *fcu)
bool BKE_fcurve_calc_range(const FCurve *fcu, float *r_min, float *r_max, bool selected_keys_only)
void sort_time_fcurve(FCurve *fcu)
void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
float fcurve_samplingcb_evalcurve(FCurve *fcu, void *data, float evaltime)
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)
#define FCURVE_ACTIVE_KEYFRAME_NONE
@ FCURVE_EXTRAPOLATE_CONSTANT
@ FCURVE_EXTRAPOLATE_LINEAR
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void ED_keyframes_add(FCurve *fcu, int num_keys_to_add)
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)
TEST(action_groups, ReconstructGroupsWithReordering)
static FCurve * testcurve_with_duplicates()
VecBase< float, 2 > float2
int active_keyframe_index