@@ -399,3 +399,86 @@ TEST(Keyframe_Large_Number_Values)
399399 CHECK_CLOSE (kf.GetPoint (0 ).co .Y , 1.0 , 0.01 );
400400 CHECK_CLOSE (kf.GetPoint (1 ).co .Y , 100.0 , 0.01 );
401401}
402+
403+ TEST (Keyframe_Remove_Point)
404+ {
405+ Keyframe kf;
406+ kf.AddPoint (openshot::Point (Coordinate (1 , 1 ), CONSTANT));
407+ kf.AddPoint (openshot::Point (Coordinate (3 , 100 ), CONSTANT));
408+ CHECK_EQUAL (1 , kf.GetInt (2 ));
409+ kf.AddPoint (openshot::Point (Coordinate (2 , 50 ), CONSTANT));
410+ CHECK_EQUAL (50 , kf.GetInt (2 ));
411+ kf.RemovePoint (1 ); // This is the index of point with X == 2
412+ CHECK_EQUAL (1 , kf.GetInt (2 ));
413+ CHECK_THROW (kf.RemovePoint (100 ), OutOfBoundsPoint);
414+ }
415+
416+ TEST (Keyframe_Constant_Interpolation_First_Segment)
417+ {
418+ Keyframe kf;
419+ kf.AddPoint (Point (Coordinate (1 , 1 ), CONSTANT));
420+ kf.AddPoint (Point (Coordinate (2 , 50 ), CONSTANT));
421+ kf.AddPoint (Point (Coordinate (3 , 100 ), CONSTANT));
422+ CHECK_EQUAL (1 , kf.GetInt (0 ));
423+ CHECK_EQUAL (1 , kf.GetInt (1 ));
424+ CHECK_EQUAL (50 , kf.GetInt (2 ));
425+ CHECK_EQUAL (100 , kf.GetInt (3 ));
426+ CHECK_EQUAL (100 , kf.GetInt (4 ));
427+ }
428+
429+ TEST (Keyframe_isIncreasing)
430+ {
431+ // Which cases need to be tested to keep same behaviour as
432+ // previously?
433+ //
434+ // - "invalid point" => true
435+ // - point where all next values are equal => false
436+ // - point where first non-eq next value is smaller => false
437+ // - point where first non-eq next value is larger => true
438+ Keyframe kf;
439+ kf.AddPoint (1 , 1 , LINEAR); // testing with linear
440+ kf.AddPoint (3 , 5 , BEZIER); // testing with bezier
441+ kf.AddPoint (6 , 10 , CONSTANT); // first non-eq is smaller
442+ kf.AddPoint (8 , 8 , CONSTANT); // first non-eq is larger
443+ kf.AddPoint (10 , 10 , CONSTANT); // all next values are equal
444+ kf.AddPoint (15 , 10 , CONSTANT);
445+
446+ // "invalid points"
447+ CHECK_EQUAL (true , kf.IsIncreasing (0 ));
448+ CHECK_EQUAL (true , kf.IsIncreasing (15 ));
449+ // all next equal
450+ CHECK_EQUAL (false , kf.IsIncreasing (12 ));
451+ // first non-eq is larger
452+ CHECK_EQUAL (true , kf.IsIncreasing (8 ));
453+ // first non-eq is smaller
454+ CHECK_EQUAL (false , kf.IsIncreasing (6 ));
455+ // bezier and linear
456+ CHECK_EQUAL (true , kf.IsIncreasing (4 ));
457+ CHECK_EQUAL (true , kf.IsIncreasing (2 ));
458+ }
459+
460+ TEST (Keyframe_GetLength)
461+ {
462+ Keyframe f;
463+ CHECK_EQUAL (0 , f.GetLength ());
464+ f.AddPoint (1 , 1 );
465+ CHECK_EQUAL (1 , f.GetLength ());
466+ f.AddPoint (2 , 1 );
467+ CHECK_EQUAL (3 , f.GetLength ());
468+ f.AddPoint (200 , 1 );
469+ CHECK_EQUAL (201 , f.GetLength ());
470+
471+ Keyframe g;
472+ g.AddPoint (200 , 1 );
473+ CHECK_EQUAL (1 , g.GetLength ());
474+ g.AddPoint (1 ,1 );
475+ CHECK_EQUAL (201 , g.GetLength ());
476+ }
477+
478+ TEST (Keyframe_Use_Interpolation_of_Segment_End_Point)
479+ {
480+ Keyframe f;
481+ f.AddPoint (1 ,0 , CONSTANT);
482+ f.AddPoint (100 ,155 , BEZIER);
483+ CHECK_CLOSE (75.9 , f.GetValue (50 ), 0.1 );
484+ }
0 commit comments