comparison data/model/PowerOfSqrtTwoZoomConstraint.cpp @ 1324:d4a28d1479a8 zoom

Some hackery toward having a zoomlevel type
author Chris Cannam
date Mon, 12 Dec 2016 15:18:52 +0000
parents cc27f35aa75c
children 710e6250a401
comparison
equal deleted inserted replaced
1323:4dbb7a7c9c28 1324:d4a28d1479a8
17 17
18 #include <iostream> 18 #include <iostream>
19 #include <cmath> 19 #include <cmath>
20 20
21 21
22 int 22 ZoomLevel
23 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, 23 PowerOfSqrtTwoZoomConstraint::getNearestZoomLevel(ZoomLevel requested,
24 RoundingDirection dir) const 24 RoundingDirection dir) const
25 { 25 {
26 int type, power; 26 int type, power;
27 int rv = getNearestBlockSize(blockSize, type, power, dir); 27 int blockSize;
28 return rv; 28
29 if (requested.zone == ZoomLevel::FramesPerPixel) {
30 blockSize = getNearestBlockSize(requested.level, type, power, dir);
31 return { requested.zone, blockSize };
32 } else {
33 RoundingDirection opposite = dir;
34 if (dir == RoundUp) opposite = RoundDown;
35 else if (dir == RoundDown) opposite = RoundUp;
36 blockSize = getNearestBlockSize(requested.level, type, power, opposite);
37 if (blockSize > getMinZoomLevel().level) {
38 blockSize = getMinZoomLevel().level;
39 }
40 if (blockSize == 1) {
41 return { ZoomLevel::FramesPerPixel, 1 };
42 } else {
43 return { requested.zone, blockSize };
44 }
45 }
29 } 46 }
30 47
31 int 48 int
32 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, 49 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize,
33 int &type, 50 int &type,
104 prevType = type; 121 prevType = type;
105 prevPower = power; 122 prevPower = power;
106 prevBase = base; 123 prevBase = base;
107 } 124 }
108 125
109 if (result > getMaxZoomLevel()) result = getMaxZoomLevel(); 126 if (result > getMaxZoomLevel().level) {
127 result = getMaxZoomLevel().level;
128 }
129
110 return result; 130 return result;
111 } 131 }