| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 |
| 19 | #ifndef VINTERPOLATOR_H |
| 20 | #define VINTERPOLATOR_H |
| 21 |
| 22 | #include "vpoint.h" |
| 23 |
| 24 | V_BEGIN_NAMESPACE |
| 25 |
| 26 | class VInterpolator { |
| 27 | public: |
| 28 | VInterpolator() |
| 29 | { /* caller must call Init later */ |
| 30 | } |
| 31 |
| 32 | VInterpolator(float aX1, float aY1, float aX2, float aY2) |
| 33 | { |
| 34 | init(aX1, aY1, aX2, aY2); |
| 35 | } |
| 36 |
| 37 | VInterpolator(VPointF pt1, VPointF pt2) |
| 38 | { |
| 39 | init(pt1.x(), pt1.y(), pt2.x(), pt2.y()); |
| 40 | } |
| 41 |
| 42 | void init(float aX1, float aY1, float aX2, float aY2); |
| 43 |
| 44 | float value(float aX) const; |
| 45 |
| 46 | void GetSplineDerivativeValues(float aX, float& aDX, float& aDY) const; |
| 47 |
| 48 | private: |
| 49 | void CalcSampleValues(); |
| 50 |
| 51 | /** |
| 52 | * Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. |
| 53 | */ |
| 54 | static float CalcBezier(float aT, float aA1, float aA2); |
| 55 |
| 56 | /** |
| 57 | * Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. |
| 58 | */ |
| 59 | static float GetSlope(float aT, float aA1, float aA2); |
| 60 |
| 61 | float GetTForX(float aX) const; |
| 62 |
| 63 | float NewtonRaphsonIterate(float aX, float aGuessT) const; |
| 64 |
| 65 | float BinarySubdivide(float aX, float aA, float aB) const; |
| 66 |
| 67 | static float A(float aA1, float aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; } |
| 68 |
| 69 | static float B(float aA1, float aA2) { return 3.0 * aA2 - 6.0 * aA1; } |
| 70 |
| 71 | static float C(float aA1) { return 3.0 * aA1; } |
| 72 |
| 73 | float mX1; |
| 74 | float mY1; |
| 75 | float mX2; |
| 76 | float mY2; |
| 77 | enum { kSplineTableSize = 11 }; |
| 78 | float mSampleValues[kSplineTableSize]; |
| 79 | static const float kSampleStepSize; |
| 80 | }; |
| 81 |
| 82 | V_END_NAMESPACE |
| 83 |
| 84 | #endif // VINTERPOLATOR_H |
| 85 |