comparison src/Finder.cpp @ 52:8cbc15519d2c refactors

Fix narrowing float conversions
author Chris Cannam
date Fri, 14 Nov 2014 09:45:56 +0000
parents b0ebc3e2c016
children 331a17753663
comparison
equal deleted inserted replaced
51:e43220da49d1 52:8cbc15519d2c
70 } // getExpandDirection() 70 } // getExpandDirection()
71 71
72 Matcher::Advance 72 Matcher::Advance
73 Finder::getExpandDirection(int row, int col, bool check) 73 Finder::getExpandDirection(int row, int col, bool check)
74 { 74 {
75 int min = getPathCost(row, col); 75 float min = getPathCost(row, col);
76 bestRow = row; 76 bestRow = row;
77 bestCol = col; 77 bestCol = col;
78 getRowRange(col, rowRange); 78 getRowRange(col, rowRange);
79 if (rowRange[1] > row+1) 79 if (rowRange[1] > row+1)
80 rowRange[1] = row+1; // don't cheat by looking at future :) 80 rowRange[1] = row+1; // don't cheat by looking at future :)
81 for (int index = rowRange[0]; index < rowRange[1]; index++) { 81 for (int index = rowRange[0]; index < rowRange[1]; index++) {
82 int tmp = getPathCost(index, col); 82 float tmp = getPathCost(index, col);
83 if (tmp < min) { 83 if (tmp < min) {
84 min = tmp; 84 min = tmp;
85 bestRow = index; 85 bestRow = index;
86 } 86 }
87 } 87 }
88 getColRange(row, colRange); 88 getColRange(row, colRange);
89 if (colRange[1] > col+1) 89 if (colRange[1] > col+1)
90 colRange[1] = col+1; // don't cheat by looking at future :) 90 colRange[1] = col+1; // don't cheat by looking at future :)
91 for (int index = colRange[0]; index < colRange[1]; index++) { 91 for (int index = colRange[0]; index < colRange[1]; index++) {
92 int tmp = getPathCost(row, index); 92 float tmp = getPathCost(row, index);
93 if (tmp < min) { 93 if (tmp < min) {
94 min = tmp; 94 min = tmp;
95 bestCol = index; 95 bestCol = index;
96 bestRow = row; 96 bestRow = row;
97 } 97 }
221 if (thisRowStart < c1) 221 if (thisRowStart < c1)
222 thisRowStart = c1; 222 thisRowStart = c1;
223 for (c = thisRowStart; c <= c2; c++) { 223 for (c = thisRowStart; c <= c2; c++) {
224 if (find(r,c)) { 224 if (find(r,c)) {
225 int i2 = index2; 225 int i2 = index2;
226 int newCost = pm1->m_distance[r][i2]; 226 float newCost = pm1->m_distance[r][i2];
227 Matcher::Advance dir = Matcher::AdvanceNone; 227 Matcher::Advance dir = Matcher::AdvanceNone;
228 if (r > r1) { // not first row 228 if (r > r1) { // not first row
229 int min = -1; 229 float min = -1;
230 if ((c > prevRowStart) && (c <= prevRowStop)) { 230 if ((c > prevRowStart) && (c <= prevRowStop)) {
231 // diagonal from (r-1,c-1) 231 // diagonal from (r-1,c-1)
232 min = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]-1] + 232 min = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]-1] +
233 newCost * 2; 233 newCost * 2;
234 dir = Matcher::AdvanceBoth; 234 dir = Matcher::AdvanceBoth;
235 } 235 }
236 if ((c >= prevRowStart) && (c < prevRowStop)) { 236 if ((c >= prevRowStart) && (c < prevRowStop)) {
237 // vertical from (r-1,c) 237 // vertical from (r-1,c)
238 int cost = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]] + 238 float cost = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]] +
239 newCost; 239 newCost;
240 if ((min == -1) || (cost < min)) { 240 if ((min == -1) || (cost < min)) {
241 min = cost; 241 min = cost;
242 dir = Matcher::AdvanceThis; 242 dir = Matcher::AdvanceThis;
243 } 243 }
244 } 244 }
245 if (c > thisRowStart) { 245 if (c > thisRowStart) {
246 // horizontal from (r,c-1) 246 // horizontal from (r,c-1)
247 int cost =pm1->m_bestPathCost[r][i2-1]+newCost; 247 float cost =pm1->m_bestPathCost[r][i2-1]+newCost;
248 if ((min == -1) || (cost < min)) { 248 if ((min == -1) || (cost < min)) {
249 min = cost; 249 min = cost;
250 dir = Matcher::AdvanceOther; 250 dir = Matcher::AdvanceOther;
251 } 251 }
252 } 252 }
269 int 269 int
270 Finder::retrievePath(bool smooth, vector<int> &pathx, vector<int> &pathy) 270 Finder::retrievePath(bool smooth, vector<int> &pathx, vector<int> &pathy)
271 { 271 {
272 int x = pm2->getFrameCount() - 1; 272 int x = pm2->getFrameCount() - 1;
273 int y = pm1->getFrameCount() - 1; 273 int y = pm1->getFrameCount() - 1;
274 274
275 pathx.clear(); 275 pathx.clear();
276 pathy.clear(); 276 pathy.clear();
277 277
278 while (find(y, x) && ((x > 0) || (y > 0))) { 278 while (find(y, x) && ((x > 0) || (y > 0))) {
279 279