Mercurial > hg > svcore
diff data/model/PowerOfSqrtTwoZoomConstraint.cpp @ 1450:a12fd0456f0c streaming-csv-writer
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 17 Apr 2018 10:35:42 +0100 |
parents | 48e9f538e6e9 |
children | 710e6250a401 a7485c1bdba5 |
line wrap: on
line diff
--- a/data/model/PowerOfSqrtTwoZoomConstraint.cpp Tue Apr 17 10:03:51 2018 +0100 +++ b/data/model/PowerOfSqrtTwoZoomConstraint.cpp Tue Apr 17 10:35:42 2018 +0100 @@ -21,7 +21,7 @@ int PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, - RoundingDirection dir) const + RoundingDirection dir) const { int type, power; int rv = getNearestBlockSize(blockSize, type, power, dir); @@ -30,30 +30,30 @@ int PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, - int &type, - int &power, - RoundingDirection dir) const + int &type, + int &power, + RoundingDirection dir) const { // cerr << "given " << blockSize << endl; int minCachePower = getMinCachePower(); if (blockSize < (1 << minCachePower)) { - type = -1; - power = 0; - float val = 1.0, prevVal = 1.0; - while (val + 0.01 < blockSize) { - prevVal = val; - val *= sqrtf(2.f); - } - int rval; - if (dir == RoundUp) rval = int(val + 0.01f); - else if (dir == RoundDown) rval = int(prevVal + 0.01f); - else if (val - float(blockSize) < + type = -1; + power = 0; + float val = 1.0, prevVal = 1.0; + while (val + 0.01 < blockSize) { + prevVal = val; + val *= sqrtf(2.f); + } + int rval; + if (dir == RoundUp) rval = int(val + 0.01f); + else if (dir == RoundDown) rval = int(prevVal + 0.01f); + else if (val - float(blockSize) < float(blockSize) - prevVal) rval = int(val + 0.01f); - else rval = int(prevVal + 0.01); -// SVDEBUG << "returning " << rval << endl; - return rval; + else rval = int(prevVal + 0.01); +// SVDEBUG << "returning " << rval << endl; + return rval; } int prevBase = (1 << minCachePower); @@ -64,46 +64,46 @@ for (unsigned int i = 0; ; ++i) { - power = minCachePower + i/2; - type = i % 2; + power = minCachePower + i/2; + type = i % 2; - int base; - if (type == 0) { - base = (1 << power); - } else { - base = (((unsigned int)((1 << minCachePower) * sqrt(2.) + 0.01)) - << (power - minCachePower)); - } + int base; + if (type == 0) { + base = (1 << power); + } else { + base = (((unsigned int)((1 << minCachePower) * sqrt(2.) + 0.01)) + << (power - minCachePower)); + } -// SVDEBUG << "Testing base " << base << endl; +// SVDEBUG << "Testing base " << base << endl; if (base == blockSize) { result = base; break; } - if (base > blockSize) { - if (dir == RoundNearest) { - if (base - blockSize < blockSize - prevBase) { - dir = RoundUp; - } else { - dir = RoundDown; - } - } - if (dir == RoundUp) { - result = base; - break; - } else { - type = prevType; - power = prevPower; - result = prevBase; - break; - } - } + if (base > blockSize) { + if (dir == RoundNearest) { + if (base - blockSize < blockSize - prevBase) { + dir = RoundUp; + } else { + dir = RoundDown; + } + } + if (dir == RoundUp) { + result = base; + break; + } else { + type = prevType; + power = prevPower; + result = prevBase; + break; + } + } - prevType = type; - prevPower = power; - prevBase = base; + prevType = type; + prevPower = power; + prevBase = base; } if (result > getMaxZoomLevel()) result = getMaxZoomLevel();