From 266bd45bdeeb429571324253a0a81a8f185fea34 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Fri, 19 Oct 2012 22:24:54 -0500 Subject: [PATCH] Added delta() to a coordinate, to track the change in unique value on the Y axis. This helps in time mapping, to track how many frames have been skipped. --- include/Coordinate.h | 1 + include/KeyFrame.h | 3 +++ src/Coordinate.cpp | 4 ++-- src/KeyFrame.cpp | 29 +++++++++++++++++++++++++++-- tests/KeyFrame_Tests.cpp | 4 ++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/include/Coordinate.h b/include/Coordinate.h index 0c8973fe..44b9574a 100644 --- a/include/Coordinate.h +++ b/include/Coordinate.h @@ -32,6 +32,7 @@ namespace openshot { float Y; ///< The Y value of the coordinate bool increasing; ///< Is the Y value increasing or decreasing? Fraction repeated; ///< Fraction of repeated Y values (for example, 1/3 would be the first Y value of 3 repeated values) + float delta; ///< This difference in Y value (from the previous unique Y value) /// The default constructor, which defaults to (0,0) Coordinate(); diff --git a/include/KeyFrame.h b/include/KeyFrame.h index 2d4bbee0..b752ed55 100644 --- a/include/KeyFrame.h +++ b/include/KeyFrame.h @@ -102,6 +102,9 @@ namespace openshot { /// Get the fraction that represents how many times this value is repeated in the curve Fraction GetRepeatFraction(int index); + /// Get the change in Y value (from the previous Y value) + float GetDelta(int index); + /// Get a point at a specific index Point& GetPoint(int index) throw(OutOfBoundsPoint); diff --git a/src/Coordinate.cpp b/src/Coordinate.cpp index 6d494cde..aaa26e74 100644 --- a/src/Coordinate.cpp +++ b/src/Coordinate.cpp @@ -11,10 +11,10 @@ using namespace openshot; // Default constructor for a coordinate, which defaults the X and Y to zero (0,0) Coordinate::Coordinate() : - X(0), Y(0), increasing(true), repeated(1,1) { + X(0), Y(0), increasing(true), repeated(1,1), delta(0.0) { } // Constructor which also allows the user to set the X and Y Coordinate::Coordinate(float x, float y) : - X(x), Y(y), increasing(true), repeated(1,1) { + X(x), Y(y), increasing(true), repeated(1,1), delta(0.0) { } diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp index da7d5426..e3cfa7e5 100644 --- a/src/KeyFrame.cpp +++ b/src/KeyFrame.cpp @@ -234,6 +234,28 @@ Fraction Keyframe::GetRepeatFraction(int index) return Fraction(1,1); } +// Get the change in Y value (from the previous Y value) +float Keyframe::GetDelta(int index) +{ + // Check if it needs to be processed + if (needs_update) + Process(); + + // Is index a valid point? + if (index >= 0 && index < Values.size()) + // Return value + return Values[index].delta; + else if (index < 0 && Values.size() > 0) + // Return the minimum value + return Values[0].delta; + else if (index >= Values.size() && Values.size() > 0) + // return the maximum value + return Values[Values.size() - 1].delta; + else + // return a blank coordinate (0,0) + return 0.0; +} + // Get a point at a specific index Point& Keyframe::GetPoint(int index) throw(OutOfBoundsPoint) { // Is index a valid point? @@ -312,11 +334,11 @@ void Keyframe::PrintValues() { if (needs_update) Process(); - cout << " PRINT ALL VALUES " << endl; + cout << "Frame Number (X)\tValue (Y)\tIs Increasing\tRepeat Numerator\tRepeat Denominator\tDelta (Y Difference)" << endl; for (vector::iterator it = Values.begin() + 1; it != Values.end(); it++) { Coordinate c = *it; - cout << int(round(c.X)) << "\t" << int(round(c.Y)) << "\t" << c.increasing << "\t" << c.repeated.num << "\t" << c.repeated.den << endl; + cout << int(round(c.X)) << "\t" << int(round(c.Y)) << "\t" << c.increasing << "\t" << c.repeated.num << "\t" << c.repeated.den << "\t" << c.delta << endl; } } @@ -412,6 +434,9 @@ void Keyframe::Process() { (*it).repeated.num = repeat_count; (*it).repeated.den = repeat_count + additional_repeats; + // Set delta (i.e. different from previous unique Y value) + (*it).delta = current_value - last_value; + // track the last value last_value = current_value; } diff --git a/tests/KeyFrame_Tests.cpp b/tests/KeyFrame_Tests.cpp index 3a751490..69272f1e 100644 --- a/tests/KeyFrame_Tests.cpp +++ b/tests/KeyFrame_Tests.cpp @@ -176,19 +176,23 @@ TEST(Keyframe_Check_Direction_and_Repeat_Fractions) CHECK_EQUAL(kf.IsIncreasing(1), false); CHECK_EQUAL(kf.GetRepeatFraction(1).num, 1); CHECK_EQUAL(kf.GetRepeatFraction(1).den, 10); + CHECK_EQUAL(kf.GetDelta(1), 500); CHECK_EQUAL(kf.GetInt(24), 497); CHECK_EQUAL(kf.IsIncreasing(24), false); CHECK_EQUAL(kf.GetRepeatFraction(24).num, 2); CHECK_EQUAL(kf.GetRepeatFraction(24).den, 4); + CHECK_EQUAL(kf.GetDelta(24), 0); CHECK_EQUAL(kf.GetInt(390), 101); CHECK_EQUAL(kf.IsIncreasing(390), false); CHECK_EQUAL(kf.GetRepeatFraction(390).num, 8); CHECK_EQUAL(kf.GetRepeatFraction(390).den, 8); + CHECK_EQUAL(kf.GetDelta(390), 0); CHECK_EQUAL(kf.GetInt(391), 100); CHECK_EQUAL(kf.IsIncreasing(391), true); CHECK_EQUAL(kf.GetRepeatFraction(391).num, 1); CHECK_EQUAL(kf.GetRepeatFraction(391).den, 12); + CHECK_EQUAL(kf.GetDelta(391), -1); }