Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / ETL / tags / 0.04.12 / ETL / _curve_func.h
1 /*! ========================================================================
2 ** Extended Template and Library
3 ** Utility Curve Template Class Implementations
4 ** $Id$
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 **
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.
12 **
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.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
22 **
23 ** ========================================================================= */
24
25 /* === S T A R T =========================================================== */
26
27 #ifndef __ETL__CURVE_FUNC_H
28 #define __ETL__CURVE_FUNC_H
29
30 /* === H E A D E R S ======================================================= */
31
32 #include <functional>
33
34 /* -- C L A S S E S --------------------------------------------------------- */
35
36 template <class T, class K=float>
37 struct affine_combo
38 {
39         // from (a) to (x) : x = a(1-t) + b(t)
40         T operator()(const T &a,const T &b,const K &t)const
41         {
42                 return T( (b-a)*t+a );
43         }
44
45         // from (x) to (a) : a = (x-b(t)) / (1-t)
46         T reverse(const T &x, const T &b, const K &t)const
47         {
48                 return T( (x-t*b)*(static_cast<K>(1)/(static_cast<K>(1)-t)) );
49         }
50 };
51
52 template <class T, class K=float>
53 struct distance_func : public std::binary_function<T, T, K>
54 {
55         K operator()(const T &a,const T &b)const
56         {
57                 T delta=b-a;
58                 return static_cast<K>(delta*delta);
59         }
60
61         K cook(const K &x)const { return x*x; }
62         K uncook(const K &x)const { return sqrt(x); }
63
64 };
65
66 /* -- E N D ----------------------------------------------------------------- */
67
68 #endif