comparison data/model/PowerOfTwoZoomConstraint.cpp @ 1429:48e9f538e6e9

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents 59e7fe1b1003
children 710e6250a401 a7485c1bdba5
comparison
equal deleted inserted replaced
1428:87ae75da6527 1429:48e9f538e6e9
15 15
16 #include "PowerOfTwoZoomConstraint.h" 16 #include "PowerOfTwoZoomConstraint.h"
17 17
18 int 18 int
19 PowerOfTwoZoomConstraint::getNearestBlockSize(int req, 19 PowerOfTwoZoomConstraint::getNearestBlockSize(int req,
20 RoundingDirection dir) const 20 RoundingDirection dir) const
21 { 21 {
22 int result = 0; 22 int result = 0;
23 23
24 for (int bs = 1; ; bs *= 2) { 24 for (int bs = 1; ; bs *= 2) {
25 if (bs >= req) { 25 if (bs >= req) {
26 if (dir == RoundNearest) { 26 if (dir == RoundNearest) {
27 if (bs - req < req - bs/2) { 27 if (bs - req < req - bs/2) {
28 result = bs; 28 result = bs;
29 break; 29 break;
30 } else { 30 } else {
31 result = bs/2; 31 result = bs/2;
32 break; 32 break;
33 } 33 }
34 } else if (dir == RoundDown) { 34 } else if (dir == RoundDown) {
35 result = bs/2; 35 result = bs/2;
36 break; 36 break;
37 } else { 37 } else {
38 result = bs; 38 result = bs;
39 break; 39 break;
40 } 40 }
41 } 41 }
42 } 42 }
43 43
44 if (result > getMaxZoomLevel()) result = getMaxZoomLevel(); 44 if (result > getMaxZoomLevel()) result = getMaxZoomLevel();
45 return result; 45 return result;
46 } 46 }