Module: synfig/synfig Branch: genete_width_outline Commit: f49d6bc012f8328fd149c80c71a238f19b1e1097 URL: http://synfig.git.sourceforge.net/git/gitweb.cgi?p=synfig/synfig;a=commit;h=f49d6bc012f8328fd149c80c71a238f19b1e1097
Author: Carlos Lopez <[email protected]> Date: Sat Feb 5 16:33:44 2011 +0100 Move the interpolate function between width points outside width point list class --- synfig-core/src/synfig/valuenode_wplist.cpp | 89 ++++++++++++++------------- synfig-core/src/synfig/valuenode_wplist.h | 12 ++-- synfig-core/src/synfig/widthpoint.cpp | 6 +- synfig-core/src/synfig/widthpoint.h | 6 +- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/synfig-core/src/synfig/valuenode_wplist.cpp b/synfig-core/src/synfig/valuenode_wplist.cpp index 91e6ff5..9842416 100644 --- a/synfig-core/src/synfig/valuenode_wplist.cpp +++ b/synfig-core/src/synfig/valuenode_wplist.cpp @@ -94,6 +94,50 @@ synfig::convert_bline_to_wplist(const ValueBase& bline) return ValueBase(ret); } +Real +synfig::widthpoint_interpolate(const WidthPoint& prev, const WidthPoint& next, Real position) +{ + WidthPoint::SideType side_int(WidthPoint::TYPE_INTERPOLATE); + Real ppos, npos; + + Real nw, pw, rw(0.0); + npos=next.get_norm_position(); + ppos=prev.get_norm_position(); + nw=next.get_width(); + pw=prev.get_width(); + if(position < npos && position > ppos) + { + Real p; + if(next.get_side_type_before() != side_int) + nw=0.0; + if(prev.get_side_type_after() != side_int) + pw=0.0; + //if previous and next are so close + if(npos-ppos < Real(0.0000001f)) + p=0.5; + else + // linear interpolation + p=(position-ppos)/(npos-ppos); + rw=pw+(nw-pw)*p; + } + else if(position > npos) + { + if(next.get_side_type_after() == side_int) + rw=nw; + } + else if(position < ppos) + { + if(prev.get_side_type_before() == side_int) + rw=pw; + } + else if(position == npos) + rw=nw; + else if(position == ppos) + rw=pw; + + return rw; +} + /* === M E T H O D S ======================================================= */ @@ -309,52 +353,9 @@ ValueNode_WPList::interpolated_width(Real position, Time time)const synfig::WidthPoint prev, next; prev=find_prev_valid_entry_by_position(position, time); next=find_next_valid_entry_by_position(position, time); - return interpolate(prev, next, position); + return widthpoint_interpolate(prev, next, position); } -Real -ValueNode_WPList::interpolate(WidthPoint& prev, WidthPoint& next, Real position)const -{ - WidthPoint::SideType side_int(WidthPoint::TYPE_INTERPOLATE); - Real ppos, npos; - - Real nw, pw, rw(0.0); - npos=next.get_norm_position(); - ppos=prev.get_norm_position(); - nw=next.get_width(); - pw=prev.get_width(); - if(position < npos && position > ppos) - { - Real p; - if(next.get_side_type_before() != side_int) - nw=0.0; - if(prev.get_side_type_after() != side_int) - pw=0.0; - //if previous and next are so close - if(npos-ppos < Real(0.0000001f)) - p=0.5; - else - // linear interpolation - p=(position-ppos)/(npos-ppos); - rw=pw+(nw-pw)*p; - } - else if(position > npos) - { - if(next.get_side_type_after() == side_int) - rw=nw; - } - else if(position < ppos) - { - if(prev.get_side_type_before() == side_int) - rw=pw; - } - else if(position == npos) - rw=nw; - else if(position == ppos) - rw=pw; - - return rw; -} ValueNode::LooseHandle ValueNode_WPList::get_bline()const diff --git a/synfig-core/src/synfig/valuenode_wplist.h b/synfig-core/src/synfig/valuenode_wplist.h index b8ec877..c2593e7 100644 --- a/synfig-core/src/synfig/valuenode_wplist.h +++ b/synfig-core/src/synfig/valuenode_wplist.h @@ -45,6 +45,12 @@ namespace synfig { //! Converts a ValueNode_BLine into a WidthPoint list synfig::ValueBase convert_bline_to_wplist(const ValueBase& bline); +//! Interpolated width +//! \param prev the previous width point to evaluate the width +//! \param next the next width point to evaluate the width +//! \param position the position to interpolate between prev and next +//! \return the interpolated width based on surrounding width points and its values +synfig::Real widthpoint_interpolate(const WidthPoint& prev, const WidthPoint& next, Real position); /*! \class ValueNode_WPList ** \brief This class implements a list of Width Points @@ -92,12 +98,6 @@ public: //! \param time the time when evaluates //! \return the interpolated width Real interpolated_width(Real position, Time time)const; - //! Interpolated width - //! \param prev the previous width point to evaluate the width - //! \param next the next width point to evaluate the width - //! \param position the position to interpolate between prev and next - //! \return the interpolated width based on surrounding width points and its values - Real interpolate(WidthPoint& prev, WidthPoint& next, Real position)const; //! Gets the bline RHandle ValueNode::LooseHandle get_bline()const; //! Sets the bline RHandle diff --git a/synfig-core/src/synfig/widthpoint.cpp b/synfig-core/src/synfig/widthpoint.cpp index e0afdbd..f3766ab 100644 --- a/synfig-core/src/synfig/widthpoint.cpp +++ b/synfig-core/src/synfig/widthpoint.cpp @@ -98,7 +98,7 @@ WidthPoint::set_width(Real x) } int -WidthPoint::get_side_type_before() +WidthPoint::get_side_type_before()const { return side_type_[0]; } @@ -110,7 +110,7 @@ WidthPoint::set_side_type_before(int sidebefore) } int -WidthPoint::get_side_type_after() +WidthPoint::get_side_type_after()const { return side_type_[1]; } @@ -122,7 +122,7 @@ WidthPoint::set_side_type_after(int sideafter) } int -WidthPoint::get_side_type(int i) +WidthPoint::get_side_type(int i)const { return i>0? side_type_[1]: side_type_[0]; } diff --git a/synfig-core/src/synfig/widthpoint.h b/synfig-core/src/synfig/widthpoint.h index 74f607f..53ed48e 100644 --- a/synfig-core/src/synfig/widthpoint.h +++ b/synfig-core/src/synfig/widthpoint.h @@ -69,11 +69,11 @@ public: const Real& get_width()const; void set_width(Real x); - int get_side_type_before(); + int get_side_type_before()const; void set_side_type_before(int sidebefore); - int get_side_type_after(); + int get_side_type_after()const; void set_side_type_after(int sideafter); - int get_side_type(int i); + int get_side_type(int i)const; bool operator < (const WidthPoint& rhs) { return position_ < rhs.position_; } }; // END of class WidthPoint ------------------------------------------------------------------------------ The modern datacenter depends on network connectivity to access resources and provide services. The best practices for maximizing a physical server's connectivity to a physical network are well understood - see how these rules translate into the virtual world? http://p.sf.net/sfu/oracle-sfdevnlfb _______________________________________________ Synfig-devl mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/synfig-devl
