comparison 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
comparison
equal deleted inserted replaced
1527:710e6250a401 1529:c1c45c5146bb
45 45
46 int 46 int
47 PowerOfTwoZoomConstraint::getNearestBlockSize(int req, 47 PowerOfTwoZoomConstraint::getNearestBlockSize(int req,
48 RoundingDirection dir) const 48 RoundingDirection dir) const
49 { 49 {
50 int result = 0; 50 int max = getMaxZoomLevel();
51 51
52 for (int bs = 1; ; bs *= 2) { 52 if (req > max) {
53 if (bs >= req) { 53 return max;
54 }
55
56 for (int bs = 1; bs <= max; bs *= 2) {
57 if (bs < req) {
58 continue;
59 } else if (bs == req) {
60 return bs;
61 } else { // bs > req
54 if (dir == RoundNearest) { 62 if (dir == RoundNearest) {
55 if (bs - req < req - bs/2) { 63 if (bs - req < req - bs/2) {
56 result = bs; 64 return bs;
57 break;
58 } else { 65 } else {
59 result = bs/2; 66 return bs/2;
60 break;
61 } 67 }
62 } else if (dir == RoundDown) { 68 } else if (dir == RoundDown) {
63 result = bs/2; 69 return bs/2;
64 break;
65 } else { 70 } else {
66 result = bs; 71 return bs;
67 break;
68 } 72 }
69 } 73 }
70 } 74 }
71 75
72 if (result > getMaxZoomLevel().level) result = getMaxZoomLevel().level; 76 return max;
73 return result;
74 } 77 }
75 78