[Bf-blender-cvs] [d94d7a5d8f6] master: Cleanup: update curve_fit_nd (no functional changes)

Campbell Barton noreply at git.blender.org
Wed Jun 29 02:11:52 CEST 2022


Commit: d94d7a5d8f691426bfd6f32837f7e4387af51c9f
Author: Campbell Barton
Date:   Wed Jun 29 09:53:54 2022 +1000
Branches: master
https://developer.blender.org/rBd94d7a5d8f691426bfd6f32837f7e4387af51c9f

Cleanup: update curve_fit_nd (no functional changes)

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

M	extern/curve_fit_nd/README.blender
M	extern/curve_fit_nd/curve_fit_nd.h
M	extern/curve_fit_nd/intern/curve_fit_cubic.c
M	extern/curve_fit_nd/intern/curve_fit_cubic_refit.c
M	extern/curve_fit_nd/intern/generic_alloc_impl.h
M	extern/curve_fit_nd/intern/generic_heap.c

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

diff --git a/extern/curve_fit_nd/README.blender b/extern/curve_fit_nd/README.blender
index 8e70fd796bb..ccc9627f5b5 100644
--- a/extern/curve_fit_nd/README.blender
+++ b/extern/curve_fit_nd/README.blender
@@ -1,5 +1,5 @@
 Project: Curve-Fit-nD
 URL: https://github.com/ideasman42/curve-fit-nd
 License: BSD 3-Clause
-Upstream version: ddcd5bd (Last Release)
+Upstream version: ae32da9de264c3ed399673e2bc1bc09003799416 (Last Release)
 Local modifications: None
diff --git a/extern/curve_fit_nd/curve_fit_nd.h b/extern/curve_fit_nd/curve_fit_nd.h
index 18244799b0f..56c3e968b1c 100644
--- a/extern/curve_fit_nd/curve_fit_nd.h
+++ b/extern/curve_fit_nd/curve_fit_nd.h
@@ -39,7 +39,7 @@
  * Takes a flat array of points and evaluates that to calculate a bezier spline.
  *
  * \param points, points_len: The array of points to calculate a cubics from.
- * \param dims: The number of dimensions for for each element in \a points.
+ * \param dims: The number of dimensions for each element in \a points.
  * \param error_threshold: the error threshold to allow for,
  * the curve will be within this distance from \a points.
  * \param corners, corners_len: indices for points which will not have aligned tangents (optional).
@@ -47,10 +47,10 @@
  * to evaluate a line to detect corner indices.
  *
  * \param r_cubic_array, r_cubic_array_len: Resulting array of tangents and knots, formatted as follows:
- * ``r_cubic_array[r_cubic_array_len][3][dims]``,
+ * `r_cubic_array[r_cubic_array_len][3][dims]`,
  * where each point has 0 and 2 for the tangents and the middle index 1 for the knot.
- * The size of the *flat* array will be ``r_cubic_array_len * 3 * dims``.
- * \param r_corner_index_array, r_corner_index_len: Corner indices in in \a r_cubic_array (optional).
+ * The size of the *flat* array will be `r_cubic_array_len * 3 * dims`.
+ * \param r_corner_index_array, r_corner_index_len: Corner indices in \a r_cubic_array (optional).
  * This allows you to access corners on the resulting curve.
  *
  * \returns zero on success, nonzero is reserved for error values.
