summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libcamera/geometry.h1
-rw-r--r--src/libcamera/geometry.cpp6
-rw-r--r--test/geometry.cpp14
3 files changed, 21 insertions, 0 deletions
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index d858f85c..02fb63c0 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -181,6 +181,7 @@ public:
unsigned int width;
unsigned int height;
+ bool isNull() const { return !width && !height; }
const std::string toString() const;
};
diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index 23181bde..b12e1a62 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -386,6 +386,12 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs)
*/
/**
+ * \fn bool Rectangle::isNull() const
+ * \brief Check if the rectangle is null
+ * \return True if both the width and height are 0, or false otherwise
+ */
+
+/**
* \brief Assemble and return a string describing the rectangle
* \return A string describing the Rectangle
*/
diff --git a/test/geometry.cpp b/test/geometry.cpp
index 1a9fc1b8..08e268c9 100644
--- a/test/geometry.cpp
+++ b/test/geometry.cpp
@@ -182,6 +182,20 @@ protected:
if (!compare(Size(200, 100), Size(100, 200), &operator>=, ">=", true))
return TestFail;
+ /* Test Rectangle::isNull(). */
+ if (!Rectangle(0, 0, 0, 0).isNull() ||
+ !Rectangle(1, 1, 0, 0).isNull()) {
+ cout << "Null rectangle incorrectly reported as not null" << endl;
+ return TestFail;
+ }
+
+ if (Rectangle(0, 0, 0, 1).isNull() ||
+ Rectangle(0, 0, 1, 0).isNull() ||
+ Rectangle(0, 0, 1, 1).isNull()) {
+ cout << "Non-null rectangle incorrectly reported as null" << endl;
+ return TestFail;
+ }
+
return TestPass;
}
};