Mercurial > hg > svcore
diff data/model/PowerOfTwoZoomConstraint.cpp @ 1529:c1c45c5146bb zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 18 Sep 2018 15:06:58 +0100 |
parents | 710e6250a401 a7485c1bdba5 |
children | bf32b26d1dad |
line wrap: on
line diff
--- a/data/model/PowerOfTwoZoomConstraint.cpp Mon Sep 17 13:51:14 2018 +0100 +++ b/data/model/PowerOfTwoZoomConstraint.cpp Tue Sep 18 15:06:58 2018 +0100 @@ -47,29 +47,32 @@ PowerOfTwoZoomConstraint::getNearestBlockSize(int req, RoundingDirection dir) const { - int result = 0; + int max = getMaxZoomLevel(); - for (int bs = 1; ; bs *= 2) { - if (bs >= req) { + if (req > max) { + return max; + } + + for (int bs = 1; bs <= max; bs *= 2) { + if (bs < req) { + continue; + } else if (bs == req) { + return bs; + } else { // bs > req if (dir == RoundNearest) { if (bs - req < req - bs/2) { - result = bs; - break; + return bs; } else { - result = bs/2; - break; + return bs/2; } } else if (dir == RoundDown) { - result = bs/2; - break; + return bs/2; } else { - result = bs; - break; + return bs; } } } - if (result > getMaxZoomLevel().level) result = getMaxZoomLevel().level; - return result; + return max; }