Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_reciprocal.cpp
index 4af2051..d31a995 100644 (file)
@@ -6,7 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
-**     Copyright (c) 2007 Chris Moore
+**     Copyright (c) 2007, 2008 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -50,23 +50,27 @@ using namespace synfig;
 
 /* === M E T H O D S ======================================================= */
 
-ValueNode_Reciprocal::ValueNode_Reciprocal(const ValueBase::Type &x):
-       LinkableValueNode(x)
+ValueNode_Reciprocal::ValueNode_Reciprocal(const ValueBase &x):
+       LinkableValueNode(x.get_type())
 {
-}
+       Real value(x.get(Real()));
+       Real infinity(999999.0);
+       Real epsilon(0.000001);
 
-ValueNode_Reciprocal::ValueNode_Reciprocal(const ValueNode::Handle &x):
-       LinkableValueNode(x->get_type())
-{
-       set_link("link", x);
-       set_link("epsilon",  ValueNode_Const::create(Real(0.000001)));
-       set_link("infinite", ValueNode_Const::create(Real(999999.0)));
+       if (value == 0)
+               value = infinity;
+       else
+               value = 1.0/value;
+
+       set_link("link",     ValueNode_Const::create(Real(value)));
+       set_link("epsilon",  ValueNode_Const::create(Real(epsilon)));
+       set_link("infinite", ValueNode_Const::create(Real(infinity)));
 }
 
 ValueNode_Reciprocal*
 ValueNode_Reciprocal::create(const ValueBase &x)
 {
-       return new ValueNode_Reciprocal(ValueNode_Const::create(x));
+       return new ValueNode_Reciprocal(x);
 }
 
 LinkableValueNode*
@@ -81,26 +85,24 @@ ValueNode_Reciprocal::~ValueNode_Reciprocal()
 }
 
 bool
-ValueNode_Reciprocal::set_link_vfunc(int i,ValueNode::Handle x)
+ValueNode_Reciprocal::set_link_vfunc(int i,ValueNode::Handle value)
 {
-       assert(i >= 0 && i < link_count());
+       assert(i>=0 && i<link_count());
+
        switch(i)
        {
-       case 0:  link_     = x; break;
-       case 1:  epsilon_  = x; break;
-       case 2:  infinite_ = x; break;
-       default: return false;
+       case 0: CHECK_TYPE_AND_SET_VALUE(link_,     ValueBase::TYPE_REAL);
+       case 1: CHECK_TYPE_AND_SET_VALUE(epsilon_,  ValueBase::TYPE_REAL);
+       case 2: CHECK_TYPE_AND_SET_VALUE(infinite_, ValueBase::TYPE_REAL);
        }
-
-       signal_child_changed()(i);
-       signal_value_changed()();
-       return true;
+       return false;
 }
 
 ValueNode::LooseHandle
 ValueNode_Reciprocal::get_link_vfunc(int i)const
 {
-       assert(i >= 0 && i < link_count());
+       assert(i>=0 && i<link_count());
+
        if(i==0) return link_;
        if(i==1) return epsilon_;
        if(i==2) return infinite_;
@@ -117,7 +119,8 @@ ValueNode_Reciprocal::link_count()const
 String
 ValueNode_Reciprocal::link_local_name(int i)const
 {
-       assert(i >= 0 && i < link_count());
+       assert(i>=0 && i<link_count());
+
        if(i==0) return _("Link");
        if(i==1) return _("Epsilon");
        if(i==2) return _("Infinite");
@@ -127,7 +130,8 @@ ValueNode_Reciprocal::link_local_name(int i)const
 String
 ValueNode_Reciprocal::link_name(int i)const
 {
-       assert(i >= 0 && i < link_count());
+       assert(i>=0 && i<link_count());
+
        if(i==0) return "link";
        if(i==1) return "epsilon";
        if(i==2) return "infinite";
@@ -147,10 +151,16 @@ ValueNode_Reciprocal::get_link_index_from_name(const String &name)const
 ValueBase
 ValueNode_Reciprocal::operator()(Time t)const
 {
+       if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
+               printf("%s:%d operator()\n", __FILE__, __LINE__);
+
        Real link     = (*link_)    (t).get(Real());
        Real epsilon  = (*epsilon_) (t).get(Real());
        Real infinite = (*infinite_)(t).get(Real());
 
+       if (epsilon < 0.00000001)
+               epsilon = 0.00000001;
+
        if (abs(link) < epsilon)
                if (link < 0)
                        return -infinite;