1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_segcalctangent.cpp
3 ** \brief Implementation of the "Segment Tangent" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_segcalctangent.h"
34 #include "valuenode_const.h"
35 #include "valuenode_composite.h"
37 #include "exception.h"
38 #include <ETL/hermite>
39 #include <ETL/calculus>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
50 /* === M A C R O S ========================================================= */
52 /* === G L O B A L S ======================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 /* === M E T H O D S ======================================================= */
58 ValueNode_SegCalcTangent::ValueNode_SegCalcTangent(const ValueBase::Type &x):
61 if(x!=ValueBase::TYPE_VECTOR)
62 throw Exception::BadType(ValueBase::type_local_name(x));
64 set_link("segment",ValueNode_Const::create(ValueBase::TYPE_SEGMENT));
65 set_link("amount",ValueNode_Const::create(Real(0.5)));
68 ValueNode_SegCalcTangent*
69 ValueNode_SegCalcTangent::create(const ValueBase &x)
71 return new ValueNode_SegCalcTangent(x.get_type());
74 ValueNode_SegCalcTangent::~ValueNode_SegCalcTangent()
80 ValueNode_SegCalcTangent::operator()(Time t)const
82 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
83 printf("%s:%d operator()\n", __FILE__, __LINE__);
85 Segment segment((*segment_)(t).get(Segment()));
87 etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
88 etl::derivative< etl::hermite<Vector> > deriv(curve);
90 return deriv((*amount_)(t).get(Real()));
95 ValueNode_SegCalcTangent::get_name()const
97 return "segcalctangent";
101 ValueNode_SegCalcTangent::get_local_name()const
103 return _("Segment Tangent");
107 ValueNode_SegCalcTangent::check_type(ValueBase::Type type)
109 return type==ValueBase::TYPE_VECTOR;
113 ValueNode_SegCalcTangent::set_link_vfunc(int i,ValueNode::Handle value)
115 assert(i>=0 && i<link_count());
119 case 0: CHECK_TYPE_AND_SET_VALUE(segment_, ValueBase::TYPE_SEGMENT);
120 case 1: CHECK_TYPE_AND_SET_VALUE(amount_, ValueBase::TYPE_REAL);
125 ValueNode::LooseHandle
126 ValueNode_SegCalcTangent::get_link_vfunc(int i)const
128 assert(i>=0 && i<link_count());
139 ValueNode_SegCalcTangent::link_count()const
145 ValueNode_SegCalcTangent::link_name(int i)const
147 assert(i>=0 && i<link_count());
157 ValueNode_SegCalcTangent::link_local_name(int i)const
159 assert(i>=0 && i<link_count());
169 ValueNode_SegCalcTangent::get_link_index_from_name(const String &name)const
176 throw Exception::BadLinkName(name);
180 ValueNode_SegCalcTangent::create_new()const
182 return new ValueNode_SegCalcTangent(ValueBase::TYPE_VECTOR);