Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_05 / synfig-studio / src / synfigapp / blineconvert.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file blineconvert.h
3 **      \brief Template Header
4 **
5 **      $Id: blineconvert.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_BLINE_CONVERT_H
26 #define __SYNFIG_BLINE_CONVERT_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <synfig/general.h>
31 #include <synfig/blinepoint.h>
32 #include <list>
33 #include <vector>
34
35 /* === M A C R O S ========================================================= */
36
37 /* === T Y P E D E F S ===================================================== */
38
39 /* === C L A S S E S & S T R U C T S ======================================= */
40
41 namespace synfigapp {
42         
43 class BLineConverter
44 {
45 public:
46         struct cpindex
47         {
48                 int             curind;
49                 synfig::Real    tangentscale;
50                 synfig::Real    error;  //negative error will indicate invalid;
51                 
52                 cpindex(int ci, synfig::Real s=0, synfig::Real e=-1) 
53                 :curind(ci), tangentscale(s), error(e) 
54                 {}
55                 
56                 cpindex(const cpindex & o)
57                 :curind(o.curind), tangentscale(o.tangentscale), error(o.error) 
58                 {}
59                 
60                 const cpindex & operator = (const cpindex & rhs)
61                 {
62                         curind = rhs.curind;
63                         tangentscale = rhs.tangentscale;
64                         error = rhs.error;
65                         return *this;
66                 }
67                 
68                 bool operator < (const cpindex &rhs) const
69                 {
70                         return curind < rhs.curind;             
71                 }
72                 
73                 //point is obviously in[curind]
74                 //tangent scale will get reset to the smallest (or something else depending on experimentation)
75         };
76
77 private:
78         //cached data
79         std::vector<synfig::Point>      f;      //the preprocessed input cache
80         std::vector<synfig::Real>       f_w;
81
82         //temporary point storage for vector calc
83         std::vector<synfig::Point>      ftemp;
84         
85         std::vector<synfig::Vector>     df; //the derivative cache      
86         std::vector<synfig::Real>       cvt; //the curvature cache
87         
88         std::vector<int>                        brk; //the break point cache
89         
90         std::vector<synfig::Real>       di,     //cumulative distance
91                                                                 d_i; //distance between adjacent segments
92         
93         std::vector<synfig::Point>      work; //the working point cache for the entire curve
94         std::vector<cpindex>            curind;
95         
96         //function parameters
97         void clear();
98
99 public:
100         synfig::Real width;
101
102         //Converter properties
103         synfig::Real pixelwidth;
104         synfig::Real smoothness; //actual error will be smoothness*pixelwidth (for global set pixelwidth = 1)
105
106         BLineConverter();
107
108         static void EnforceMinWidth(std::list<synfig::BLinePoint> &bline, synfig::Real min_pressure);
109         void operator ()(std::list<synfig::BLinePoint> &out, const std::list<synfig::Point> &in,const std::list<synfig::Real> &in_w);
110 };
111         
112 }; // END of namespace synfigapp
113
114 /* === E N D =============================================================== */
115
116 #endif