comparison data/model/test/TestZoomConstraints.h @ 1530:bf32b26d1dad zoom

Fix (bodgily) things broken in the merge
author Chris Cannam
date Tue, 18 Sep 2018 16:03:29 +0100
parents a7485c1bdba5
children 2f3a77472c8c
comparison
equal deleted inserted replaced
1529:c1c45c5146bb 1530:bf32b26d1dad
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 2
3 /* 3 /*
4 Sonic Visualiser 4 Sonic Visualiser
5 An audio file viewer and annotation editor. 5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 7
8 This program is free software; you can redistribute it and/or 8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as 9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the 10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file 11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information. 12 COPYING included with this distribution for more information.
13 */ 13 */
14 14
15 #ifndef TEST_ZOOM_CONSTRAINTS_H 15 #ifndef TEST_ZOOM_CONSTRAINTS_H
16 #define TEST_ZOOM_CONSTRAINTS_H 16 #define TEST_ZOOM_CONSTRAINTS_H
17 17
30 { 30 {
31 Q_OBJECT 31 Q_OBJECT
32 32
33 private slots: 33 private slots:
34 void unconstrainedNearest() { 34 void unconstrainedNearest() {
35 // well, this shows how horrible this api is
35 ZoomConstraint c; 36 ZoomConstraint c;
36 QCOMPARE(c.getNearestBlockSize(1), 1); 37 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1)), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
37 QCOMPARE(c.getNearestBlockSize(2), 2); 38 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2)), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
38 QCOMPARE(c.getNearestBlockSize(3), 3); 39 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3)), ZoomLevel(ZoomLevel::FramesPerPixel, 3));
39 QCOMPARE(c.getNearestBlockSize(4), 4); 40 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4)), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
40 QCOMPARE(c.getNearestBlockSize(20), 20); 41 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20)), ZoomLevel(ZoomLevel::FramesPerPixel, 20));
41 QCOMPARE(c.getNearestBlockSize(23), 23); 42 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23)), ZoomLevel(ZoomLevel::FramesPerPixel, 23));
42 int max = c.getMaxZoomLevel(); 43 auto max = c.getMaxZoomLevel();
43 QCOMPARE(c.getNearestBlockSize(max), max); 44 QCOMPARE(c.getNearestZoomLevel(max), max);
44 QCOMPARE(c.getNearestBlockSize(max+1), max); 45 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1)), max);
45 } 46 }
46 47
47 void unconstrainedUp() { 48 void unconstrainedUp() {
48 ZoomConstraint c; 49 ZoomConstraint c;
49 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundUp), 1); 50 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
50 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundUp), 2); 51 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
51 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundUp), 3); 52 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 3));
52 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundUp), 4); 53 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
53 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundUp), 20); 54 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 20));
54 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundUp), 32); 55 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
55 int max = c.getMaxZoomLevel(); 56 auto max = c.getMaxZoomLevel();
56 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundUp), max); 57 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundUp), max);
57 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundUp), max); 58 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundUp), max);
58 } 59 }
59 60
60 void unconstrainedDown() { 61 void unconstrainedDown() {
61 ZoomConstraint c; 62 ZoomConstraint c;
62 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundDown), 1); 63 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
63 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundDown), 2); 64 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
64 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundDown), 3); 65 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 3));
65 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundDown), 4); 66 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
66 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundDown), 20); 67 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 20));
67 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundDown), 32); 68 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
68 int max = c.getMaxZoomLevel(); 69 auto max = c.getMaxZoomLevel();
69 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundDown), max); 70 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundDown), max);
70 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundDown), max); 71 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundDown), max);
71 } 72 }
72 73
73 void powerOfTwoNearest() { 74 void powerOfTwoNearest() {
74 PowerOfTwoZoomConstraint c; 75 PowerOfTwoZoomConstraint c;
75 QCOMPARE(c.getNearestBlockSize(1), 1); 76 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1)), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
76 QCOMPARE(c.getNearestBlockSize(2), 2); 77 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2)), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
77 QCOMPARE(c.getNearestBlockSize(3), 2); 78 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3)), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
78 QCOMPARE(c.getNearestBlockSize(4), 4); 79 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4)), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
79 QCOMPARE(c.getNearestBlockSize(20), 16); 80 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20)), ZoomLevel(ZoomLevel::FramesPerPixel, 16));
80 QCOMPARE(c.getNearestBlockSize(23), 16); 81 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23)), ZoomLevel(ZoomLevel::FramesPerPixel, 16));
81 QCOMPARE(c.getNearestBlockSize(24), 16); 82 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 24)), ZoomLevel(ZoomLevel::FramesPerPixel, 16));
82 QCOMPARE(c.getNearestBlockSize(25), 32); 83 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 25)), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
83 int max = c.getMaxZoomLevel(); 84 auto max = c.getMaxZoomLevel();
84 QCOMPARE(c.getNearestBlockSize(max), max); 85 QCOMPARE(c.getNearestZoomLevel(max), max);
85 QCOMPARE(c.getNearestBlockSize(max+1), max); 86 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1)), max);
86 } 87 }
87 88
88 void powerOfTwoUp() { 89 void powerOfTwoUp() {
89 PowerOfTwoZoomConstraint c; 90 PowerOfTwoZoomConstraint c;
90 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundUp), 1); 91 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
91 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundUp), 2); 92 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
92 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundUp), 4); 93 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
93 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundUp), 4); 94 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
94 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundUp), 32); 95 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
95 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundUp), 32); 96 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
96 QCOMPARE(c.getNearestBlockSize(33, ZoomConstraint::RoundUp), 64); 97 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 33), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 64));
97 int max = c.getMaxZoomLevel(); 98 auto max = c.getMaxZoomLevel();
98 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundUp), max); 99 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundUp), max);
99 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundUp), max); 100 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundUp), max);
100 } 101 }
101 102
102 void powerOfTwoDown() { 103 void powerOfTwoDown() {
103 PowerOfTwoZoomConstraint c; 104 PowerOfTwoZoomConstraint c;
104 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundDown), 1); 105 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
105 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundDown), 2); 106 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
106 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundDown), 2); 107 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
107 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundDown), 4); 108 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
108 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundDown), 16); 109 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 16));
109 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundDown), 32); 110 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
110 QCOMPARE(c.getNearestBlockSize(33, ZoomConstraint::RoundDown), 32); 111 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 33), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
111 int max = c.getMaxZoomLevel(); 112 auto max = c.getMaxZoomLevel();
112 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundDown), max); 113 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundDown), max);
113 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundDown), max); 114 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundDown), max);
114 } 115 }
115 116
116 void powerOfSqrtTwoNearest() { 117 void powerOfSqrtTwoNearest() {
117 PowerOfSqrtTwoZoomConstraint c; 118 PowerOfSqrtTwoZoomConstraint c;
118 QCOMPARE(c.getNearestBlockSize(1), 1); 119 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1)), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
119 QCOMPARE(c.getNearestBlockSize(2), 2); 120 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2)), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
120 QCOMPARE(c.getNearestBlockSize(3), 2); 121 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3)), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
121 QCOMPARE(c.getNearestBlockSize(4), 4); 122 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4)), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
122 QCOMPARE(c.getNearestBlockSize(18), 16); 123 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 18)), ZoomLevel(ZoomLevel::FramesPerPixel, 16));
123 QCOMPARE(c.getNearestBlockSize(19), 16); 124 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 19)), ZoomLevel(ZoomLevel::FramesPerPixel, 16));
124 QCOMPARE(c.getNearestBlockSize(20), 22); 125 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20)), ZoomLevel(ZoomLevel::FramesPerPixel, 22));
125 QCOMPARE(c.getNearestBlockSize(23), 22); 126 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23)), ZoomLevel(ZoomLevel::FramesPerPixel, 22));
126 QCOMPARE(c.getNearestBlockSize(28), 32); 127 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 28)), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
127 // PowerOfSqrtTwoZoomConstraint makes an effort to ensure 128 // PowerOfSqrtTwoZoomConstraint makes an effort to ensure
128 // bigger numbers get rounded to a multiple of something 129 // bigger numbers get rounded to a multiple of something
129 // simple (64 or 90 depending on whether they are power-of-two 130 // simple (64 or 90 depending on whether they are power-of-two
130 // or power-of-sqrt-two types) 131 // or power-of-sqrt-two types)
131 QCOMPARE(c.getNearestBlockSize(800), 720); 132 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 800)), ZoomLevel(ZoomLevel::FramesPerPixel, 720));
132 QCOMPARE(c.getNearestBlockSize(1023), 1024); 133 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1023)), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
133 QCOMPARE(c.getNearestBlockSize(1024), 1024); 134 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1024)), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
134 QCOMPARE(c.getNearestBlockSize(1025), 1024); 135 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1025)), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
135 int max = c.getMaxZoomLevel(); 136 auto max = c.getMaxZoomLevel();
136 QCOMPARE(c.getNearestBlockSize(max), max); 137 QCOMPARE(c.getNearestZoomLevel(max), max);
137 QCOMPARE(c.getNearestBlockSize(max+1), max); 138 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1)), max);
138 } 139 }
139 140
140 void powerOfSqrtTwoUp() { 141 void powerOfSqrtTwoUp() {
141 PowerOfSqrtTwoZoomConstraint c; 142 PowerOfSqrtTwoZoomConstraint c;
142 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundUp), 1); 143 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
143 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundUp), 2); 144 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
144 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundUp), 4); 145 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
145 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundUp), 4); 146 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
146 QCOMPARE(c.getNearestBlockSize(18, ZoomConstraint::RoundUp), 22); 147 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 18), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 22));
147 QCOMPARE(c.getNearestBlockSize(22, ZoomConstraint::RoundUp), 22); 148 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 22), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 22));
148 QCOMPARE(c.getNearestBlockSize(23, ZoomConstraint::RoundUp), 32); 149 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32));
149 QCOMPARE(c.getNearestBlockSize(800, ZoomConstraint::RoundUp), 1024); 150 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 800), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
150 QCOMPARE(c.getNearestBlockSize(1023, ZoomConstraint::RoundUp), 1024); 151 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1023), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
151 QCOMPARE(c.getNearestBlockSize(1024, ZoomConstraint::RoundUp), 1024); 152 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1024), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
152 // see comment above 153 // see comment above
153 QCOMPARE(c.getNearestBlockSize(1025, ZoomConstraint::RoundUp), 1440); 154 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1025), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1440));
154 int max = c.getMaxZoomLevel(); 155 auto max = c.getMaxZoomLevel();
155 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundUp), max); 156 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundUp), max);
156 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundUp), max); 157 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundUp), max);
157 } 158 }
158 159
159 void powerOfSqrtTwoDown() { 160 void powerOfSqrtTwoDown() {
160 PowerOfSqrtTwoZoomConstraint c; 161 PowerOfSqrtTwoZoomConstraint c;
161 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundDown), 1); 162 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1));
162 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundDown), 2); 163 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
163 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundDown), 2); 164 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2));
164 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundDown), 4); 165 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 4));
165 QCOMPARE(c.getNearestBlockSize(18, ZoomConstraint::RoundDown), 16); 166 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 18), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 16));
166 QCOMPARE(c.getNearestBlockSize(22, ZoomConstraint::RoundDown), 22); 167 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 22), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 22));
167 QCOMPARE(c.getNearestBlockSize(23, ZoomConstraint::RoundDown), 22); 168 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 22));
168 // see comment above 169 // see comment above
169 QCOMPARE(c.getNearestBlockSize(800, ZoomConstraint::RoundDown), 720); 170 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 800), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 720));
170 QCOMPARE(c.getNearestBlockSize(1023, ZoomConstraint::RoundDown), 720); 171 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1023), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 720));
171 QCOMPARE(c.getNearestBlockSize(1024, ZoomConstraint::RoundDown), 1024); 172 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1024), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
172 QCOMPARE(c.getNearestBlockSize(1025, ZoomConstraint::RoundDown), 1024); 173 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1025), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1024));
173 int max = c.getMaxZoomLevel(); 174 auto max = c.getMaxZoomLevel();
174 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundDown), max); 175 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundDown), max);
175 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundDown), max); 176 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundDown), max);
176 } 177 }
177 }; 178 };
178 179
179 #endif 180 #endif
180 181