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

Some hackery toward having a zoomlevel type
author Chris Cannam
date Mon, 12 Dec 2016 15:18:52 +0000
parents 59e7fe1b1003
children 710e6250a401
comparison
equal deleted inserted replaced
1323:4dbb7a7c9c28 1324:d4a28d1479a8
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "PowerOfTwoZoomConstraint.h" 16 #include "PowerOfTwoZoomConstraint.h"
17
18 ZoomLevel
19 PowerOfTwoZoomConstraint::getNearestZoomLevel(ZoomLevel requested,
20 RoundingDirection dir) const
21 {
22 int blockSize;
23
24 if (requested.zone == ZoomLevel::FramesPerPixel) {
25 blockSize = getNearestBlockSize(requested.level, dir);
26 if (blockSize > getMaxZoomLevel().level) {
27 blockSize = getMaxZoomLevel().level;
28 }
29 return { requested.zone, blockSize };
30 } else {
31 RoundingDirection opposite = dir;
32 if (dir == RoundUp) opposite = RoundDown;
33 else if (dir == RoundDown) opposite = RoundUp;
34 blockSize = getNearestBlockSize(requested.level, opposite);
35 if (blockSize > getMinZoomLevel().level) {
36 blockSize = getMinZoomLevel().level;
37 }
38 if (blockSize == 1) {
39 return { ZoomLevel::FramesPerPixel, 1 };
40 } else {
41 return { requested.zone, blockSize };
42 }
43 }
44 }
17 45
18 int 46 int
19 PowerOfTwoZoomConstraint::getNearestBlockSize(int req, 47 PowerOfTwoZoomConstraint::getNearestBlockSize(int req,
20 RoundingDirection dir) const 48 RoundingDirection dir) const
21 { 49 {
39 break; 67 break;
40 } 68 }
41 } 69 }
42 } 70 }
43 71
44 if (result > getMaxZoomLevel()) result = getMaxZoomLevel(); 72 if (result > getMaxZoomLevel().level) result = getMaxZoomLevel().level;
45 return result; 73 return result;
46 } 74 }
47 75