Use the ETL 'round_to_int' function rather than re-writing it in each of these files.
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Wed, 10 Oct 2007 15:54:11 +0000 (15:54 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Wed, 10 Oct 2007 15:54:11 +0000 (15:54 +0000)
git-svn-id: http://svn.voria.com/code@895 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/synfig/valuenode_add.cpp
synfig-core/trunk/src/synfig/valuenode_linear.cpp
synfig-core/trunk/src/synfig/valuenode_scale.cpp
synfig-core/trunk/src/synfig/valuenode_subtract.cpp
synfig-core/trunk/src/synfig/valuenode_timedswap.cpp

index 172b305..9f83229 100644 (file)
@@ -38,6 +38,7 @@
 #include "vector.h"
 #include "angle.h"
 #include "real.h"
+#include <ETL/misc>
 
 #endif
 
@@ -173,11 +174,7 @@ synfig::ValueNode_Add::operator()(Time t)const
        case ValueBase::TYPE_COLOR:
                return ((*ref_a)(t).get(Color())+(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
        case ValueBase::TYPE_INTEGER:
-       {
-               Real ret = ((*ref_a)(t).get(int())+(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()) + 0.5f;
-               if (ret < 0) return static_cast<int>(ret-1);
-               return static_cast<int>(ret); 
-       }
+               return round_to_int(((*ref_a)(t).get(int())+(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()));
        case ValueBase::TYPE_REAL:
                return ((*ref_a)(t).get(Vector::value_type())+(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real());
        case ValueBase::TYPE_TIME:
index f0d6c11..b017c9a 100644 (file)
@@ -34,6 +34,7 @@
 #include "valuenode_const.h"
 #include "general.h"
 #include "color.h"
+#include <ETL/misc>
 
 #endif
 
@@ -114,11 +115,7 @@ ValueNode_Linear::operator()(Time t)const
        case ValueBase::TYPE_COLOR:
                return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
        case ValueBase::TYPE_INTEGER:
-       {
-               Real ret = (*m_)(t).get(int())*t+(*b_)(t).get(int()) + 0.5f;
-               if (ret < 0) return static_cast<int>(ret-1);
-               return static_cast<int>(ret);
-       }
+               return round_to_int((*m_)(t).get(int())*t+(*b_)(t).get(int()));
        case ValueBase::TYPE_REAL:
                return (*m_)(t).get(  Real())*t+(*b_)(t).get(  Real());
        case ValueBase::TYPE_TIME:
index b2f62b7..0ab0735 100644 (file)
@@ -39,6 +39,7 @@
 #include "vector.h"
 #include "time.h"
 #include "angle.h"
+#include <ETL/misc>
 
 #endif
 
@@ -176,11 +177,7 @@ synfig::ValueNode_Scale::operator()(Time t)const
                return ret;
        }
        else if(get_type()==ValueBase::TYPE_INTEGER)
-       {
-               Real ret = (*value_node)(t).get(int())*(*scalar)(t).get(Real()) + 0.5f;
-               if (ret < 0) return static_cast<int>(ret-1);
-               return static_cast<int>(ret);
-       }
+               return round_to_int((*value_node)(t).get(int())*(*scalar)(t).get(Real()));
        else if(get_type()==ValueBase::TYPE_REAL)
                return (*value_node)(t).get(Real())*(*scalar)(t).get(Real());
        else if(get_type()==ValueBase::TYPE_TIME)
index 81fca92..27df6a0 100644 (file)
@@ -38,6 +38,7 @@
 #include "vector.h"
 #include "angle.h"
 #include "real.h"
+#include <ETL/misc>
 
 #endif
 
@@ -173,11 +174,7 @@ synfig::ValueNode_Subtract::operator()(Time t)const
        case ValueBase::TYPE_COLOR:
                return ((*ref_a)(t).get(Color())-(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
        case ValueBase::TYPE_INTEGER:
-       {
-               Real ret = ((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()) + 0.5f;
-               if (ret < 0) return static_cast<int>(ret-1);
-               return static_cast<int>(ret); 
-       }
+               return round_to_int(((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()));
        case ValueBase::TYPE_REAL:
                return ((*ref_a)(t).get(Vector::value_type())-(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real());
        case ValueBase::TYPE_TIME:
index 20be99f..549feac 100644 (file)
@@ -35,6 +35,7 @@
 #include "valuenode_const.h"
 #include <stdexcept>
 #include "color.h"
+#include <ETL/misc>
 
 #endif
 
@@ -220,7 +221,7 @@ synfig::ValueNode_TimedSwap::operator()(Time t)const
                        {
                                float a=(float)(*after)(t).get(int());
                                float b=(float)(*before)(t).get(int());
-                               return static_cast<int>((b-a)*amount+a+0.5f);
+                               return round_to_int((b-a)*amount+a);
                        }
                case ValueBase::TYPE_REAL:
                        {