Use a switch statement in the operator() like the other valuenode types do.
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 18 Sep 2007 19:41:49 +0000 (19:41 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 18 Sep 2007 19:41:49 +0000 (19:41 +0000)
git-svn-id: http://svn.voria.com/code@711 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/synfig/valuenode_subtract.cpp

index 4d31718..e4c9756 100644 (file)
@@ -192,22 +192,26 @@ synfig::ValueNode_Subtract::operator()(Time t)const
 {
        if(!ref_a || !ref_b)
                throw runtime_error(strprintf("ValueNode_Subtract: %s",_("One or both of my parameters aren't set!")));
-       if(get_type()==ValueBase::TYPE_ANGLE)
+       switch(get_type())
+       {
+       case ValueBase::TYPE_ANGLE:
                return ((*ref_a)(t).get(Angle())-(*ref_b)(t).get(Angle()))*(*scalar)(t).get(Real());
-       if(get_type()==ValueBase::TYPE_COLOR)
+       case ValueBase::TYPE_COLOR:
                return ((*ref_a)(t).get(Color())-(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
-       if(get_type()==ValueBase::TYPE_INTEGER)
+       case ValueBase::TYPE_INTEGER:
        {
-               Real value = ((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()) + 0.5f;
-               if (value < 0) return static_cast<int>(value-1);
-               return static_cast<int>(value);
+               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); 
        }
-       if(get_type()==ValueBase::TYPE_REAL)
+       case ValueBase::TYPE_REAL:
                return ((*ref_a)(t).get(Vector::value_type())-(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real());
-       if(get_type()==ValueBase::TYPE_VECTOR)
+       case ValueBase::TYPE_VECTOR:
                return ((*ref_a)(t).get(Vector())-(*ref_b)(t).get(Vector()))*(*scalar)(t).get(Real());
-
-       synfig::error(get_id()+':'+strprintf(_("Cannot subtract types of %s and %s"),ValueBase::type_name(ref_a->get_type()).c_str(),ValueBase::type_name(ref_b->get_type()).c_str()));
+       default:
+               assert(0);
+               break;
+       }
        return ValueBase();
 }