1 /*! ========================================================================
2 ** Extended Template Library
3 ** Hermite Template Class Implementation
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
23 ** ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __ETL__HERMITE_H
28 #define __ETL__HERMITE_H
30 /* === H E A D E R S ======================================================= */
34 /* === M A C R O S ========================================================= */
36 /* === T Y P E D E F S ===================================================== */
38 /* === C L A S S E S & S T R U C T S ======================================= */
44 class hermite_base : std::unary_function<float,T>
48 typedef float time_type;
50 affine_combo<value_type,time_type> affine_func;
55 time_type drs; // reciprocal of (s-r)
57 hermite_base():r(0.0),s(1.0) { drs=1.0/(s-r); }
59 const value_type &a, const value_type &b, const value_type &c, const value_type &d,
60 const time_type &r=0.0, const time_type &s=1.0):
61 a(a),b(b),c(c),d(d),r(r),s(s) { sync(); }
67 _coeff[1]=-d*1 - c*2 + b*3 - a*3;
68 _coeff[2]= d*1 + c*1 - b*2 + a*2;
72 operator()(time_type t)const
73 { t-=r; t*=drs; return a + (_coeff[0]+(_coeff[1]+(_coeff[2])*t)*t)*t; }
75 void set_rs(time_type new_r, time_type new_s) { r=new_r; s=new_s; drs=1.0/(s-r); }
76 void set_r(time_type new_r) { r=new_r; drs=1.0/(s-r); }
77 void set_s(time_type new_s) { s=new_s; drs=1.0/(s-r); }
78 const time_type &get_r(void)const { return r; }
79 const time_type &get_s(void)const { return s; }
80 time_type get_dt(void)const { return s-r; }
87 operator[](int i) const
93 class hermite : public hermite_base<T>
97 typedef float time_type;
103 hermite(const value_type &p1, const value_type &p2, const value_type &t1, const value_type &t2):
104 P1(p1),P2(p2),T1(t1),T2(t2) { sync(); }
105 hermite(const value_type &p1, const value_type &p2):
106 P1(p1),P2(p2),T1(p2-p1),T2(p2-p1) { sync(); }
108 value_type P1,P2,T1,T2;
110 value_type &p1(void) { return P1; }
111 value_type &p2(void) { return P2; }
112 value_type &t1(void) { return T1; }
113 value_type &t2(void) { return T2; }
117 // hermite_base<T>::operator[](0)=P1;
118 // bezier<T>::operator[](1)=P1+T1/3;
119 // bezier<T>::operator[](2)=P2-T2/3;
120 // bezier<T>::operator[](3)=P2;
122 hermite_base<T>::operator[](0)=P1;
123 hermite_base<T>::operator[](1)=P2;
124 hermite_base<T>::operator[](2)=T1;
125 hermite_base<T>::operator[](3)=T2;
127 hermite_base<T>::sync();
134 template <typename V,typename T=float>
135 class hermite : public bezier<V,T>
138 typedef V value_type;
145 hermite(const value_type &p1, const value_type &p2, const value_type &t1, const value_type &t2):
146 P1(p1),P2(p2),T1(t1),T2(t2) { sync(); }
147 hermite(const value_type &p1, const value_type &p2):
148 P1(p1),P2(p2),T1(p2-p1),T2(p2-p1) { sync(); }
150 value_type P1,P2,T1,T2;
152 value_type &p1() { return P1; }
153 value_type &p2() { return P2; }
154 value_type &t1() { return T1; }
155 value_type &t2() { return T2; }
159 bezier<V,T>::operator[](0)=P1;
160 bezier<V,T>::operator[](1)=P1+T1/3;
161 bezier<V,T>::operator[](2)=P2-T2/3;
162 bezier<V,T>::operator[](3)=P2;
170 /* === E X T E R N S ======================================================= */
172 /* === E N D =============================================================== */