Mercurial > hg > svcore
comparison data/model/PowerOfSqrtTwoZoomConstraint.cpp @ 929:59e7fe1b1003 warnfix_no_size_t
Unsigned removals and warning fixes in data/
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 14:33:42 +0100 |
parents | e802e550a1f2 |
children | cc27f35aa75c |
comparison
equal
deleted
inserted
replaced
928:6a94bb528e9d | 929:59e7fe1b1003 |
---|---|
17 | 17 |
18 #include <iostream> | 18 #include <iostream> |
19 #include <cmath> | 19 #include <cmath> |
20 | 20 |
21 | 21 |
22 size_t | 22 int |
23 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(size_t blockSize, | 23 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, |
24 RoundingDirection dir) const | 24 RoundingDirection dir) const |
25 { | 25 { |
26 int type, power; | 26 int type, power; |
27 size_t rv = getNearestBlockSize(blockSize, type, power, dir); | 27 int rv = getNearestBlockSize(blockSize, type, power, dir); |
28 return rv; | 28 return rv; |
29 } | 29 } |
30 | 30 |
31 size_t | 31 int |
32 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(size_t blockSize, | 32 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, |
33 int &type, | 33 int &type, |
34 int &power, | 34 int &power, |
35 RoundingDirection dir) const | 35 RoundingDirection dir) const |
36 { | 36 { |
37 // cerr << "given " << blockSize << endl; | 37 // cerr << "given " << blockSize << endl; |
38 | 38 |
39 size_t minCachePower = getMinCachePower(); | 39 int minCachePower = getMinCachePower(); |
40 | 40 |
41 if (blockSize < (1U << minCachePower)) { | 41 if (blockSize < (1 << minCachePower)) { |
42 type = -1; | 42 type = -1; |
43 power = 0; | 43 power = 0; |
44 float val = 1.0, prevVal = 1.0; | 44 float val = 1.0, prevVal = 1.0; |
45 while (val + 0.01 < blockSize) { | 45 while (val + 0.01 < blockSize) { |
46 prevVal = val; | 46 prevVal = val; |
47 val *= sqrt(2.f); | 47 val *= sqrt(2.f); |
48 } | 48 } |
49 size_t rval; | 49 int rval; |
50 if (dir == RoundUp) rval = size_t(val + 0.01); | 50 if (dir == RoundUp) rval = int(val + 0.01); |
51 else if (dir == RoundDown) rval = size_t(prevVal + 0.01); | 51 else if (dir == RoundDown) rval = int(prevVal + 0.01); |
52 else if (val - blockSize < blockSize - prevVal) rval = size_t(val + 0.01); | 52 else if (val - blockSize < blockSize - prevVal) rval = int(val + 0.01); |
53 else rval = size_t(prevVal + 0.01); | 53 else rval = int(prevVal + 0.01); |
54 // SVDEBUG << "returning " << rval << endl; | 54 // SVDEBUG << "returning " << rval << endl; |
55 return rval; | 55 return rval; |
56 } | 56 } |
57 | 57 |
58 unsigned int prevBase = (1 << minCachePower); | 58 int prevBase = (1 << minCachePower); |
59 unsigned int prevPower = minCachePower; | 59 int prevPower = minCachePower; |
60 unsigned int prevType = 0; | 60 int prevType = 0; |
61 | 61 |
62 size_t result = 0; | 62 int result = 0; |
63 | 63 |
64 for (unsigned int i = 0; ; ++i) { | 64 for (unsigned int i = 0; ; ++i) { |
65 | 65 |
66 power = minCachePower + i/2; | 66 power = minCachePower + i/2; |
67 type = i % 2; | 67 type = i % 2; |
68 | 68 |
69 unsigned int base; | 69 int base; |
70 if (type == 0) { | 70 if (type == 0) { |
71 base = (1 << power); | 71 base = (1 << power); |
72 } else { | 72 } else { |
73 base = (((unsigned int)((1 << minCachePower) * sqrt(2.) + 0.01)) | 73 base = (((unsigned int)((1 << minCachePower) * sqrt(2.) + 0.01)) |
74 << (power - minCachePower)); | 74 << (power - minCachePower)); |