Slight adjustment to curve fitting tangents
authorCampbell Barton <ideasman42@gmail.com>
Sat, 30 Apr 2016 06:27:43 +0000 (16:27 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 30 Apr 2016 06:27:43 +0000 (16:27 +1000)
Don't let the point spacing give bias to a side.

extern/curve_fit_nd/intern/curve_fit_cubic.c
extern/curve_fit_nd/intern/curve_fit_inline.h

index 810cf92760d539198865142518e32e14cfb5d7a1..6aee04f20b15642fb738345f9a2a124796c2eadd 100644 (file)
@@ -814,8 +814,22 @@ static void fit_cubic_to_points(
                pt_a += dims;
        }
 
-       /* tan_center = (pt_a - pt_b).normalized() */
-       normalize_vn_vnvn(tan_center, pt_a, pt_b, dims);
+       {
+#ifdef USE_VLA
+               double tan_center_a[dims];
+               double tan_center_b[dims];
+#else
+               double *tan_center_a = alloca(sizeof(double) * dims);
+               double *tan_center_b = alloca(sizeof(double) * dims);
+#endif
+               const double *pt   = &points_offset[split_index * dims];
+
+               /* tan_center = ((pt_a - pt).normalized() + (pt - pt_b).normalized()).normalized() */
+               normalize_vn_vnvn(tan_center_a, pt_a, pt, dims);
+               normalize_vn_vnvn(tan_center_b, pt, pt_b, dims);
+               add_vn_vnvn(tan_center, tan_center_a, tan_center_b, dims);
+               normalize_vn(tan_center, dims);
+       }
 
        fit_cubic_to_points(
                points_offset, split_index + 1,
index 17aa02be3e5b42a81b572ff900f4f33ed904d773..1b47cbd5eb5a91ddc0c4d772ad6fd9dfe1b215ac 100644 (file)
@@ -209,6 +209,7 @@ static double len_vn(
 {
        return sqrt(len_squared_vn(v0, dims));
 }
+#endif
 
 MINLINE double normalize_vn(
         double v0[], const uint dims)
@@ -219,7 +220,6 @@ MINLINE double normalize_vn(
        }
        return d;
 }
-#endif
 
 /* v_out = (v0 - v1).normalized() */
 MINLINE double normalize_vn_vnvn(