[Bf-blender-cvs] [f694321db07] master: Fix: Curve resample duplicates last point for cyclic splines

Hans Goudey noreply at git.blender.org
Sun May 9 08:33:42 CEST 2021


Commit: f694321db073018e6f5bf58bee77a55f2018b369
Author: Hans Goudey
Date:   Sun May 9 01:33:34 2021 -0500
Branches: master
https://developer.blender.org/rBf694321db073018e6f5bf58bee77a55f2018b369

Fix: Curve resample duplicates last point for cyclic splines

The last point of the output was at the same location as the
first point of a cyclic spline. The fix is simple, just account for
the cyclic when choosing the sample edge length, and don't
hard code the last sample.

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

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

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

diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc
index 447e8a5b0a5..11620a30948 100644
--- a/source/blender/blenkernel/intern/spline_base.cc
+++ b/source/blender/blenkernel/intern/spline_base.cc
@@ -286,7 +286,7 @@ Array<float> Spline::sample_uniform_index_factors(const int samples_size) const
   }
 
   const float total_length = this->length();
-  const float sample_length = total_length / (samples_size - 1);
+  const float sample_length = total_length / (samples_size - (is_cyclic_ ? 0 : 1));
 
   /* Store the length at the previous evaluated point in a variable so it can
    * start out at zero (the lengths array doesn't contain 0 for the first point). */
@@ -305,7 +305,10 @@ Array<float> Spline::sample_uniform_index_factors(const int samples_size) const
     prev_length = length;
   }
 
-  samples.last() = lengths.size();
+  if (!is_cyclic_) {
+    /* In rare cases this can prevent overflow of the stored index. */
+    samples.last() = lengths.size();
+  }
 
   return samples;
 }



More information about the Bf-blender-cvs mailing list