Mercurial > hg > svcore
comparison data/model/PowerOfSqrtTwoZoomConstraint.cpp @ 1529:c1c45c5146bb zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 18 Sep 2018 15:06:58 +0100 |
parents | 710e6250a401 a7485c1bdba5 |
children | 1ae6a19464a7 05c3fbaec8ea |
comparison
equal
deleted
inserted
replaced
1527:710e6250a401 | 1529:c1c45c5146bb |
---|---|
15 | 15 |
16 #include "PowerOfSqrtTwoZoomConstraint.h" | 16 #include "PowerOfSqrtTwoZoomConstraint.h" |
17 | 17 |
18 #include <iostream> | 18 #include <iostream> |
19 #include <cmath> | 19 #include <cmath> |
20 | |
21 #include "base/Debug.h" | |
20 | 22 |
21 | 23 |
22 ZoomLevel | 24 ZoomLevel |
23 PowerOfSqrtTwoZoomConstraint::getNearestZoomLevel(ZoomLevel requested, | 25 PowerOfSqrtTwoZoomConstraint::getNearestZoomLevel(ZoomLevel requested, |
24 RoundingDirection dir) const | 26 RoundingDirection dir) const |
49 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, | 51 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, |
50 int &type, | 52 int &type, |
51 int &power, | 53 int &power, |
52 RoundingDirection dir) const | 54 RoundingDirection dir) const |
53 { | 55 { |
54 // cerr << "given " << blockSize << endl; | 56 // SVCERR << "given " << blockSize << endl; |
55 | 57 |
56 int minCachePower = getMinCachePower(); | 58 int minCachePower = getMinCachePower(); |
57 | 59 |
58 if (blockSize < (1 << minCachePower)) { | 60 if (blockSize < (1 << minCachePower)) { |
59 type = -1; | 61 type = -1; |
61 float val = 1.0, prevVal = 1.0; | 63 float val = 1.0, prevVal = 1.0; |
62 while (val + 0.01 < blockSize) { | 64 while (val + 0.01 < blockSize) { |
63 prevVal = val; | 65 prevVal = val; |
64 val *= sqrtf(2.f); | 66 val *= sqrtf(2.f); |
65 } | 67 } |
66 int rval; | 68 int rval = int(val + 0.01f); |
67 if (dir == RoundUp) rval = int(val + 0.01f); | 69 // SVCERR << "got val = " << val << ", rval = " << rval << ", prevVal = " << prevVal << endl; |
68 else if (dir == RoundDown) rval = int(prevVal + 0.01f); | 70 if (rval != blockSize && dir != RoundUp) { |
69 else if (val - float(blockSize) < | 71 if (dir == RoundDown) { |
70 float(blockSize) - prevVal) rval = int(val + 0.01f); | 72 rval = int(prevVal + 0.01f); |
71 else rval = int(prevVal + 0.01); | 73 } else if (val - float(blockSize) < float(blockSize) - prevVal) { |
72 // SVDEBUG << "returning " << rval << endl; | 74 rval = int(val + 0.01f); |
75 } else { | |
76 rval = int(prevVal + 0.01); | |
77 } | |
78 } | |
79 // SVCERR << "returning " << rval << endl; | |
73 return rval; | 80 return rval; |
74 } | 81 } |
75 | 82 |
76 int prevBase = (1 << minCachePower); | 83 int prevBase = (1 << minCachePower); |
77 int prevPower = minCachePower; | 84 int prevPower = minCachePower; |
90 } else { | 97 } else { |
91 base = (((unsigned int)((1 << minCachePower) * sqrt(2.) + 0.01)) | 98 base = (((unsigned int)((1 << minCachePower) * sqrt(2.) + 0.01)) |
92 << (power - minCachePower)); | 99 << (power - minCachePower)); |
93 } | 100 } |
94 | 101 |
95 // SVDEBUG << "Testing base " << base << endl; | 102 // SVCERR << "Testing base " << base << " (i = " << i << ", power = " << power << ", type = " << type << ")" << endl; |
96 | 103 |
97 if (base == blockSize) { | 104 if (base == blockSize) { |
98 result = base; | 105 result = base; |
99 break; | 106 break; |
100 } | 107 } |