Remove spaces and tabs at end of lines.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_log.cpp
bloba79dde53f61e0103233f997ad1639df66aa3e257
1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_log.cpp
3 ** \brief Implementation of the "Natural Logarithm" valuenode conversion.
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
10 ** Copyright (c) 2008 Carlos López
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
21 ** \endlegal
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
27 #ifdef USING_PCH
28 # include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 # include <config.h>
32 #endif
34 #include "valuenode_log.h"
35 #include "valuenode_const.h"
36 #include "general.h"
38 #endif
40 /* === U S I N G =========================================================== */
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 ValueNode_Logarithm::ValueNode_Logarithm(const ValueBase &x):
55 LinkableValueNode(x.get_type())
57 Real value(x.get(Real()));
58 Real infinity(999999.0);
59 Real epsilon(0.000001);
61 value = exp(value);
63 set_link("link", ValueNode_Const::create(Real(value)));
64 set_link("epsilon", ValueNode_Const::create(Real(epsilon)));
65 set_link("infinite", ValueNode_Const::create(Real(infinity)));
68 ValueNode_Logarithm*
69 ValueNode_Logarithm::create(const ValueBase &x)
71 return new ValueNode_Logarithm(x);
74 LinkableValueNode*
75 ValueNode_Logarithm::create_new()const
77 return new ValueNode_Logarithm(get_type());
80 ValueNode_Logarithm::~ValueNode_Logarithm()
82 unlink_all();
85 bool
86 ValueNode_Logarithm::set_link_vfunc(int i,ValueNode::Handle value)
88 assert(i>=0 && i<link_count());
90 switch(i)
92 case 0: CHECK_TYPE_AND_SET_VALUE(link_, ValueBase::TYPE_REAL);
93 case 1: CHECK_TYPE_AND_SET_VALUE(epsilon_, ValueBase::TYPE_REAL);
94 case 2: CHECK_TYPE_AND_SET_VALUE(infinite_, ValueBase::TYPE_REAL);
96 return false;
99 ValueNode::LooseHandle
100 ValueNode_Logarithm::get_link_vfunc(int i)const
102 assert(i>=0 && i<link_count());
104 if(i==0) return link_;
105 if(i==1) return epsilon_;
106 if(i==2) return infinite_;
108 return 0;
112 ValueNode_Logarithm::link_count()const
114 return 3;
117 String
118 ValueNode_Logarithm::link_local_name(int i)const
120 assert(i>=0 && i<link_count());
122 if(i==0) return _("Link");
123 if(i==1) return _("Epsilon");
124 if(i==2) return _("Infinite");
125 return String();
128 String
129 ValueNode_Logarithm::link_name(int i)const
131 assert(i>=0 && i<link_count());
133 if(i==0) return "link";
134 if(i==1) return "epsilon";
135 if(i==2) return "infinite";
136 return String();
140 ValueNode_Logarithm::get_link_index_from_name(const String &name)const
142 if(name=="link") return 0;
143 if(name=="epsilon") return 1;
144 if(name=="infinite") return 2;
146 throw Exception::BadLinkName(name);
149 ValueBase
150 ValueNode_Logarithm::operator()(Time t)const
152 Real link = (*link_) (t).get(Real());
153 Real epsilon = (*epsilon_) (t).get(Real());
154 Real infinite = (*infinite_)(t).get(Real());
156 if (epsilon < 0.00000001)
157 epsilon = 0.00000001;
159 if (link < epsilon)
160 return -infinite;
161 else
162 return log(link);
165 String
166 ValueNode_Logarithm::get_name()const
168 return "logarithm";
171 String
172 ValueNode_Logarithm::get_local_name()const
174 return _("Logarithm");
177 bool
178 ValueNode_Logarithm::check_type(ValueBase::Type type)
180 return type==ValueBase::TYPE_REAL;