changeset 89:7785bb8a1be6 refactors

Fix diagonal handling: there was an implicit fixed diagonal weight of 2 in comparison of diagmin+distance to othermin directly
author Chris Cannam
date Thu, 27 Nov 2014 12:59:23 +0000
parents 1f5291760ed9
children 7bb586054b16
files src/Matcher.cpp
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/Matcher.cpp	Thu Nov 27 12:57:59 2014 +0000
+++ b/src/Matcher.cpp	Thu Nov 27 12:59:23 2014 +0000
@@ -278,6 +278,8 @@
             (m_frames[frameIndex],
              m_otherMatcher->m_frames[index % m_blockSize]);
 
+        float diagDistance = distance * m_params.diagonalWeight;
+
         if ((m_frameCount == 0) && (index == 0)) { // first element
 
             updateValue(0, 0, AdvanceNone,
@@ -317,7 +319,7 @@
             } else {
 
                 double min1 = getPathCost(m_frameCount - 1, index - 1);
-                if (min1 + distance <= min2) {
+                if (min1 + diagDistance <= min2 + distance) {
                     updateValue(m_frameCount, index, AdvanceBoth,
                                 min1, distance);
                 } else {
@@ -338,9 +340,13 @@
                      << " min2 = " << min2 << ", " 
                      << " min3 = " << min3 << endl;
             }
+
+            double cost1 = min1 + distance;
+            double cost2 = min2 + distance;
+            double cost3 = min3 + diagDistance;
             
-            if (min1 <= min2) {
-                if (min3 + distance <= min1) {
+            if (cost1 <= cost2) {
+                if (cost3 <= cost1) {
                     updateValue(m_frameCount, index, AdvanceBoth,
                                 min3, distance);
                 } else {
@@ -348,7 +354,7 @@
                                 min1, distance);
                 }
             } else {
-                if (min3 + distance <= min2) {
+                if (cost3 <= cost2) {
                     updateValue(m_frameCount, index, AdvanceBoth,
                                 min3, distance);
                 } else {