Issue #116 add range check and simplify some conditions

This commit is contained in:
Sean Owen 2014-04-18 11:06:08 +01:00
parent 41caac38e8
commit 7d878d701e

View file

@ -241,34 +241,34 @@ public class FinderPatternFinder {
* @return true if proportions are withing expected limits
*/
private boolean crossCheckDiagonal(int startI, int centerJ, int maxCount, int originalStateCountTotal) {
int maxI = image.getHeight();
int maxJ = image.getWidth();
int[] stateCount = getCrossCheckStateCount();
// Start counting up, left from center finding black center mass
int i = 0;
while (startI - i >= 0 && image.get(centerJ - i, startI - i)) {
while (startI >= i && centerJ >= i && image.get(centerJ - i, startI - i)) {
stateCount[2]++;
i++;
}
if ((startI - i < 0) || (centerJ - i < 0)) {
if (startI < i || centerJ < i) {
return false;
}
// Continue up, left finding white space
while ((startI - i >= 0) && (centerJ - i >= 0) && !image.get(centerJ - i, startI - i) && stateCount[1] <= maxCount) {
while (startI >= i && centerJ >= i && !image.get(centerJ - i, startI - i) &&
stateCount[1] <= maxCount) {
stateCount[1]++;
i++;
}
// If already too many modules in this state or ran off the edge:
if ((startI - i < 0) || (centerJ - i < 0) || stateCount[1] > maxCount) {
if (startI < i || centerJ < i || stateCount[1] > maxCount) {
return false;
}
// Continue up, left finding black border
while ((startI - i >= 0) && (centerJ - i >= 0) && image.get(centerJ - i, startI - i) && stateCount[0] <= maxCount) {
while (startI >= i && centerJ >= i && image.get(centerJ - i, startI - i) &&
stateCount[0] <= maxCount) {
stateCount[0]++;
i++;
}
@ -276,28 +276,33 @@ public class FinderPatternFinder {
return false;
}
int maxI = image.getHeight();
int maxJ = image.getWidth();
// Now also count down, right from center
i = 1;
while ((startI + i < maxI) && (centerJ + i < maxJ) && image.get(centerJ + i, startI + i)) {
while (startI + i < maxI && centerJ + i < maxJ && image.get(centerJ + i, startI + i)) {
stateCount[2]++;
i++;
}
// Ran off the edge?
if ((startI + i >= maxI) || (centerJ + i >= maxJ)) {
if (startI + i >= maxI || centerJ + i >= maxJ) {
return false;
}
while ((startI + i < maxI) && (centerJ + i < maxJ) && !image.get(centerJ + i, startI + i) && stateCount[3] < maxCount) {
while (startI + i < maxI && centerJ + i < maxJ && !image.get(centerJ + i, startI + i) &&
stateCount[3] < maxCount) {
stateCount[3]++;
i++;
}
if ((startI + i >= maxI) || (centerJ + i >= maxJ) || stateCount[3] >= maxCount) {
if (startI + i >= maxI || centerJ + i >= maxJ || stateCount[3] >= maxCount) {
return false;
}
while ((startI + i < maxI) && (centerJ + i < maxJ) && image.get(centerJ + i, startI + i) && stateCount[4] < maxCount) {
while (startI + i < maxI && centerJ + i < maxJ && image.get(centerJ + i, startI + i) &&
stateCount[4] < maxCount) {
stateCount[4]++;
i++;
}