1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_reciprocal.cpp
3 ** \brief Implementation of the "Reciprocal" 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_reciprocal.h"
34 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_Reciprocal::ValueNode_Reciprocal(const ValueBase &x):
54 LinkableValueNode(x.get_type())
56 Vocab ret(get_children_vocab());
57 set_children_vocab(ret);
58 Real value(x.get(Real()));
59 Real infinity(999999.0);
60 Real epsilon(0.000001);
67 set_link("link", ValueNode_Const::create(Real(value)));
68 set_link("epsilon", ValueNode_Const::create(Real(epsilon)));
69 set_link("infinite", ValueNode_Const::create(Real(infinity)));
73 ValueNode_Reciprocal::create(const ValueBase &x)
75 return new ValueNode_Reciprocal(x);
79 ValueNode_Reciprocal::create_new()const
81 return new ValueNode_Reciprocal(get_type());
84 ValueNode_Reciprocal::~ValueNode_Reciprocal()
90 ValueNode_Reciprocal::set_link_vfunc(int i,ValueNode::Handle value)
92 assert(i>=0 && i<link_count());
96 case 0: CHECK_TYPE_AND_SET_VALUE(link_, ValueBase::TYPE_REAL);
97 case 1: CHECK_TYPE_AND_SET_VALUE(epsilon_, ValueBase::TYPE_REAL);
98 case 2: CHECK_TYPE_AND_SET_VALUE(infinite_, ValueBase::TYPE_REAL);
103 ValueNode::LooseHandle
104 ValueNode_Reciprocal::get_link_vfunc(int i)const
106 assert(i>=0 && i<link_count());
108 if(i==0) return link_;
109 if(i==1) return epsilon_;
110 if(i==2) return infinite_;
116 ValueNode_Reciprocal::operator()(Time t)const
118 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
119 printf("%s:%d operator()\n", __FILE__, __LINE__);
121 Real link = (*link_) (t).get(Real());
122 Real epsilon = (*epsilon_) (t).get(Real());
123 Real infinite = (*infinite_)(t).get(Real());
125 if (epsilon < 0.00000001)
126 epsilon = 0.00000001;
128 if (abs(link) < epsilon)
138 ValueNode_Reciprocal::get_name()const
144 ValueNode_Reciprocal::get_local_name()const
146 return _("Reciprocal");
150 ValueNode_Reciprocal::check_type(ValueBase::Type type)
152 return type==ValueBase::TYPE_REAL;
155 LinkableValueNode::Vocab
156 ValueNode_Reciprocal::get_children_vocab_vfunc()const
158 if(children_vocab.size())
159 return children_vocab;
161 LinkableValueNode::Vocab ret;
163 ret.push_back(ParamDesc(ValueBase(),"link")
164 .set_local_name(_("Link"))
165 .set_description(_("The value node used to calculate its reciprocal"))
168 ret.push_back(ParamDesc(ValueBase(),"epsilon")
169 .set_local_name(_("Epsilon"))
170 .set_description(_("The value used to decide whether 'Link' is too small to obtain its reciprocal"))
173 ret.push_back(ParamDesc(ValueBase(),"infinite")
174 .set_local_name(_("Infinite"))
175 .set_description(_("The resulting value when 'Link' < 'Epsilon'"))