1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/nsSMILKeySpline.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NS_SMILKEYSPLINE_H_ 1.10 +#define NS_SMILKEYSPLINE_H_ 1.11 + 1.12 +/** 1.13 + * Utility class to provide scaling defined in a keySplines element. 1.14 + */ 1.15 +class nsSMILKeySpline 1.16 +{ 1.17 +public: 1.18 + nsSMILKeySpline() { /* caller must call Init later */ } 1.19 + 1.20 + /** 1.21 + * Creates a new key spline control point description. 1.22 + * 1.23 + * aX1, etc. are the x1, y1, x2, y2 cubic Bezier control points as defined by 1.24 + * SMILANIM 3.2.3. They must each be in the range 0.0 <= x <= 1.0 1.25 + */ 1.26 + nsSMILKeySpline(double aX1, double aY1, 1.27 + double aX2, double aY2) 1.28 + { 1.29 + Init(aX1, aY1, aX2, aY2); 1.30 + } 1.31 + 1.32 + double X1() const { return mX1; } 1.33 + double Y1() const { return mY1; } 1.34 + double X2() const { return mX2; } 1.35 + double Y2() const { return mY2; } 1.36 + 1.37 + void Init(double aX1, double aY1, 1.38 + double aX2, double aY2); 1.39 + 1.40 + /** 1.41 + * Gets the output (y) value for an input (x). 1.42 + * 1.43 + * @param aX The input x value. A floating-point number between 0 and 1.44 + * 1 (inclusive). 1.45 + */ 1.46 + double GetSplineValue(double aX) const; 1.47 + 1.48 + void GetSplineDerivativeValues(double aX, double& aDX, double& aDY) const; 1.49 + 1.50 +private: 1.51 + void 1.52 + CalcSampleValues(); 1.53 + 1.54 + /** 1.55 + * Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. 1.56 + */ 1.57 + static double 1.58 + CalcBezier(double aT, double aA1, double aA2); 1.59 + 1.60 + /** 1.61 + * Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. 1.62 + */ 1.63 + static double 1.64 + GetSlope(double aT, double aA1, double aA2); 1.65 + 1.66 + double 1.67 + GetTForX(double aX) const; 1.68 + 1.69 + double 1.70 + NewtonRaphsonIterate(double aX, double aGuessT) const; 1.71 + 1.72 + double 1.73 + BinarySubdivide(double aX, double aA, double aB) const; 1.74 + 1.75 + static double 1.76 + A(double aA1, double aA2) 1.77 + { 1.78 + return 1.0 - 3.0 * aA2 + 3.0 * aA1; 1.79 + } 1.80 + 1.81 + static double 1.82 + B(double aA1, double aA2) 1.83 + { 1.84 + return 3.0 * aA2 - 6.0 * aA1; 1.85 + } 1.86 + 1.87 + static double 1.88 + C(double aA1) 1.89 + { 1.90 + return 3.0 * aA1; 1.91 + } 1.92 + 1.93 + double mX1; 1.94 + double mY1; 1.95 + double mX2; 1.96 + double mY2; 1.97 + 1.98 + enum { kSplineTableSize = 11 }; 1.99 + double mSampleValues[kSplineTableSize]; 1.100 + 1.101 + static const double kSampleStepSize; 1.102 +}; 1.103 + 1.104 +#endif // NS_SMILKEYSPLINE_H_