1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_segcalctangent.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "valuenode_segcalctangent.h"
33 #include "valuenode_const.h"
34 #include "valuenode_composite.h"
36 #include "exception.h"
37 #include <ETL/hermite>
38 #include <ETL/calculus>
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 ValueNode_SegCalcTangent::ValueNode_SegCalcTangent(const ValueBase::Type &x):
60 if(x!=ValueBase::TYPE_VECTOR)
61 throw Exception::BadType(ValueBase::type_name(x));
63 segment_=ValueNode_Composite::create(ValueBase::TYPE_SEGMENT);
64 amount_=ValueNode_Const::create(Real(0.5));
67 ValueNode_SegCalcTangent*
68 ValueNode_SegCalcTangent::create(const ValueBase &x)
70 return new ValueNode_SegCalcTangent(x.get_type());
73 ValueNode_SegCalcTangent::~ValueNode_SegCalcTangent()
79 ValueNode_SegCalcTangent::operator()(Time t)const
81 Segment segment((*segment_)(t).get(Segment()));
83 etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
84 etl::derivative< etl::hermite<Vector> > deriv(curve);
86 #ifdef ETL_FIXED_DERIVATIVE
87 return deriv((*amount_)(t).get(Real()))*(0.5);
89 return deriv((*amount_)(t).get(Real()))*(-0.5);
96 ValueNode_SegCalcTangent::get_name()const
98 return "segcalctangent";
102 ValueNode_SegCalcTangent::get_local_name()const
104 return _("SegCalcTangent");
108 ValueNode_SegCalcTangent::check_type(ValueBase::Type type)
110 return type==ValueBase::TYPE_VECTOR;
114 ValueNode_SegCalcTangent::set_link_vfunc(int i,ValueNode::Handle x)
116 assert(i==0 || i==1);
120 signal_child_changed()(i);signal_value_changed()();
126 signal_child_changed()(i);signal_value_changed()();
132 ValueNode::LooseHandle
133 ValueNode_SegCalcTangent::get_link_vfunc(int i)const
135 assert(i==0 || i==1);
145 ValueNode_SegCalcTangent::link_count()const
151 ValueNode_SegCalcTangent::link_name(int i)const
153 assert(i==0 || i==1);
162 ValueNode_SegCalcTangent::link_local_name(int i)const
164 assert(i==0 || i==1);
173 ValueNode_SegCalcTangent::get_link_index_from_name(const String &name)const
180 throw Exception::BadLinkName(name);
184 ValueNode_SegCalcTangent::create_new()const
186 return new ValueNode_SegCalcTangent(ValueBase::TYPE_VECTOR);