Made all the assert() lines which check the valuenode sub-parameter index range the...
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_subtract.cpp
index 9d925f7..f9293bb 100644 (file)
@@ -1,11 +1,12 @@
 /* === S Y N F I G ========================================================= */
 /*!    \file valuenode_subtract.cpp
-**     \brief Template File
+**     \brief Implementation of the "Subtract" valuenode conversion.
 **
 **     $Id$
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 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
@@ -37,6 +38,7 @@
 #include "vector.h"
 #include "angle.h"
 #include "real.h"
+#include <ETL/misc>
 
 #endif
 
@@ -172,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:
@@ -193,7 +191,8 @@ synfig::ValueNode_Subtract::operator()(Time t)const
 bool
 ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle value)
 {
-       assert(i>=0 && i<3);
+       assert(i>=0 && i<link_count());
+
        switch(i)
        {
                case 0:
@@ -214,7 +213,8 @@ ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle value)
 ValueNode::LooseHandle
 ValueNode_Subtract::get_link_vfunc(int i)const
 {
-       assert(i>=0 && i<3);
+       assert(i>=0 && i<link_count());
+
        switch(i)
        {
                case 0: return ref_a;
@@ -233,7 +233,8 @@ ValueNode_Subtract::link_count()const
 String
 ValueNode_Subtract::link_local_name(int i)const
 {
-       assert(i>=0 && i<3);
+       assert(i>=0 && i<link_count());
+
        switch(i)
        {
                case 0: return _("LHS");
@@ -246,7 +247,8 @@ ValueNode_Subtract::link_local_name(int i)const
 String
 ValueNode_Subtract::link_name(int i)const
 {
-       assert(i>=0 && i<3);
+       assert(i>=0 && i<link_count());
+
        switch(i)
        {
                case 0: return "lhs";
@@ -259,7 +261,6 @@ ValueNode_Subtract::link_name(int i)const
 int
 ValueNode_Subtract::get_link_index_from_name(const String &name)const
 {
-       printf("%s:%d link_index_from_name\n", __FILE__, __LINE__);
        if(name=="lhs") return 0;
        if(name=="rhs") return 1;
        if(name=="scalar") return 2;