lottie/vector: move pixman code to separate pixman folder.
[platform/core/uifw/lottie-player.git] / src / vector / vinterpolator.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef VINTERPOLATOR_H
18 #define VINTERPOLATOR_H
19
20 #include "vpoint.h"
21
22 V_BEGIN_NAMESPACE
23
24 class VInterpolator {
25 public:
26     VInterpolator()
27     { /* caller must call Init later */
28     }
29
30     VInterpolator(float aX1, float aY1, float aX2, float aY2)
31     {
32         init(aX1, aY1, aX2, aY2);
33     }
34
35     VInterpolator(VPointF pt1, VPointF pt2)
36     {
37         init(pt1.x(), pt1.y(), pt2.x(), pt2.y());
38     }
39
40     void init(float aX1, float aY1, float aX2, float aY2);
41
42     float value(float aX) const;
43
44     void GetSplineDerivativeValues(float aX, float& aDX, float& aDY) const;
45
46 private:
47     void CalcSampleValues();
48
49     /**
50      * Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
51      */
52     static float CalcBezier(float aT, float aA1, float aA2);
53
54     /**
55      * Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
56      */
57     static float GetSlope(float aT, float aA1, float aA2);
58
59     float GetTForX(float aX) const;
60
61     float NewtonRaphsonIterate(float aX, float aGuessT) const;
62
63     float BinarySubdivide(float aX, float aA, float aB) const;
64
65     static float A(float aA1, float aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
66
67     static float B(float aA1, float aA2) { return 3.0 * aA2 - 6.0 * aA1; }
68
69     static float C(float aA1) { return 3.0 * aA1; }
70
71     float mX1;
72     float mY1;
73     float mX2;
74     float mY2;
75     enum { kSplineTableSize = 11 };
76     float              mSampleValues[kSplineTableSize];
77     static const float kSampleStepSize;
78 };
79
80 V_END_NAMESPACE
81
82 #endif  // VINTERPOLATOR_H