Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc3 / 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 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenode_segcalctangent.h"
34 #include "valuenode_const.h"
35 #include "valuenode_composite.h"
36 #include "general.h"
37 #include "exception.h"
38 #include <ETL/hermite>
39 #include <ETL/calculus>
40 #include "segment.h"
41
42 #endif
43
44 /* === U S I N G =========================================================== */
45
46 using namespace std;
47 using namespace etl;
48 using namespace synfig;
49
50 /* === M A C R O S ========================================================= */
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 ValueNode_SegCalcTangent::ValueNode_SegCalcTangent(const ValueBase::Type &x):
59         LinkableValueNode(x)
60 {
61         if(x!=ValueBase::TYPE_VECTOR)
62                 throw Exception::BadType(ValueBase::type_name(x));
63
64         set_link("segment",ValueNode_Const::create(ValueBase::TYPE_SEGMENT));
65         set_link("amount",ValueNode_Const::create(Real(0.5)));
66 }
67
68 ValueNode_SegCalcTangent*
69 ValueNode_SegCalcTangent::create(const ValueBase &x)
70 {
71         return new ValueNode_SegCalcTangent(x.get_type());
72 }
73
74 ValueNode_SegCalcTangent::~ValueNode_SegCalcTangent()
75 {
76         unlink_all();
77 }
78
79 ValueBase
80 ValueNode_SegCalcTangent::operator()(Time t)const
81 {
82         Segment segment((*segment_)(t).get(Segment()));
83
84         etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
85         etl::derivative< etl::hermite<Vector> > deriv(curve);
86
87 #ifdef ETL_FIXED_DERIVATIVE
88         return deriv((*amount_)(t).get(Real()))*(0.5);
89 #else
90         return deriv((*amount_)(t).get(Real()))*(-0.5);
91 #endif
92
93 }
94
95
96 String
97 ValueNode_SegCalcTangent::get_name()const
98 {
99         return "segcalctangent";
100 }
101
102 String
103 ValueNode_SegCalcTangent::get_local_name()const
104 {
105         return _("Segment Tangent");
106 }
107
108 bool
109 ValueNode_SegCalcTangent::check_type(ValueBase::Type type)
110 {
111         return type==ValueBase::TYPE_VECTOR;
112 }
113
114 bool
115 ValueNode_SegCalcTangent::set_link_vfunc(int i,ValueNode::Handle x)
116 {
117         assert(i==0 || i==1);
118         if(i==0)
119         {
120                 segment_=x;
121                 signal_child_changed()(i);signal_value_changed()();
122                 return true;
123         }
124         if(i==1)
125         {
126                 amount_=x;
127                 signal_child_changed()(i);signal_value_changed()();
128                 return true;
129         }
130         return false;
131 }
132
133 ValueNode::LooseHandle
134 ValueNode_SegCalcTangent::get_link_vfunc(int i)const
135 {
136         assert(i==0 || i==1);
137         if(i==0)
138                 return segment_;
139         if(i==1)
140                 return amount_;
141
142         return 0;
143 }
144
145 int
146 ValueNode_SegCalcTangent::link_count()const
147 {
148         return 2;
149 }
150
151 String
152 ValueNode_SegCalcTangent::link_name(int i)const
153 {
154         assert(i==0 || i==1);
155         if(i==0)
156                 return "segment";
157         if(i==1)
158                 return "amount";
159         return String();
160 }
161
162 String
163 ValueNode_SegCalcTangent::link_local_name(int i)const
164 {
165         assert(i==0 || i==1);
166         if(i==0)
167                 return _("Segment");
168         if(i==1)
169                 return _("Amount");
170         return String();
171 }
172
173 int
174 ValueNode_SegCalcTangent::get_link_index_from_name(const String &name)const
175 {
176         if(name=="segment")
177                 return 0;
178         if(name=="amount")
179                 return 1;
180
181         throw Exception::BadLinkName(name);
182 }
183
184 LinkableValueNode*
185 ValueNode_SegCalcTangent::create_new()const
186 {
187         return new ValueNode_SegCalcTangent(ValueBase::TYPE_VECTOR);
188 }