1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_segcalcvertex.cpp
3 ** \brief Implementation of the "Segment Vertex" 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_segcalcvertex.h"
34 #include "valuenode_const.h"
35 #include "valuenode_composite.h"
37 #include "exception.h"
38 #include <ETL/hermite>
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_SegCalcVertex::ValueNode_SegCalcVertex(const ValueBase::Type &x):
60 if(x!=ValueBase::TYPE_VECTOR)
61 throw Exception::BadType(ValueBase::type_local_name(x));
63 set_link("segment",ValueNode_Const::create(ValueBase::TYPE_SEGMENT));
64 set_link("amount",ValueNode_Const::create(Real(0.5)));
67 ValueNode_SegCalcVertex*
68 ValueNode_SegCalcVertex::create(const ValueBase &x)
70 return new ValueNode_SegCalcVertex(x.get_type());
73 ValueNode_SegCalcVertex::~ValueNode_SegCalcVertex()
79 ValueNode_SegCalcVertex::operator()(Time t)const
81 Segment segment((*segment_)(t).get(Segment()));
83 etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
85 return curve((*amount_)(t).get(Real()));
90 ValueNode_SegCalcVertex::get_name()const
92 return "segcalcvertex";
96 ValueNode_SegCalcVertex::get_local_name()const
98 return _("Segment Vertex");
102 ValueNode_SegCalcVertex::check_type(ValueBase::Type type)
104 return type==ValueBase::TYPE_VECTOR;
108 ValueNode_SegCalcVertex::set_link_vfunc(int i,ValueNode::Handle value)
110 assert(i>=0 && i<link_count());
114 case 0: CHECK_TYPE_AND_SET_VALUE(segment_, ValueBase::TYPE_SEGMENT);
115 case 1: CHECK_TYPE_AND_SET_VALUE(amount_, ValueBase::TYPE_REAL);
120 ValueNode::LooseHandle
121 ValueNode_SegCalcVertex::get_link_vfunc(int i)const
123 assert(i>=0 && i<link_count());
134 ValueNode_SegCalcVertex::link_count()const
140 ValueNode_SegCalcVertex::link_name(int i)const
142 assert(i>=0 && i<link_count());
152 ValueNode_SegCalcVertex::link_local_name(int i)const
154 assert(i>=0 && i<link_count());
164 ValueNode_SegCalcVertex::get_link_index_from_name(const String &name)const
171 throw Exception::BadLinkName(name);
175 ValueNode_SegCalcVertex::create_new()const
177 return new ValueNode_SegCalcVertex(ValueBase::TYPE_VECTOR);