Fox #27866: Curve handle snaps/locks when it shouldnt
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 9 Jul 2011 14:22:52 +0000 (14:22 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 9 Jul 2011 14:22:52 +0000 (14:22 +0000)
It was a precision error in calchandleNurb. Do not align handles
along handle which si too short.

source/blender/blenkernel/intern/curve.c

index 704af73dd10fc4f70b23a425ab61979564b88328..202a3f28d9ab6750e2871c06628d6a122aee5402 100644 (file)
@@ -2431,6 +2431,7 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
 {
        float *p1,*p2,*p3, pt[3];
        float dx1,dy1,dz1,dx,dy,dz,vx,vy,vz,len,len1,len2;
+       const float eps= 1e-5;
 
        if(bezt->h1==0 && bezt->h2==0) return;
 
@@ -2587,30 +2588,38 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
 
        if(bezt->f1 & SELECT) { /* order of calculation */
                if(bezt->h2==HD_ALIGN) {        /* aligned */
-                       len= len2/len1;
-                       p2[3]= p2[0]+len*(p2[0]-p2[-3]);
-                       p2[4]= p2[1]+len*(p2[1]-p2[-2]);
-                       p2[5]= p2[2]+len*(p2[2]-p2[-1]);
+                       if(len1>eps) {
+                               len= len2/len1;
+                               p2[3]= p2[0]+len*(p2[0]-p2[-3]);
+                               p2[4]= p2[1]+len*(p2[1]-p2[-2]);
+                               p2[5]= p2[2]+len*(p2[2]-p2[-1]);
+                       }
                }
                if(bezt->h1==HD_ALIGN) {
-                       len= len1/len2;
-                       p2[-3]= p2[0]+len*(p2[0]-p2[3]);
-                       p2[-2]= p2[1]+len*(p2[1]-p2[4]);
-                       p2[-1]= p2[2]+len*(p2[2]-p2[5]);
+                       if(len2>eps) {
+                               len= len1/len2;
+                               p2[-3]= p2[0]+len*(p2[0]-p2[3]);
+                               p2[-2]= p2[1]+len*(p2[1]-p2[4]);
+                               p2[-1]= p2[2]+len*(p2[2]-p2[5]);
+                       }
                }
        }
        else {
                if(bezt->h1==HD_ALIGN) {
-                       len= len1/len2;
-                       p2[-3]= p2[0]+len*(p2[0]-p2[3]);
-                       p2[-2]= p2[1]+len*(p2[1]-p2[4]);
-                       p2[-1]= p2[2]+len*(p2[2]-p2[5]);
+                       if(len2>eps) {
+                               len= len1/len2;
+                               p2[-3]= p2[0]+len*(p2[0]-p2[3]);
+                               p2[-2]= p2[1]+len*(p2[1]-p2[4]);
+                               p2[-1]= p2[2]+len*(p2[2]-p2[5]);
+                       }
                }
                if(bezt->h2==HD_ALIGN) {        /* aligned */
-                       len= len2/len1;
-                       p2[3]= p2[0]+len*(p2[0]-p2[-3]);
-                       p2[4]= p2[1]+len*(p2[1]-p2[-2]);
-                       p2[5]= p2[2]+len*(p2[2]-p2[-1]);
+                       if(len1>eps) {
+                               len= len2/len1;
+                               p2[3]= p2[0]+len*(p2[0]-p2[-3]);
+                               p2[4]= p2[1]+len*(p2[1]-p2[-2]);
+                               p2[5]= p2[2]+len*(p2[2]-p2[-1]);
+                       }
                }
        }
 }