summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-10-13 04:11:18 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-10-15 05:05:17 +0300
commite229b35edff5aeb2dbe819ec7b4cf9816f90460a (patch)
tree17d07579c82477398af84dead35a3e1e4b1c93ea /test
parentccec150589a177654b9039d21163c36ccff85cff (diff)
libcamera: geometry: Add Size members to grown or shrink by a margin
Add four new member functions to the Size class (two in-place and two const) to grow and shrink a Size by given margins. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'test')
-rw-r--r--test/geometry.cpp48
1 files changed, 43 insertions, 5 deletions
diff --git a/test/geometry.cpp b/test/geometry.cpp
index d13c88bf..51256924 100644
--- a/test/geometry.cpp
+++ b/test/geometry.cpp
@@ -104,7 +104,10 @@ protected:
return TestFail;
}
- /* Test alignDownTo(), alignUpTo(), boundTo() and expandTo() */
+ /*
+ * Test alignDownTo(), alignUpTo(), boundTo(), expandTo(),
+ * growBy() and shrinkBy()
+ */
Size s(50, 50);
s.alignDownTo(16, 16);
@@ -131,14 +134,36 @@ protected:
return TestFail;
}
- s.alignDownTo(16, 16).alignUpTo(32, 32)
- .boundTo({ 40, 80 }).expandTo({ 16, 80 });
- if (s != Size(40, 80)) {
+ s.growBy({ 10, 20 });
+ if (s != Size(60, 70)) {
+ cout << "Size::growBy() test failed" << endl;
+ return TestFail;
+ }
+
+ s.shrinkBy({ 20, 10 });
+ if (s != Size(40, 60)) {
+ cout << "Size::shrinkBy() test failed" << endl;
+ return TestFail;
+ }
+
+ s.shrinkBy({ 100, 100 });
+ if (s != Size(0, 0)) {
+ cout << "Size::shrinkBy() clamp test failed" << endl;
+ return TestFail;
+ }
+
+ s = Size(50,50).alignDownTo(16, 16).alignUpTo(32, 32)
+ .boundTo({ 40, 80 }).expandTo({ 16, 80 })
+ .growBy({ 4, 4 }).shrinkBy({ 10, 20 });
+ if (s != Size(34, 64)) {
cout << "Size chained in-place modifiers test failed" << endl;
return TestFail;
}
- /* Test alignedDownTo(), alignedUpTo(), boundedTo() and expandedTo() */
+ /*
+ * Test alignedDownTo(), alignedUpTo(), boundedTo(),
+ * expandedTo(), grownBy() and shrunkBy()
+ */
if (Size(0, 0).alignedDownTo(16, 8) != Size(0, 0) ||
Size(1, 1).alignedDownTo(16, 8) != Size(0, 0) ||
Size(16, 8).alignedDownTo(16, 8) != Size(16, 8)) {
@@ -167,6 +192,19 @@ protected:
return TestFail;
}
+ if (Size(0, 0).grownBy({ 10, 20 }) != Size(10, 20) ||
+ Size(200, 50).grownBy({ 10, 20 }) != Size(210, 70)) {
+ cout << "Size::grownBy() test failed" << endl;
+ return TestFail;
+ }
+
+ if (Size(200, 50).shrunkBy({ 10, 20 }) != Size(190, 30) ||
+ Size(200, 50).shrunkBy({ 10, 100 }) != Size(190, 0) ||
+ Size(200, 50).shrunkBy({ 300, 20 }) != Size(0, 30)) {
+ cout << "Size::shrunkBy() test failed" << endl;
+ return TestFail;
+ }
+
/* Aspect ratio tests */
if (Size(0, 0).boundedToAspectRatio(Size(4, 3)) != Size(0, 0) ||
Size(1920, 1440).boundedToAspectRatio(Size(16, 9)) != Size(1920, 1080) ||