Commit: 55fe91abf34e2f984e7be79694f542c6a5f80b63
Author: Campbell Barton
Date:   Thu Feb 27 17:03:35 2014 +1100
https://developer.blender.org/rB55fe91abf34e2f984e7be79694f542c6a5f80b63

Code cleanup: curves calculation was using offsets confusingly

also avoid calculating handle length when align isn't used.

===================================================================

M       source/blender/blenkernel/intern/curve.c

===================================================================

diff --git a/source/blender/blenkernel/intern/curve.c 
b/source/blender/blenkernel/intern/curve.c
index 58c7e7d..03eb929 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -2902,8 +2902,12 @@ void BKE_curve_bevelList_make(Object *ob, ListBase 
*nurbs, bool for_render)
  */
 
 /* mode: is not zero when FCurve, is 2 when forced horizontal for autohandles 
*/
-static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple 
*next, int mode, int skip_align)
+static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple 
*next, int mode, bool skip_align)
 {
+       /* defines to avoid confusion */
+#define p2_h1 (p2 - 3)
+#define p2_h2 (p2 + 3)
+
        float *p1, *p2, *p3, pt[3];
        float dvec_a[3], dvec_b[3];
        float len, len_a, len_b;
@@ -2960,7 +2964,7 @@ static void calchandleNurb_intern(BezTriple *bezt, 
BezTriple *prev, BezTriple *n
                len = len_v3(tvec) * 2.5614f;
 
                if (len != 0.0f) {
-                       int leftviolate = 0, rightviolate = 0;  /* for mode==2 
*/
+                       bool leftviolate = false, rightviolate = false;  /* for 
mode==2 */
 
                        if (len_a > 5.0f * len_b)
                                len_a = 5.0f * len_b;
@@ -2969,7 +2973,7 @@ static void calchandleNurb_intern(BezTriple *bezt, 
BezTriple *prev, BezTriple *n
 
                        if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) {
                                len_a /= len;
-                               madd_v3_v3v3fl(p2 - 3, p2, tvec, -len_a);
+                               madd_v3_v3v3fl(p2_h1, p2, tvec, -len_a);
 
                                if ((bezt->h1 == HD_AUTO_ANIM) && next && prev) 
{ /* keep horizontal if extrema */
                                        float ydiff1 = prev->vec[1][1] - 
bezt->vec[1][1];
@@ -2995,7 +2999,7 @@ static void calchandleNurb_intern(BezTriple *bezt, 
BezTriple *prev, BezTriple *n
                        }
                        if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) {
                                len_b /= len;
-                               madd_v3_v3v3fl(p2 + 3, p2, tvec,  len_b);
+                               madd_v3_v3v3fl(p2_h2, p2, tvec,  len_b);
 
                                if ((bezt->h2 == HD_AUTO_ANIM) && next && prev) 
{ /* keep horizontal if extrema */
                                        float ydiff1 = prev->vec[1][1] - 
bezt->vec[1][1];
@@ -3023,8 +3027,8 @@ static void calchandleNurb_intern(BezTriple *bezt, 
BezTriple *prev, BezTriple *n
                                float h1[3], h2[3];
                                float dot;
 
-                               sub_v3_v3v3(h1, p2 - 3, p2);
-                               sub_v3_v3v3(h2, p2, p2 + 3);
+                               sub_v3_v3v3(h1, p2_h1, p2);
+                               sub_v3_v3v3(h2, p2, p2_h2);
 
                                len_a = normalize_v3(h1);
                                len_b = normalize_v3(h2);
@@ -3033,32 +3037,32 @@ static void calchandleNurb_intern(BezTriple *bezt, 
BezTriple *prev, BezTriple *n
 
                                if (leftviolate) {
                                        mul_v3_fl(h1, dot * len_b);
-                                       sub_v3_v3v3(p2 + 3, p2, h1);
+                                       sub_v3_v3v3(p2_h2, p2, h1);
                                }
                                else {
                                        mul_v3_fl(h2, dot * len_a);
-                                       add_v3_v3v3(p2 - 3, p2, h2);
+                                       add_v3_v3v3(p2_h1, p2, h2);
                                }
                        }
                }
        }
 
        if (bezt->h1 == HD_VECT) {    /* vector */
-               madd_v3_v3v3fl(p2 - 3, p2, dvec_a, -1.0f / 3.0f);
+               madd_v3_v3v3fl(p2_h1, p2, dvec_a, -1.0f / 3.0f);
        }
        if (bezt->h2 == HD_VECT) {
-               madd_v3_v3v3fl(p2 + 3, p2, dvec_b,  1.0f / 3.0f);
+               madd_v3_v3v3fl(p2_h2, p2, dvec_b,  1.0f / 3.0f);
        }
 
-       if (skip_align) {
+       if (skip_align || !ELEM(HD_ALIGN, bezt->h1, bezt->h2)) {
                /* handles need to be updated during animation and applying 
stuff like hooks,
                 * but in such situations it's quite difficult to distinguish 
in which order
                 * align handles should be aligned so skip them for now */
                return;
        }
 
-       len_b = len_v3v3(p2, p2 + 3);
-       len_a = len_v3v3(p2, p2 - 3);
+       len_a = len_v3v3(p2, p2_h1);
+       len_b = len_v3v3(p2, p2_h2);
        if (len_a == 0.0f)
                len_a = 1.0f;
        if (len_b == 0.0f)
@@ -3068,17 +3072,17 @@ static void calchandleNurb_intern(BezTriple *bezt, 
BezTriple *prev, BezTriple *n
                if (bezt->h2 == HD_ALIGN) { /* aligned */
                        if (len_a > eps) {
                                len = len_b / len_a;
-                               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]);
+                               p2_h2[0] = p2[0] + len * (p2[0] - p2_h1[0]);
+                               p2_h2[1] = p2[1] + len * (p2[1] - p2_h1[1]);
+                               p2_h2[2] = p2[2] + len * (p2[2] - p2_h1[2]);
                        }
                }
                if (bezt->h1 == HD_ALIGN) {
                        if (len_b > eps) {
                                len = len_a / len_b;
-                               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]);
+                               p2_h1[0] = p2[0] + len * (p2[0] - p2_h2[0]);
+                               p2_h1[1] = p2[1] + len * (p2[1] - p2_h2[1]);
+                               p2_h1[2] = p2[2] + len * (p2[2] - p2_h2[2]);
                        }
                }
        }
@@ -3086,23 +3090,26 @@ static void calchandleNurb_intern(BezTriple *bezt, 
BezTriple *prev, BezTriple *n
                if (bezt->h1 == HD_ALIGN) {
                        if (len_b > eps) {
                                len = len_a / len_b;
-                               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]);
+                               p2_h1[0] = p2[0] + len * (p2[0] - p2_h2[0]);
+                               p2_h1[1] = p2[1] + len * (p2[1] - p2_h2[1]);
+                               p2_h1[2] = p2[2] + len * (p2[2] - p2_h2[2]);
                        }
                }
                if (bezt->h2 == HD_ALIGN) {   /* aligned */
                        if (len_a > eps) {
                                len = len_b / len_a;
-                               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]);
+                               p2_h2[0] = p2[0] + len * (p2[0] - p2_h1[0]);
+                               p2_h2[1] = p2[1] + len * (p2[1] - p2_h1[1]);
+                               p2_h2[2] = p2[2] + len * (p2[2] - p2_h1[2]);
                        }
                }
        }
+
+#undef p2_h1
+#undef p2_h2
 }
 
-static void calchandlesNurb_intern(Nurb *nu, int skip_align)
+static void calchandlesNurb_intern(Nurb *nu, bool skip_align)
 {
        BezTriple *bezt, *prev, *next;
        int a;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to