Commit: 5a997cae61601e92a09963ac85a6527ca6275912
Author: Hans Goudey
Date:   Mon Jun 3 07:36:53 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rB5a997cae61601e92a09963ac85a6527ca6275912

Fixed profile sample table creation. Table has to be plugged in to evaulate 
though

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

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

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

diff --git a/source/blender/blenkernel/intern/colortools.c 
b/source/blender/blenkernel/intern/colortools.c
index 5585bbdf3a2..7896ba68af8 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -1293,17 +1293,15 @@ void curvemap_path_evaluate(const struct CurveMap 
*cuma, float length_portion, f
 }
 
 
-/* HANS-TODO: Fix this, it can't be the right method, because it doesn't 
generalize well to
- * small distances between points. There could be a lot of points inside one 
segment length,
- * but this code assumes that there's only 1. I need to think harder about 
what method to use here.
- * But really it might not be worth pursuing this much because there might be 
a more general solution
- * that includes curves and the small speedup it would give isn't a high 
priority right now */
+/* HANS-TODO: Test this! (And start using it) */
 static void curvemap_path_make_table(struct CurveMap *cuma) {
   /* Fill table with values for the position of the graph at each of the 
segments */
-  float segment_length = cuma->total_length / cuma->nsegments;
+  const float segment_length = cuma->total_length / cuma->nsegments;
   float length_travelled = 0.0f;
   float distance_to_next_point = 
curvemap_path_linear_distance_to_next_point(cuma, 0);
   float distance_to_previous_point = 0.0f;
+  float travelled_since_last_point = 0.0f;
+  float segment_left = segment_length;
   float f;
   int i_point = 0;
 
@@ -1312,25 +1310,24 @@ static void curvemap_path_make_table(struct CurveMap 
*cuma) {
 
   /* Travel along the path, recording locations of segments as we pass where 
they should be */
   for (int i = 0; i < cuma->nsegments; i++) {
-    if (segment_length < distance_to_next_point) {
-      /* There is room for the next segment before the next point */
-      f = (distance_to_previous_point + segment_length) / 
(distance_to_previous_point + distance_to_next_point);
-      cuma->x_segment_vals[i] = lerp(cuma->curve[i_point].x, 
cuma->curve[i_point+1].x, f);
-      cuma->y_segment_vals[i] = lerp(cuma->curve[i_point].x, 
cuma->curve[i_point+1].x, f);
-      distance_to_next_point -= segment_length;
-      distance_to_previous_point += segment_length;
-    }
-    else {
-      /* We have to pass over a CurveMapPoint to get to the next segment */
-      float left_after_pass = segment_length - distance_to_next_point;
+    /* Travel over all of the points that could be inside this segment */
+    while (distance_to_next_point > segment_length * (i + 1) - 
length_travelled) {
+      length_travelled += distance_to_next_point;
+      segment_left -= distance_to_next_point;
+      travelled_since_last_point += distance_to_next_point;
       i_point++;
-      distance_to_previous_point = segment_length - distance_to_next_point;
       distance_to_next_point = 
curvemap_path_linear_distance_to_next_point(cuma, i_point);
-      f = left_after_pass / (distance_to_previous_point + 
distance_to_next_point);
-      cuma->x_segment_vals[i] = lerp(cuma->curve[i_point].x, 
cuma->curve[i_point+1].x, f);
-      cuma->y_segment_vals[i] = lerp(cuma->curve[i_point].x, 
cuma->curve[i_point+1].x, f);
+      distance_to_previous_point = 0.0f;
     }
-    length_travelled += segment_length;
+    /* We're now at the last point that fits inside the current segment */
+
+    f = segment_left / (distance_to_previous_point + distance_to_next_point);
+    cuma->x_segment_vals[i] = lerp(cuma->curve[i_point].x, 
cuma->curve[i_point+1].x, f);
+    cuma->y_segment_vals[i] = lerp(cuma->curve[i_point].x, 
cuma->curve[i_point+1].x, f);
+    distance_to_next_point -= segment_left;
+    distance_to_previous_point += segment_left;
+
+    length_travelled += segment_left;
   }
 
 }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to