2013-09-12 23:41:49 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Unit tests for openshot::Keyframe
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-12 23:41:49 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-12 23:41:49 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-12 23:41:49 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-12 23:41:49 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-12 23:41:49 -05:00
|
|
|
*/
|
|
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
#include "UnitTest++.h"
|
2019-10-27 03:54:36 -04:00
|
|
|
// Prevent name clashes with juce::UnitTest
|
|
|
|
|
#define DONT_SET_USING_JUCE_NAMESPACE 1
|
2011-10-11 08:44:27 -05:00
|
|
|
#include "../include/OpenShot.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace openshot;
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetPoint_With_No_Points)
|
|
|
|
|
{
|
|
|
|
|
// Create an empty keyframe
|
|
|
|
|
Keyframe k1;
|
|
|
|
|
|
|
|
|
|
CHECK_THROW(k1.GetPoint(0), OutOfBoundsPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetPoint_With_1_Points)
|
|
|
|
|
{
|
|
|
|
|
// Create an empty keyframe
|
|
|
|
|
Keyframe k1;
|
|
|
|
|
k1.AddPoint(openshot::Point(2,3));
|
|
|
|
|
|
|
|
|
|
CHECK_THROW(k1.GetPoint(-1), OutOfBoundsPoint);
|
2019-11-19 23:43:28 +01:00
|
|
|
CHECK_EQUAL(1, k1.GetCount());
|
2011-10-11 08:44:27 -05:00
|
|
|
CHECK_CLOSE(2.0f, k1.GetPoint(0).co.X, 0.00001);
|
|
|
|
|
CHECK_CLOSE(3.0f, k1.GetPoint(0).co.Y, 0.00001);
|
|
|
|
|
CHECK_THROW(k1.GetPoint(1), OutOfBoundsPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_AddPoint_With_1_Point)
|
|
|
|
|
{
|
|
|
|
|
// Create an empty keyframe
|
|
|
|
|
Keyframe k1;
|
|
|
|
|
k1.AddPoint(openshot::Point(2,9));
|
|
|
|
|
|
|
|
|
|
CHECK_CLOSE(2.0f, k1.GetPoint(0).co.X, 0.00001);
|
|
|
|
|
CHECK_THROW(k1.GetPoint(-1), OutOfBoundsPoint);
|
|
|
|
|
CHECK_THROW(k1.GetPoint(1), OutOfBoundsPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_AddPoint_With_2_Points)
|
|
|
|
|
{
|
|
|
|
|
// Create an empty keyframe
|
|
|
|
|
Keyframe k1;
|
|
|
|
|
k1.AddPoint(openshot::Point(2,9));
|
|
|
|
|
k1.AddPoint(openshot::Point(5,20));
|
|
|
|
|
|
|
|
|
|
CHECK_CLOSE(2.0f, k1.GetPoint(0).co.X, 0.00001);
|
|
|
|
|
CHECK_CLOSE(5.0f, k1.GetPoint(1).co.X, 0.00001);
|
|
|
|
|
CHECK_THROW(k1.GetPoint(-1), OutOfBoundsPoint);
|
|
|
|
|
CHECK_THROW(k1.GetPoint(2), OutOfBoundsPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetValue_For_Bezier_Curve_2_Points)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(50, 4), BEZIER));
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
2012-10-04 15:07:29 -05:00
|
|
|
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);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_CLOSE(1.14025f, kf.GetValue(9), 0.0001);
|
|
|
|
|
CHECK_CLOSE(1.91492f, kf.GetValue(20), 0.0001);
|
|
|
|
|
CHECK_CLOSE(3.81602f, kf.GetValue(40), 0.0001);
|
2012-10-04 15:07:29 -05:00
|
|
|
CHECK_CLOSE(4.0f, kf.GetValue(50), 0.0001);
|
2011-10-11 08:44:27 -05:00
|
|
|
// Check the expected number of values
|
2019-11-19 23:43:28 +01:00
|
|
|
CHECK_EQUAL(kf.GetLength(), 51);
|
2011-10-11 08:44:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetValue_For_Bezier_Curve_5_Points_40_Percent_Handle)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(50, 4), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(100, 10), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(150, 0), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(200, 3), BEZIER));
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
2012-10-04 15:07:29 -05:00
|
|
|
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);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_CLOSE(2.73656f, kf.GetValue(27), 0.0001);
|
|
|
|
|
CHECK_CLOSE(7.55139f, kf.GetValue(77), 0.0001);
|
|
|
|
|
CHECK_CLOSE(4.08102f, kf.GetValue(127), 0.0001);
|
|
|
|
|
CHECK_CLOSE(1.77569f, kf.GetValue(177), 0.0001);
|
2012-10-04 15:07:29 -05:00
|
|
|
CHECK_CLOSE(3.0f, kf.GetValue(200), 0.0001);
|
2011-10-11 08:44:27 -05:00
|
|
|
// Check the expected number of values
|
2019-11-19 23:43:28 +01:00
|
|
|
CHECK_EQUAL(kf.GetLength(), 201);
|
2011-10-11 08:44:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetValue_For_Bezier_Curve_5_Points_25_Percent_Handle)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(50, 4), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(100, 10), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(150, 0), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(200, 3), BEZIER));
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
2012-10-04 15:07:29 -05:00
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001);
|
|
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_CLOSE(1.00023f, kf.GetValue(1), 0.0001);
|
|
|
|
|
CHECK_CLOSE(2.73656f, kf.GetValue(27), 0.0001);
|
|
|
|
|
CHECK_CLOSE(7.55139f, kf.GetValue(77), 0.0001);
|
|
|
|
|
CHECK_CLOSE(4.08102f, kf.GetValue(127), 0.0001);
|
|
|
|
|
CHECK_CLOSE(1.77569f, kf.GetValue(177), 0.0001);
|
2012-10-04 15:07:29 -05:00
|
|
|
CHECK_CLOSE(3.0f, kf.GetValue(200), 0.0001);
|
2011-10-11 08:44:27 -05:00
|
|
|
// Check the expected number of values
|
2019-11-19 23:43:28 +01:00
|
|
|
CHECK_EQUAL(kf.GetLength(), 201);
|
2011-10-11 08:44:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetValue_For_Linear_Curve_3_Points)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), LINEAR));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(25, 8), LINEAR));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(50, 2), LINEAR));
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
2012-10-04 15:07:29 -05:00
|
|
|
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);
|
2011-10-11 08:44:27 -05:00
|
|
|
// Check the expected number of values
|
2019-11-19 23:43:28 +01:00
|
|
|
CHECK_EQUAL(kf.GetLength(), 51);
|
2011-10-11 08:44:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetValue_For_Constant_Curve_3_Points)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), CONSTANT));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(25, 8), CONSTANT));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(50, 2), CONSTANT));
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
2012-10-04 15:07:29 -05:00
|
|
|
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);
|
2011-10-11 08:44:27 -05:00
|
|
|
// Check the expected number of values
|
2019-11-19 23:43:28 +01:00
|
|
|
CHECK_EQUAL(kf.GetLength(), 51);
|
2011-10-11 08:44:27 -05:00
|
|
|
}
|
2012-10-19 22:11:22 -05:00
|
|
|
|
|
|
|
|
TEST(Keyframe_Check_Direction_and_Repeat_Fractions)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(1, 500);
|
|
|
|
|
kf.AddPoint(400, 100);
|
|
|
|
|
kf.AddPoint(500, 500);
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetInt(1), 500);
|
|
|
|
|
CHECK_EQUAL(kf.IsIncreasing(1), false);
|
|
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(1).num, 1);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(1).den, 12);
|
2012-10-19 22:24:54 -05:00
|
|
|
CHECK_EQUAL(kf.GetDelta(1), 500);
|
2012-10-19 22:11:22 -05:00
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_EQUAL(kf.GetInt(24), 498);
|
2012-10-19 22:11:22 -05:00
|
|
|
CHECK_EQUAL(kf.IsIncreasing(24), false);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(24).num, 3);
|
|
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(24).den, 6);
|
2012-10-19 22:24:54 -05:00
|
|
|
CHECK_EQUAL(kf.GetDelta(24), 0);
|
2012-10-19 22:11:22 -05:00
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_EQUAL(kf.GetLong(390), 100);
|
|
|
|
|
CHECK_EQUAL(kf.IsIncreasing(390), true);
|
|
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(390).num, 3);
|
|
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(390).den, 15);
|
2012-10-19 22:24:54 -05:00
|
|
|
CHECK_EQUAL(kf.GetDelta(390), 0);
|
2012-10-19 22:11:22 -05:00
|
|
|
|
2015-08-24 01:05:48 -05:00
|
|
|
CHECK_EQUAL(kf.GetLong(391), 100);
|
2012-10-19 22:11:22 -05:00
|
|
|
CHECK_EQUAL(kf.IsIncreasing(391), true);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(391).num, 4);
|
|
|
|
|
CHECK_EQUAL(kf.GetRepeatFraction(391).den, 15);
|
|
|
|
|
CHECK_EQUAL(kf.GetDelta(388), -1);
|
2012-10-19 22:11:22 -05:00
|
|
|
}
|
2015-02-22 01:04:54 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_Get_Closest_Point)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(1, 0.0);
|
|
|
|
|
kf.AddPoint(1000, 1.0);
|
|
|
|
|
kf.AddPoint(2500, 0.0);
|
|
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
// Spot check values from the curve (to the right)
|
2015-02-22 01:04:54 -06:00
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(900, 900)).co.X, 1000);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(1, 1)).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(5, 5)).co.X, 1000);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(1000, 1000)).co.X, 1000);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(1001, 1001)).co.X, 2500);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(2500, 2500)).co.X, 2500);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(3000, 3000)).co.X, 2500);
|
|
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
// Spot check values from the curve (to the left)
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(900, 900), true).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(1, 1), true).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(5, 5), true).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(1000, 1000), true).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(1001, 1001), true).co.X, 1000);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(2500, 2500), true).co.X, 1000);
|
|
|
|
|
CHECK_EQUAL(kf.GetClosestPoint(openshot::Point(3000, 3000), true).co.X, 2500);
|
2015-02-22 01:04:54 -06:00
|
|
|
}
|
2015-03-13 23:19:55 -05:00
|
|
|
|
2016-09-17 17:14:27 -05:00
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
TEST(Keyframe_Get_Previous_Point)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(1, 0.0);
|
|
|
|
|
kf.AddPoint(1000, 1.0);
|
|
|
|
|
kf.AddPoint(2500, 0.0);
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(900, 900))).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1, 1))).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(5, 5))).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1000, 1000))).co.X, 1);
|
|
|
|
|
CHECK_EQUAL(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1001, 1001))).co.X, 1000);
|
|
|
|
|
CHECK_EQUAL(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(2500, 2500))).co.X, 1000);
|
|
|
|
|
CHECK_EQUAL(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(3000, 3000))).co.X, 1000);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 17:14:27 -05:00
|
|
|
TEST(Keyframe_Get_Max_Point)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(1, 1.0);
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetMaxPoint().co.Y, 1.0);
|
|
|
|
|
|
|
|
|
|
kf.AddPoint(2, 0.0);
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetMaxPoint().co.Y, 1.0);
|
|
|
|
|
|
|
|
|
|
kf.AddPoint(3, 2.0);
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetMaxPoint().co.Y, 2.0);
|
|
|
|
|
|
|
|
|
|
kf.AddPoint(4, 1.0);
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetMaxPoint().co.Y, 2.0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 23:19:55 -05:00
|
|
|
TEST(Keyframe_Scale_Keyframe)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(25, 8), BEZIER));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(50, 2), BEZIER));
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01);
|
|
|
|
|
CHECK_CLOSE(7.99f, kf.GetValue(24), 0.01);
|
|
|
|
|
CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_CLOSE(3.68f, kf.GetValue(40), 0.01);
|
2015-03-13 23:19:55 -05:00
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(49), 0.01);
|
|
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01);
|
|
|
|
|
|
|
|
|
|
// Resize / Scale the keyframe
|
|
|
|
|
kf.ScalePoints(2.0); // 100% larger
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_CLOSE(4.21f, kf.GetValue(24), 0.01);
|
|
|
|
|
CHECK_CLOSE(4.47f, kf.GetValue(25), 0.01);
|
|
|
|
|
CHECK_CLOSE(7.57f, kf.GetValue(40), 0.01);
|
2015-03-13 23:19:55 -05:00
|
|
|
CHECK_CLOSE(7.99f, kf.GetValue(49), 0.01);
|
|
|
|
|
CHECK_CLOSE(8.0f, kf.GetValue(50), 0.01);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_CLOSE(2.35f, kf.GetValue(90), 0.01);
|
2015-03-13 23:19:55 -05:00
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(100), 0.01);
|
|
|
|
|
|
|
|
|
|
// Resize / Scale the keyframe
|
|
|
|
|
kf.ScalePoints(0.5); // 50% smaller, which should match the original size
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01);
|
|
|
|
|
CHECK_CLOSE(7.99f, kf.GetValue(24), 0.01);
|
|
|
|
|
CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01);
|
2016-10-19 02:19:07 -05:00
|
|
|
CHECK_CLOSE(3.68f, kf.GetValue(40), 0.01);
|
2015-03-13 23:19:55 -05:00
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(49), 0.01);
|
|
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_Flip_Keyframe)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), LINEAR));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(25, 8), LINEAR));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(50, 2), LINEAR));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(100, 10), LINEAR));
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01);
|
|
|
|
|
CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01);
|
|
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01);
|
|
|
|
|
CHECK_CLOSE(10.0f, kf.GetValue(100), 0.01);
|
|
|
|
|
|
|
|
|
|
// Flip the points
|
|
|
|
|
kf.FlipPoints();
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_CLOSE(10.0f, kf.GetValue(1), 0.01);
|
|
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(25), 0.01);
|
|
|
|
|
CHECK_CLOSE(8.0f, kf.GetValue(50), 0.01);
|
|
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(100), 0.01);
|
|
|
|
|
|
|
|
|
|
// Flip the points again (back to the original)
|
|
|
|
|
kf.FlipPoints();
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01);
|
|
|
|
|
CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01);
|
|
|
|
|
CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01);
|
|
|
|
|
CHECK_CLOSE(10.0f, kf.GetValue(100), 0.01);
|
|
|
|
|
}
|
2015-12-15 18:12:24 -06:00
|
|
|
|
|
|
|
|
TEST(Keyframe_Remove_Duplicate_Point)
|
|
|
|
|
{
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(1, 0.0);
|
|
|
|
|
kf.AddPoint(1, 1.0);
|
|
|
|
|
kf.AddPoint(1, 2.0);
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetLength(), 1);
|
|
|
|
|
CHECK_CLOSE(kf.GetPoint(0).co.Y, 2.0, 0.01);
|
2019-03-06 15:35:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_Large_Number_Values)
|
|
|
|
|
{
|
|
|
|
|
// Large value
|
|
|
|
|
int64_t large_value = 30 * 60 * 90;
|
|
|
|
|
|
|
|
|
|
// Create a keyframe curve with 2 points
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(1, 1.0);
|
|
|
|
|
kf.AddPoint(large_value, 100.0); // 90 minutes long
|
|
|
|
|
|
|
|
|
|
// Spot check values from the curve
|
|
|
|
|
CHECK_EQUAL(kf.GetLength(), large_value + 1);
|
|
|
|
|
CHECK_CLOSE(kf.GetPoint(0).co.Y, 1.0, 0.01);
|
|
|
|
|
CHECK_CLOSE(kf.GetPoint(1).co.Y, 100.0, 0.01);
|
2019-10-27 03:54:36 -04:00
|
|
|
}
|
2019-11-22 22:34:22 +01:00
|
|
|
|
|
|
|
|
TEST(Keyframe_Remove_Point)
|
|
|
|
|
{
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(1, 1), CONSTANT));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(3, 100), CONSTANT));
|
|
|
|
|
CHECK_EQUAL(1, kf.GetInt(2));
|
|
|
|
|
kf.AddPoint(openshot::Point(Coordinate(2, 50), CONSTANT));
|
|
|
|
|
CHECK_EQUAL(50, kf.GetInt(2));
|
|
|
|
|
kf.RemovePoint(1); // This is the index of point with X == 2
|
|
|
|
|
CHECK_EQUAL(1, kf.GetInt(2));
|
|
|
|
|
CHECK_THROW(kf.RemovePoint(100), OutOfBoundsPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_Constant_Interpolation_First_Segment)
|
|
|
|
|
{
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(Point(Coordinate(1, 1), CONSTANT));
|
|
|
|
|
kf.AddPoint(Point(Coordinate(2, 50), CONSTANT));
|
|
|
|
|
kf.AddPoint(Point(Coordinate(3, 100), CONSTANT));
|
|
|
|
|
CHECK_EQUAL(1, kf.GetInt(0));
|
|
|
|
|
CHECK_EQUAL(1, kf.GetInt(1));
|
|
|
|
|
CHECK_EQUAL(50, kf.GetInt(2));
|
|
|
|
|
CHECK_EQUAL(100, kf.GetInt(3));
|
|
|
|
|
CHECK_EQUAL(100, kf.GetInt(4));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_isIncreasing)
|
|
|
|
|
{
|
|
|
|
|
// Which cases need to be tested to keep same behaviour as
|
|
|
|
|
// previously?
|
|
|
|
|
//
|
|
|
|
|
// - "invalid point" => true
|
|
|
|
|
// - point where all next values are equal => false
|
|
|
|
|
// - point where first non-eq next value is smaller => false
|
|
|
|
|
// - point where first non-eq next value is larger => true
|
|
|
|
|
Keyframe kf;
|
|
|
|
|
kf.AddPoint(1, 1, LINEAR); // testing with linear
|
|
|
|
|
kf.AddPoint(3, 5, BEZIER); // testing with bezier
|
|
|
|
|
kf.AddPoint(6, 10, CONSTANT); // first non-eq is smaller
|
|
|
|
|
kf.AddPoint(8, 8, CONSTANT); // first non-eq is larger
|
|
|
|
|
kf.AddPoint(10, 10, CONSTANT); // all next values are equal
|
|
|
|
|
kf.AddPoint(15, 10, CONSTANT);
|
|
|
|
|
|
|
|
|
|
// "invalid points"
|
|
|
|
|
CHECK_EQUAL(true, kf.IsIncreasing(0));
|
|
|
|
|
CHECK_EQUAL(true, kf.IsIncreasing(15));
|
|
|
|
|
// all next equal
|
|
|
|
|
CHECK_EQUAL(false, kf.IsIncreasing(12));
|
|
|
|
|
// first non-eq is larger
|
|
|
|
|
CHECK_EQUAL(true, kf.IsIncreasing(8));
|
|
|
|
|
// first non-eq is smaller
|
|
|
|
|
CHECK_EQUAL(false, kf.IsIncreasing(6));
|
|
|
|
|
// bezier and linear
|
|
|
|
|
CHECK_EQUAL(true, kf.IsIncreasing(4));
|
|
|
|
|
CHECK_EQUAL(true, kf.IsIncreasing(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_GetLength)
|
|
|
|
|
{
|
|
|
|
|
Keyframe f;
|
|
|
|
|
CHECK_EQUAL(0, f.GetLength());
|
|
|
|
|
f.AddPoint(1, 1);
|
|
|
|
|
CHECK_EQUAL(1, f.GetLength());
|
|
|
|
|
f.AddPoint(2, 1);
|
|
|
|
|
CHECK_EQUAL(3, f.GetLength());
|
|
|
|
|
f.AddPoint(200, 1);
|
|
|
|
|
CHECK_EQUAL(201, f.GetLength());
|
|
|
|
|
|
|
|
|
|
Keyframe g;
|
|
|
|
|
g.AddPoint(200, 1);
|
|
|
|
|
CHECK_EQUAL(1, g.GetLength());
|
|
|
|
|
g.AddPoint(1,1);
|
|
|
|
|
CHECK_EQUAL(201, g.GetLength());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Keyframe_Use_Interpolation_of_Segment_End_Point)
|
|
|
|
|
{
|
|
|
|
|
Keyframe f;
|
|
|
|
|
f.AddPoint(1,0, CONSTANT);
|
|
|
|
|
f.AddPoint(100,155, BEZIER);
|
|
|
|
|
CHECK_CLOSE(75.9, f.GetValue(50), 0.1);
|
|
|
|
|
}
|