Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_06 / src / synfig / valuenode_segcalctangent.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_segcalctangent.cpp
3 **      \brief Template File
4 **
5 **      $Id$
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 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "valuenode_segcalctangent.h"
33 #include "valuenode_const.h"
34 #include "valuenode_composite.h"
35 #include "general.h"
36 #include "exception.h"
37 #include <ETL/hermite>
38 #include <ETL/calculus>
39 #include "segment.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48
49 /* === M A C R O S ========================================================= */
50
51 /* === G L O B A L S ======================================================= */
52
53 /* === P R O C E D U R E S ================================================= */
54
55 /* === M E T H O D S ======================================================= */
56
57 ValueNode_SegCalcTangent::ValueNode_SegCalcTangent(const ValueBase::Type &x):
58         LinkableValueNode(x)
59 {
60         if(x!=ValueBase::TYPE_VECTOR)
61                 throw Exception::BadType(ValueBase::type_name(x));
62
63         segment_=ValueNode_Composite::create(ValueBase::TYPE_SEGMENT);
64         amount_=ValueNode_Const::create(Real(0.5));
65 }
66
67 ValueNode_SegCalcTangent*
68 ValueNode_SegCalcTangent::create(const ValueBase &x)
69 {
70         return new ValueNode_SegCalcTangent(x.get_type());
71 }
72
73 ValueNode_SegCalcTangent::~ValueNode_SegCalcTangent()
74 {
75         unlink_all();
76 }
77
78 ValueBase
79 ValueNode_SegCalcTangent::operator()(Time t)const
80 {
81         Segment segment((*segment_)(t).get(Segment()));
82
83         etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
84         etl::derivative< etl::hermite<Vector> > deriv(curve);
85
86 #ifdef ETL_FIXED_DERIVATIVE
87         return deriv((*amount_)(t).get(Real()))*(0.5);
88 #else
89         return deriv((*amount_)(t).get(Real()))*(-0.5);
90 #endif
91
92 }
93
94
95 String
96 ValueNode_SegCalcTangent::get_name()const
97 {
98         return "segcalctangent";
99 }
100
101 String
102 ValueNode_SegCalcTangent::get_local_name()const
103 {
104         return _("SegCalcTangent");
105 }
106
107 bool
108 ValueNode_SegCalcTangent::check_type(ValueBase::Type type)
109 {
110         return type==ValueBase::TYPE_VECTOR;
111 }
112
113 bool
114 ValueNode_SegCalcTangent::set_link_vfunc(int i,ValueNode::Handle x)
115 {
116         assert(i==0 || i==1);
117         if(i==0)
118         {
119                 segment_=x;
120                 signal_child_changed()(i);signal_value_changed()();
121                 return true;
122         }
123         if(i==1)
124         {
125                 amount_=x;
126                 signal_child_changed()(i);signal_value_changed()();
127                 return true;
128         }
129         return false;
130 }
131
132 ValueNode::LooseHandle
133 ValueNode_SegCalcTangent::get_link_vfunc(int i)const
134 {
135         assert(i==0 || i==1);
136         if(i==0)
137                 return segment_;
138         if(i==1)
139                 return amount_;
140
141         return 0;
142 }
143
144 int
145 ValueNode_SegCalcTangent::link_count()const
146 {
147         return 2;
148 }
149
150 String
151 ValueNode_SegCalcTangent::link_name(int i)const
152 {
153         assert(i==0 || i==1);
154         if(i==0)
155                 return "segment";
156         if(i==1)
157                 return "amount";
158         return String();
159 }
160
161 String
162 ValueNode_SegCalcTangent::link_local_name(int i)const
163 {
164         assert(i==0 || i==1);
165         if(i==0)
166                 return _("Segment");
167         if(i==1)
168                 return _("Amount");
169         return String();
170 }
171
172 int
173 ValueNode_SegCalcTangent::get_link_index_from_name(const String &name)const
174 {
175         if(name=="segment")
176                 return 0;
177         if(name=="amount")
178                 return 1;
179
180         throw Exception::BadLinkName(name);
181 }
182
183 LinkableValueNode*
184 ValueNode_SegCalcTangent::create_new()const
185 {
186         return new ValueNode_SegCalcTangent(ValueBase::TYPE_VECTOR);
187 }