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 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::Type &x):
58 ValueNode_Reciprocal::ValueNode_Reciprocal(const ValueNode::Handle &x):
59 LinkableValueNode(x->get_type())
62 set_link("epsilon", ValueNode_Const::create(Real(0.000001)));
63 set_link("infinite", ValueNode_Const::create(Real(999999.0)));
67 ValueNode_Reciprocal::create(const ValueBase &x)
69 return new ValueNode_Reciprocal(ValueNode_Const::create(x));
73 ValueNode_Reciprocal::create_new()const
75 return new ValueNode_Reciprocal(get_type());
78 ValueNode_Reciprocal::~ValueNode_Reciprocal()
84 ValueNode_Reciprocal::set_link_vfunc(int i,ValueNode::Handle x)
86 assert(i >= 0 && i < link_count());
89 case 0: link_ = x; break;
90 case 1: epsilon_ = x; break;
91 case 2: infinite_ = x; break;
92 default: return false;
95 signal_child_changed()(i);
96 signal_value_changed()();
100 ValueNode::LooseHandle
101 ValueNode_Reciprocal::get_link_vfunc(int i)const
103 assert(i >= 0 && i < link_count());
104 if(i==0) return link_;
105 if(i==1) return epsilon_;
106 if(i==2) return infinite_;
112 ValueNode_Reciprocal::link_count()const
118 ValueNode_Reciprocal::link_local_name(int i)const
120 assert(i >= 0 && i < link_count());
121 if(i==0) return _("Link");
122 if(i==1) return _("Epsilon");
123 if(i==2) return _("Infinite");
128 ValueNode_Reciprocal::link_name(int i)const
130 assert(i >= 0 && i < link_count());
131 if(i==0) return "link";
132 if(i==1) return "epsilon";
133 if(i==2) return "infinite";
138 ValueNode_Reciprocal::get_link_index_from_name(const String &name)const
140 if(name=="link") return 0;
141 if(name=="epsilon") return 1;
142 if(name=="infinite") return 2;
144 throw Exception::BadLinkName(name);
148 ValueNode_Reciprocal::operator()(Time t)const
150 Real link = (*link_) (t).get(Real());
151 Real epsilon = (*epsilon_) (t).get(Real());
152 Real infinite = (*infinite_)(t).get(Real());
154 if (epsilon < 0.00000001)
155 epsilon = 0.00000001;
157 if (abs(link) < epsilon)
167 ValueNode_Reciprocal::get_name()const
173 ValueNode_Reciprocal::get_local_name()const
175 return _("Reciprocal");
179 ValueNode_Reciprocal::check_type(ValueBase::Type type)
181 return type==ValueBase::TYPE_REAL;