[libcamera-devel] [PATCH 04/20] libcamera: geometry: Add isNull() function to Rectangle class

Jacopo Mondi jacopo at jmondi.org
Tue Jul 14 12:41:56 CEST 2020


It's common for code to check if a rectangle is null. Add a helper function
to do so and test the function in test/geometry.cpp

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 include/libcamera/geometry.h | 1 +
 src/libcamera/geometry.cpp   | 6 ++++++
 test/geometry.cpp            | 6 ++++++
 3 files changed, 13 insertions(+)

diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index d217cfd50c86..98a919eb01f1 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -19,6 +19,7 @@ struct Rectangle {
 	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 4594f9ff435f..f79f769bf88e 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -49,6 +49,12 @@ namespace libcamera {
  * \brief The distance between the top and bottom sides
  */
 
+/**
+ * \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 fd0132c03b02..72d938b40e54 100644
--- a/test/geometry.cpp
+++ b/test/geometry.cpp
@@ -36,6 +36,12 @@ protected:
 
 	int run()
 	{
+		Rectangle r{};
+		if (!r.isNull()) {
+			cout << "Null rectangle incorrectly reported as not null" << endl;
+			return TestFail;
+		}
+
 		if (!Size().isNull() || !Size(0, 0).isNull()) {
 			cout << "Null size incorrectly reported as not null" << endl;
 			return TestFail;
-- 
2.27.0



More information about the libcamera-devel mailing list