diff layer/TimeValueLayer.cpp @ 851:cf23656a8ca6

Clarify some sneaky logic
author Chris Cannam
date Wed, 03 Sep 2014 11:49:31 +0100
parents 1d526ba11a24
children 6c6e34b09688
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp	Wed Sep 03 11:48:18 2014 +0100
+++ b/layer/TimeValueLayer.cpp	Wed Sep 03 11:49:31 2014 +0100
@@ -733,13 +733,21 @@
     i = close.begin();
 
     // Scan through the close points first, then the more distant ones
-    // if no suitable close one is found
+    // if no suitable close one is found. So the while-termination
+    // condition here can only happen once i has passed through the
+    // whole of the close container and then the whole of the separate
+    // points container. The two iterators are totally distinct, but
+    // have the same type so we cheekily use the same variable and a
+    // single loop for both.
 
     while (i != points.end()) {
 
-        if (i == close.end()) {
-            i = points.begin();
-            distant = true;
+        if (!distant) {
+            if (i == close.end()) {
+                // switch from the close container to the points container
+                i = points.begin();
+                distant = true;
+            }
         }
 
 	if (snap == SnapRight) {