Author: Carlos Lopez <[email protected]>
Date:   Sat Aug 27 10:59:08 2011 +0200

Do not try to convert form homogeneous to standard and viceversa outside the 
[1,0] range. It Doesn't converge

---

 synfig-core/src/synfig/valuenode_bline.cpp |   31 +++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/synfig-core/src/synfig/valuenode_bline.cpp 
b/synfig-core/src/synfig/valuenode_bline.cpp
index b5f2403..27708b5 100644
--- a/synfig-core/src/synfig/valuenode_bline.cpp
+++ b/synfig-core/src/synfig/valuenode_bline.cpp
@@ -286,14 +286,20 @@ synfig::find_closest_point(const ValueBase &bline, const 
Point &pos, Real &radiu
 Real
 synfig::std_to_hom(const ValueBase &bline, Real pos, bool bline_loop)
 {
+       Real ret(pos);
        BLinePoint blinepoint0, blinepoint1;
        const std::vector<BLinePoint> 
list(bline.get_list().begin(),bline.get_list().end());
        int size = list.size(), from_vertex;
        if(!bline_loop) size--;
+       // Trim the pos to be in the [0, 1] interval
+       Real integer_pos=(int)pos;
+       bool is_negative(pos < 0);
+       pos = pos - integer_pos;
+       if (is_negative) pos++;
        if(size < 1) return Real();
        // trivial cases
        if(pos == 0.0 || pos == 1.0)
-               return pos;
+               return ret;
        // Calculate the lengths and the total length
        Real tl=0, pl=0;
        std::vector<Real> lengths;
@@ -317,21 +323,32 @@ synfig::std_to_hom(const ValueBase &bline, Real pos, bool 
bline_loop)
                                                        
blinepoint0.get_tangent2(), blinepoint1.get_tangent1());
        // add the distance on the bezier we are on.
        pl+=curve.find_distance(0.0, pos*size - from_vertex);
-       // and return the homogenous position
-       return pl/tl;
+       // calculate the homogeneous position
+       ret=pl/tl;
+       // Now restore the position to the same interval it was (outside [0,1])
+       if(is_negative) ret--;
+       ret = ret + integer_pos;
+       // and return it
+       return ret;
 }
 
 Real
 synfig::hom_to_std(const ValueBase &bline, Real pos, bool bline_loop)
 {
+       Real ret(pos);
        BLinePoint blinepoint0, blinepoint1;
        const std::vector<BLinePoint> 
list(bline.get_list().begin(),bline.get_list().end());
        int size = list.size(), from_vertex(0);
        if(!bline_loop) size--;
+       // Trim the pos to be in the [0, 1] interval
+       Real integer_pos=(int)pos;
+       bool is_negative(pos < 0);
+       pos = pos - integer_pos;
+       if (is_negative) pos++;
        if(size < 1) return Real();
        // trivial cases
        if(pos == 0.0 || pos == 1.0)
-               return pos;
+               return ret;
        // Calculate the lengths and the total length
        Real tl(0), pl(0), mpl, bl;
        std::vector<Real> lengths;
@@ -396,8 +413,12 @@ synfig::hom_to_std(const ValueBase &bline, Real pos, bool 
bline_loop)
                iterations++;
        }while (error>max_error && max_iterations > iterations);
        // convert the current standard index (s) to the bline's standard index
+       ret=Real(from_vertex + sn)/size;
+       // Now restore the position to the same interval it was (outside [0,1])
+       if(is_negative) ret--;
+       ret+=integer_pos;
        // and return it
-       return Real(from_vertex + sn)/size;
+       return ret;
 }
 
 Real


------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to