diff --git a/include/Clip.h b/include/Clip.h index 09940678..b4e6688d 100644 --- a/include/Clip.h +++ b/include/Clip.h @@ -89,16 +89,16 @@ namespace openshot { AnchorType anchor; ///= 0 && index < Values.size()) // Return value - return Values[index]; + return Values[index].Y; else if (index < 0 && Values.size() > 0) // Return the minimum value - return Coordinate(index, Values[0].Y); + return Values[0].Y; else if (index >= Values.size() && Values.size() > 0) // return the maximum value - return Coordinate(index, Values[Values.size() - 1].Y); + return Values[Values.size() - 1].Y; else // return a blank coordinate (0,0) - return Coordinate(0,0); + return 0.0; } // Get a point at a specific index diff --git a/src/Point.cpp b/src/Point.cpp index 4111f791..dfa89ba3 100644 --- a/src/Point.cpp +++ b/src/Point.cpp @@ -28,6 +28,16 @@ Point::Point(float x, float y) : Initialize_Handles(); } +// Constructor which also creates a Point and sets the X,Y, and interpolation of the Point. +Point::Point(float x, float y, Interpolation_Type interpolation) : + handle_type(AUTO), interpolation(interpolation) { + // set new coorinate + co = Coordinate(x, y); + + // set handles + Initialize_Handles(); +} + Point::Point(Coordinate co) : co(co), interpolation(BEZIER), handle_type(AUTO) { // set handles diff --git a/tests/KeyFrame_Tests.cpp b/tests/KeyFrame_Tests.cpp index 5935670a..63deaaea 100644 --- a/tests/KeyFrame_Tests.cpp +++ b/tests/KeyFrame_Tests.cpp @@ -61,13 +61,13 @@ TEST(Keyframe_GetValue_For_Bezier_Curve_2_Points) kf.AddPoint(openshot::Point(Coordinate(50, 4), BEZIER)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1).Y, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0).Y, 0.0001); - CHECK_CLOSE(1.00023f, kf.GetValue(1).Y, 0.0001); - CHECK_CLOSE(1.18398f, kf.GetValue(9).Y, 0.0001); - CHECK_CLOSE(1.99988f, kf.GetValue(20).Y, 0.0001); - CHECK_CLOSE(3.75424f, kf.GetValue(40).Y, 0.0001); - CHECK_CLOSE(4.0f, kf.GetValue(50).Y, 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); + CHECK_CLOSE(1.00023f, kf.GetValue(1), 0.0001); + CHECK_CLOSE(1.18398f, kf.GetValue(9), 0.0001); + CHECK_CLOSE(1.99988f, kf.GetValue(20), 0.0001); + CHECK_CLOSE(3.75424f, kf.GetValue(40), 0.0001); + CHECK_CLOSE(4.0f, kf.GetValue(50), 0.0001); // Check the expected number of values CHECK_EQUAL(kf.Values.size(), 51); } @@ -84,14 +84,14 @@ TEST(Keyframe_GetValue_For_Bezier_Curve_5_Points_40_Percent_Handle) kf.AddPoint(openshot::Point(Coordinate(200, 3), BEZIER)); // Spot check values from the curve - CHECK_CLOSE(kf.GetValue(-1).Y, 1.0f, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0).Y, 0.0001); - CHECK_CLOSE(1.00023f, kf.GetValue(1).Y, 0.0001); - CHECK_CLOSE(2.69174f, kf.GetValue(27).Y, 0.0001); - CHECK_CLOSE(7.46386f, kf.GetValue(77).Y, 0.0001); - CHECK_CLOSE(4.22691f, kf.GetValue(127).Y, 0.0001); - CHECK_CLOSE(1.73193f, kf.GetValue(177).Y, 0.0001); - CHECK_CLOSE(3.0f, kf.GetValue(200).Y, 0.0001); + CHECK_CLOSE(kf.GetValue(-1), 1.0f, 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); + CHECK_CLOSE(1.00023f, kf.GetValue(1), 0.0001); + CHECK_CLOSE(2.69174f, kf.GetValue(27), 0.0001); + CHECK_CLOSE(7.46386f, kf.GetValue(77), 0.0001); + CHECK_CLOSE(4.22691f, kf.GetValue(127), 0.0001); + CHECK_CLOSE(1.73193f, kf.GetValue(177), 0.0001); + CHECK_CLOSE(3.0f, kf.GetValue(200), 0.0001); // Check the expected number of values CHECK_EQUAL(kf.Values.size(), 201); } @@ -108,14 +108,14 @@ TEST(Keyframe_GetValue_For_Bezier_Curve_5_Points_25_Percent_Handle) kf.AddPoint(openshot::Point(Coordinate(200, 3), BEZIER)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1).Y, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0).Y, 0.0001); - CHECK_CLOSE(1.0009f, kf.GetValue(1).Y, 0.0001); - CHECK_CLOSE(2.64678f, kf.GetValue(27).Y, 0.0001); - CHECK_CLOSE(7.37597f, kf.GetValue(77).Y, 0.0001); - CHECK_CLOSE(4.37339f, kf.GetValue(127).Y, 0.0001); - CHECK_CLOSE(1.68798f, kf.GetValue(177).Y, 0.0001); - CHECK_CLOSE(3.0f, kf.GetValue(200).Y, 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); + CHECK_CLOSE(1.0009f, kf.GetValue(1), 0.0001); + CHECK_CLOSE(2.64678f, kf.GetValue(27), 0.0001); + CHECK_CLOSE(7.37597f, kf.GetValue(77), 0.0001); + CHECK_CLOSE(4.37339f, kf.GetValue(127), 0.0001); + CHECK_CLOSE(1.68798f, kf.GetValue(177), 0.0001); + CHECK_CLOSE(3.0f, kf.GetValue(200), 0.0001); // Check the expected number of values CHECK_EQUAL(kf.Values.size(), 201); } @@ -130,13 +130,13 @@ TEST(Keyframe_GetValue_For_Linear_Curve_3_Points) kf.AddPoint(openshot::Point(Coordinate(50, 2), LINEAR)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1).Y, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0).Y, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(1).Y, 0.0001); - CHECK_CLOSE(3.33333f, kf.GetValue(9).Y, 0.0001); - CHECK_CLOSE(6.54167f, kf.GetValue(20).Y, 0.0001); - CHECK_CLOSE(4.4f, kf.GetValue(40).Y, 0.0001); - CHECK_CLOSE(2.0f, kf.GetValue(50).Y, 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(1), 0.0001); + CHECK_CLOSE(3.33333f, kf.GetValue(9), 0.0001); + CHECK_CLOSE(6.54167f, kf.GetValue(20), 0.0001); + CHECK_CLOSE(4.4f, kf.GetValue(40), 0.0001); + CHECK_CLOSE(2.0f, kf.GetValue(50), 0.0001); // Check the expected number of values CHECK_EQUAL(kf.Values.size(), 51); } @@ -151,14 +151,14 @@ TEST(Keyframe_GetValue_For_Constant_Curve_3_Points) kf.AddPoint(openshot::Point(Coordinate(50, 2), CONSTANT)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1).Y, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0).Y, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(1).Y, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(24).Y, 0.0001); - CHECK_CLOSE(8.0f, kf.GetValue(25).Y, 0.0001); - CHECK_CLOSE(8.0f, kf.GetValue(40).Y, 0.0001); - CHECK_CLOSE(8.0f, kf.GetValue(49).Y, 0.0001); - CHECK_CLOSE(2.0f, kf.GetValue(50).Y, 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(1), 0.0001); + CHECK_CLOSE(1.0f, kf.GetValue(24), 0.0001); + CHECK_CLOSE(8.0f, kf.GetValue(25), 0.0001); + CHECK_CLOSE(8.0f, kf.GetValue(40), 0.0001); + CHECK_CLOSE(8.0f, kf.GetValue(49), 0.0001); + CHECK_CLOSE(2.0f, kf.GetValue(50), 0.0001); // Check the expected number of values CHECK_EQUAL(kf.Values.size(), 51); }