1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Mozilla SMIL module.
16 : *
17 : * The Initial Developer of the Original Code is Brian Birtles.
18 : * Portions created by the Initial Developer are Copyright (C) 2005
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Brian Birtles <birtles@gmail.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef NS_SMILKEYSPLINE_H_
39 : #define NS_SMILKEYSPLINE_H_
40 :
41 : /**
42 : * Utility class to provide scaling defined in a keySplines element.
43 : */
44 : class nsSMILKeySpline
45 0 : {
46 : public:
47 : nsSMILKeySpline() { /* caller must call Init later */ }
48 :
49 : /**
50 : * Creates a new key spline control point description.
51 : *
52 : * aX1, etc. are the x1, y1, x2, y2 cubic Bezier control points as defined by
53 : * SMILANIM 3.2.3. They must each be in the range 0.0 <= x <= 1.0
54 : */
55 0 : nsSMILKeySpline(double aX1, double aY1,
56 : double aX2, double aY2)
57 : {
58 0 : Init(aX1, aY1, aX2, aY2);
59 0 : }
60 :
61 : void Init(double aX1, double aY1,
62 : double aX2, double aY2);
63 :
64 : /**
65 : * Gets the output (y) value for an input (x).
66 : *
67 : * @param aX The input x value. A floating-point number between 0 and
68 : * 1 (inclusive).
69 : */
70 : double GetSplineValue(double aX) const;
71 :
72 : void GetSplineDerivativeValues(double aX, double& aDX, double& aDY) const;
73 :
74 : private:
75 : void
76 : CalcSampleValues();
77 :
78 : /**
79 : * Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
80 : */
81 : static double
82 : CalcBezier(double aT, double aA1, double aA2);
83 :
84 : /**
85 : * Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
86 : */
87 : static double
88 : GetSlope(double aT, double aA1, double aA2);
89 :
90 : double
91 : GetTForX(double aX) const;
92 :
93 : double
94 : NewtonRaphsonIterate(double aX, double aGuessT) const;
95 :
96 : double
97 : BinarySubdivide(double aX, double aA, double aB) const;
98 :
99 : static double
100 0 : A(double aA1, double aA2)
101 : {
102 0 : return 1.0 - 3.0 * aA2 + 3.0 * aA1;
103 : }
104 :
105 : static double
106 0 : B(double aA1, double aA2)
107 : {
108 0 : return 3.0 * aA2 - 6.0 * aA1;
109 : }
110 :
111 : static double
112 0 : C(double aA1)
113 : {
114 0 : return 3.0 * aA1;
115 : }
116 :
117 : double mX1;
118 : double mY1;
119 : double mX2;
120 : double mY2;
121 :
122 : enum { kSplineTableSize = 11 };
123 : double mSampleValues[kSplineTableSize];
124 :
125 : static const double kSampleStepSize;
126 : };
127 :
128 : #endif // NS_SMILKEYSPLINE_H_
|