[gimp/wip/gradient-edit: 21/43] app: treat gradient segments as clopen ranges



commit 050eca085d16ee2b0150e8c2f07fa398824d4cbb
Author: Ell <ell_se yahoo com>
Date:   Sat Aug 12 11:50:54 2017 -0400

    app: treat gradient segments as clopen ranges
    
    Treat gradient segment exents as [left, right) ranges, instead of
    [left, right], so that they don't overlap, and each point
    corresponds to a unique color.
    
    Perform less comparisons in gimp_gradient_get_segment_at_internal().

 app/core/gimpgradient.c |   30 ++++++++++--------------------
 1 files changed, 10 insertions(+), 20 deletions(-)
---
diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c
index 4d99a8e..520ea72 100644
--- a/app/core/gimpgradient.c
+++ b/app/core/gimpgradient.c
@@ -2077,29 +2077,19 @@ gimp_gradient_get_segment_at_internal (GimpGradient        *gradient,
   if (! seg)
     seg = gradient->segments;
 
-  while (seg)
+  if (pos >= seg->left)
     {
-      if (pos >= seg->left)
-        {
-          if (pos <= seg->right)
-            {
-              return seg;
-            }
-          else
-            {
-              seg = seg->next;
-            }
-        }
-      else
-        {
-          seg = seg->prev;
-        }
+      while (seg->next && pos >= seg->right)
+        seg = seg->next;
+    }
+  else
+    {
+      do
+        seg = seg->prev;
+      while (pos < seg->left);
     }
 
-  /* Oops: we should have found a segment, but we didn't */
-  g_warning ("%s: no matching segment for position %0.15f", G_STRFUNC, pos);
-
-  return NULL;
+  return seg;
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]