[Bf-blender-cvs] [cd07fb64779] geometry-nodes-curve-support: Splines: Continue cleanup

Hans Goudey noreply at git.blender.org
Thu Apr 22 21:20:41 CEST 2021


Commit: cd07fb6477932742affddb03ab2f347361e66992
Author: Hans Goudey
Date:   Thu Apr 22 12:15:13 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rBcd07fb6477932742affddb03ab2f347361e66992

Splines: Continue cleanup

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

M	source/blender/blenkernel/intern/spline_nurbs.cc

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

diff --git a/source/blender/blenkernel/intern/spline_nurbs.cc b/source/blender/blenkernel/intern/spline_nurbs.cc
index 4d379eaa34a..4181e8c6df6 100644
--- a/source/blender/blenkernel/intern/spline_nurbs.cc
+++ b/source/blender/blenkernel/intern/spline_nurbs.cc
@@ -267,27 +267,26 @@ static void calculate_basis_for_point(const float parameter,
 
   int start = 0;
   int end = 0;
-  for (int i = 0; i < points_len + order - 1; i++) {
-    if ((knots[i] != knots[i + 1]) && (t >= knots[i]) && (t <= knots[i + 1])) {
-      basis_buffer[i] = 1.0f;
-      start = std::max(i - order - 1, 0);
-      end = i;
-      i++;
-      while (i < points_len + order - 1) {
-        basis_buffer[i] = 0.0f;
-        i++;
-      }
-      break;
+  for (const int i : IndexRange(points_len + order - 1)) {
+    const bool knots_equal = knots[i] == knots[i + 1];
+    if (knots_equal || t < knots[i] || t > knots[i + 1]) {
+      basis_buffer[i] = 0.0f;
+      continue;
     }
-    basis_buffer[i] = 0.0f;
+
+    basis_buffer[i] = 1.0f;
+    start = std::max(i - order - 1, 0);
+    end = i;
+    basis_buffer.slice(i + 1, points_len + order - 1 - i).fill(0.0f);
+    break;
   }
   basis_buffer[points_len + order - 1] = 0.0f;
 
-  for (int i_order = 2; i_order <= order; i_order++) {
+  for (const int i_order : IndexRange(2, order - 1)) {
     if (end + i_order >= points_len + order) {
       end = points_len + order - 1 - i_order;
     }
-    for (int i = start; i <= end; i++) {
+    for (const int i : IndexRange(start, end - start + 1)) {
       float new_basis = 0.0f;
       if (basis_buffer[i] != 0.0f) {
         new_basis += ((t - knots[i]) * basis_buffer[i]) / (knots[i + i_order - 1] - knots[i]);



More information about the Bf-blender-cvs mailing list