Mercurial > hg > svcore
comparison data/model/PowerOfTwoZoomConstraint.cpp @ 1527:710e6250a401 zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:14 +0100 |
parents | d4a28d1479a8 48e9f538e6e9 |
children | c1c45c5146bb |
comparison
equal
deleted
inserted
replaced
1324:d4a28d1479a8 | 1527:710e6250a401 |
---|---|
43 } | 43 } |
44 } | 44 } |
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 result = 0; |
51 | 51 |
52 for (int bs = 1; ; bs *= 2) { | 52 for (int bs = 1; ; bs *= 2) { |
53 if (bs >= req) { | 53 if (bs >= req) { |
54 if (dir == RoundNearest) { | 54 if (dir == RoundNearest) { |
55 if (bs - req < req - bs/2) { | 55 if (bs - req < req - bs/2) { |
56 result = bs; | 56 result = bs; |
57 break; | 57 break; |
58 } else { | 58 } else { |
59 result = bs/2; | 59 result = bs/2; |
60 break; | 60 break; |
61 } | 61 } |
62 } else if (dir == RoundDown) { | 62 } else if (dir == RoundDown) { |
63 result = bs/2; | 63 result = bs/2; |
64 break; | 64 break; |
65 } else { | 65 } else { |
66 result = bs; | 66 result = bs; |
67 break; | 67 break; |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 if (result > getMaxZoomLevel().level) result = getMaxZoomLevel().level; | 72 if (result > getMaxZoomLevel().level) result = getMaxZoomLevel().level; |
73 return result; | 73 return result; |
74 } | 74 } |