@@ -85,7 +85,7 @@ int curve_fit_cubic_to_points_fl(
  * Takes a flat array of points and evaluates that to calculate handle lengths.
  *
  * \param points, points_len: The array of points to calculate a cubics from.
- * \param dims: The number of dimensions for for each element in \a points.
+ * \param dims: The number of dimensions for each element in \a points.
  * \param points_length_cache: Optional pre-calculated lengths between points.
  * \param error_threshold: the error threshold to allow for,
  * \param tan_l, tan_r: Normalized tangents the handles will be aligned to.
@@ -166,7 +166,7 @@ int curve_fit_cubic_to_points_refit_fl(
  * A helper function that takes a line and outputs its corner indices.
  *
  * \param points, points_len: Curve to evaluate.
- * \param dims: The number of dimensions for for each element in \a points.
+ * \param dims: The number of dimensions for each element in \a points.
  * \param radius_min: Corners on the curve between points below this radius are ignored.
  * \param radius_max: Corners on the curve above this radius are ignored.
  * \param samples_max: Prevent testing corners beyond this many points
diff --git a/extern/curve_fit_nd/intern/curve_fit_cubic.c b/extern/curve_fit_nd/intern/curve_fit_cubic.c
index 47c5344c821..95e5d9f79e4 100644
--- a/extern/curve_fit_nd/intern/curve_fit_cubic.c
+++ b/extern/curve_fit_nd/intern/curve_fit_cubic.c
@@ -43,20 +43,24 @@
 
 #include "../curve_fit_nd.h"
 
-/* Take curvature into account when calculating the least square solution isn't usable. */
+/** Take curvature into account when calculating the least square solution isn't usable. */
 #define USE_CIRCULAR_FALLBACK
 
-/* Use the maximum distance of any points from the direct line between 2 points
+/**
+ * Use the maximum distance of any points from the direct line between 2 points
  * to calculate how long the handles need to be.
  * Can do a 'perfect' reversal of subdivision when for curve has symmetrical handles and doesn't change direction
- * (as with an 'S' shape). */
+ * (as with an 'S' shape).
+ */
 #define USE_OFFSET_FALLBACK
 
-/* avoid re-calculating lengths multiple times */
+/** Avoid re-calculating lengths multiple times. */
 #define USE_LENGTH_CACHE
 
-/* store the indices in the cubic data so we can return the original indices,
- * useful when the caller has data associated with the curve. */
+/**
+ * Store the indices in the cubic data so we can return the original indices,
+ * useful when the caller has data associated with the curve.
+ */
 #define USE_ORIG_INDEX_DATA
 
 typedef unsigned int uint;
@@ -95,13 +99,15 @@ typedef unsigned int uint;
  * \{ */
 
 typedef struct Cubic {
-	/* single linked lists */
+	/** Single linked lists. */
 	struct Cubic *next;
 #ifdef USE_ORIG_INDEX_DATA
 	uint orig_span;
 #endif
-	/* 0: point_0, 1: handle_0, 2: handle_1, 3: point_1,
-	 * each one is offset by 'dims' */
+	/**
+	 * 0: point_0, 1: handle_0, 2: handle_1, 3: point_1,
+	 * each one is offset by 'dims'.
+	 */
 	double pt_data[0];
 } Cubic;
 
@@ -195,7 +201,7 @@ static double *cubic_list_as_array(
 	bool use_orig_index = (r_orig_index != NULL);
 #endif
 
-	/* fill the array backwards */
+	/* Fill the array backwards. */
 	const size_t array_chunk = 3 * dims;
 	double *array_iter = array + array_flat_len;
 	for (Cubic *citer = clist->items; citer; citer = citer->next) {
@@ -221,15 +227,15 @@ static double *cubic_list_as_array(
 	}
 #endif
 
-	/* flip tangent for first and last (we could leave at zero, but set to something useful) */
+	/* Flip tangent for first and last (we could leave at zero, but set to something useful). */
 
-	/* first */
+	/* First. */
 	array_iter -= array_chunk;
 	memcpy(&array_iter[dims], handle_prev, sizeof(double) * 2 * dims);
 	flip_vn_vnvn(&array_iter[0 * dims], &array_iter[1 * dims], &array_iter[2 * dims], dims);
 	assert(array == array_iter);
 
-	/* last */
+	/* Last. */
 	array_iter += array_flat_len - (3 * dims);
 	flip_vn_vnvn(&array_iter[2 * dims], &array_iter[1 * dims], &array_iter[0 * dims], dims);
 
@@ -455,7 +461,7 @@ static double points_calc_circumference_factor(
 	const double dot = dot_vnvn(tan_l, tan_r, dims);
 	const double len_tangent = dot < 0.0 ? len_vnvn(tan_l, tan_r, dims) : len_negated_vnvn(tan_l, tan_r, dims);
 	if (len_tangent > DBL_EPSILON) {
-		/* only clamp to avoid precision error */
+		/* Only clamp to avoid precision error. */
 		double angle = acos(max(-fabs(dot), -1.0));
 		/* Angle may be less than the length when the tangents define >180 degrees of the circle,
 		 * (tangents that point away from each other).
@@ -466,7 +472,7 @@ static double points_calc_circumference_factor(
 		return factor;
 	}
 	else {
-		/* tangents are exactly aligned (think two opposite sides of a circle). */
+		/* Tangents are exactly aligned (think two opposite sides of a circle). */
 		return (M_PI / 2);
 	}
 }
@@ -485,18 +491,18 @@ static double points_calc_circle_tangent_factor(
 	const double eps = 1e-8;
 	const double tan_dot = dot_vnvn(tan_l, tan_r, dims);
 	if (tan_dot > 1.0 - eps) {
-		/* no angle difference (use fallback, length wont make any difference) */
+		/* No angle difference (use fallback, length won't make any difference). */
 		return (1.0 / 3.0) * 0.75;
 	}
 	else if (tan_dot < -1.0 + eps) {
-		/* parallel tangents (half-circle) */
+		/* Parallel tangents (half-circle). */
 		return (1.0 / 2.0);
 	}
 	else {
-		/* non-aligned tangents, calculate handle length */
+		/* Non-aligned tangents, calculate handle length. */
 		const double angle = acos(tan_dot) / 2.0;
 
-		/* could also use 'angle_sin = len_vnvn(tan_l, tan_r, dims) / 2.0' */
+		/* Could also use `angle_sin = len_vnvn(tan_l, tan_r, dims) / 2.0`. */
 		const double angle_sin = sin(angle);
 		const double angle_cos = cos(angle);
 		return ((1.0 - angle_cos) / (angle_sin * 2.0)) / angle_sin;
@@ -516,15 +522,15 @@ static double points_calc_cubic_scale(
 	const double len_direct = len_vnvn(v_l, v_r, dims);
 	const double len_circle_factor = points_calc_circle_tangent_factor(tan_l, tan_r, dims);
 
-	/* if this curve is a circle, this value doesn't need modification */
+	/* If this curve is a circle, this value doesn't need modification. */
 	const double len_circle_handle = (len_direct * (len_circle_factor / 0.75));
 
-	/* scale by the difference from the circumference distance */
+	/* Scale by the difference from the circumference distance. */
 	const double len_circle = len_direct * points_calc_circumference_factor(tan_l, tan_r, dims);
 	double scale_handle = (coords_length / len_circle);
 
 	/* Could investigate an accurate calculation here,
-	 * though this gives close results */
+	 * though this gives close results. */
 	scale_handle = ((scale_handle - 1.0) * 1.75) + 1.0;
 
 	return len_circle_handle * scale_handle;
@@ -554,9 +560,8 @@ static void cubic_from_points_fallback(
 	r_cubic->orig_span = (points_offset_len - 1);
 #endif
 
-	/* p1 = p0 - (tan_l * alpha);
-	 * p2 = p3 + (tan_r * alpha);
-	 */
+	/* `p1 = p0 - (tan_l * alpha);`
+	 * `p2 = p3 + (tan_r * alpha);` */
 	msub_vn_vnvn_fl(p1, p0, tan_l, alpha, dims);
 	madd_vn_vnvn_fl(p2, p3, tan_r, alpha, dims);
 }
@@ -594,7 +599,7 @@ static void cubic_from_points_offset_fallback(
 	project_plane_vn_vnvn_normalized(a[0], tan_l, dir_unit, dims);
 	project_plane_vn_vnvn_normalized(a[1], tan_r, dir_unit, dims);
 
-	/* only for better accuracy, not essential */
+	/* Only for better accuracy, not essential. */
 	normalize_vn(a[0], dims);
 	normalize_vn(a[1], dims);
 
@@ -620,7 +625,7 @@ static void cubic_from_points_offset_fallback(
 	 *
 	 * The 'dists[..] + dir_dirs' limit is just a rough approximation.
 	 * While a more exact value could be calculated,
-	 * in this case the error values approach divide by zero (inf)
+	 * in this case the error values approach divide by zero (infinite)
 	 * so there is no need to be too precise when checking if limits have been exceeded. */
 
 	double alpha_l = (dists[0] / 0.75) / fabs(dot_vnvn(tan_l, a[0], dims));
@@ -644,9 +649,8 @@ static void cubic_from_points_offset_fallback(
 	r_cubic->orig_span = (points_offset_len - 1);
 #endif
 
-	/* p1 = p0 - (tan_l * alpha_l);
-	 * p2 = p3 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list