diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-09-05 13:03:19 +0300 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-09-05 13:22:12 +0300 |
commit | dc81b986f4aff9737796e3028cad8c41588d3687 (patch) | |
tree | f5dc5451e79f4bb15157a44ff6ddc9b35e150129 /src/system | |
parent | 3ca369a6ab81151b46898e34c8ddf6c5f429cde3 (diff) |
Add support to get a bezier curve extreme values
Add logic to get the extreme values of a curve segment. This is used by
the studio to fit an animation curve.
Change-Id: I65564802524bfd49793624a560d98cc67d22e055
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/system')
-rw-r--r-- | src/system/Qt3DSBezierEval.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/system/Qt3DSBezierEval.h b/src/system/Qt3DSBezierEval.h index ef99eec..8a6f6b0 100644 --- a/src/system/Qt3DSBezierEval.h +++ b/src/system/Qt3DSBezierEval.h @@ -166,4 +166,24 @@ inline float EvaluateBezierKeyframe(long inTime, long inTime1, float inValue1, l return 0.0; } +inline std::pair<float, float> getBezierCurveExtrema(float inTime1, float inValue1, + float inC1Time, float inC1Value, + float inC2Time, float inC2Value, + float inTime2, float inValue2) +{ + auto polynomial = CubicPolynomial(inValue1, inC1Value, inC2Value, inValue2); + + std::pair<float, float> extrema {-FLT_MAX, FLT_MAX}; // <max, min> + for (double t : polynomial.extrema()) { + const float val = float(evaluateForT(t, inValue1, inC1Value, inC2Value, inValue2)); + + if (val > extrema.first) + extrema.first = val; + if (val < extrema.second) + extrema.second = val; + } + + return extrema; +} + } // namespace Qt3DStudio |