diff 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
line wrap: on
line diff
--- a/data/model/PowerOfSqrtTwoZoomConstraint.cpp	Fri Dec 09 19:04:33 2016 +0000
+++ b/data/model/PowerOfSqrtTwoZoomConstraint.cpp	Mon Dec 12 15:18:52 2016 +0000
@@ -19,13 +19,30 @@
 #include <cmath>
 
 
-int
-PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize,
+ZoomLevel
+PowerOfSqrtTwoZoomConstraint::getNearestZoomLevel(ZoomLevel requested,
 						  RoundingDirection dir) const
 {
     int type, power;
-    int rv = getNearestBlockSize(blockSize, type, power, dir);
-    return rv;
+    int blockSize;
+
+    if (requested.zone == ZoomLevel::FramesPerPixel) {
+        blockSize = getNearestBlockSize(requested.level, type, power, dir);
+        return { requested.zone, blockSize };
+    } else {
+        RoundingDirection opposite = dir;
+        if (dir == RoundUp) opposite = RoundDown;
+        else if (dir == RoundDown) opposite = RoundUp;
+        blockSize = getNearestBlockSize(requested.level, type, power, opposite);
+        if (blockSize > getMinZoomLevel().level) {
+            blockSize = getMinZoomLevel().level;
+        }
+        if (blockSize == 1) {
+            return { ZoomLevel::FramesPerPixel, 1 };
+        } else {
+            return { requested.zone, blockSize };
+        }
+    }
 }
 
 int
@@ -106,6 +123,9 @@
 	prevBase = base;
     }
 
-    if (result > getMaxZoomLevel()) result = getMaxZoomLevel();
+    if (result > getMaxZoomLevel().level) {
+        result = getMaxZoomLevel().level;
+    }
+
     return result;
 }