Message ID | 20200714104212.48683-5-jacopo@jmondi.org |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Jacopo, Thank you for the patch. On Tue, Jul 14, 2020 at 12:41:56PM +0200, Jacopo Mondi wrote: > 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@ragnatech.se> > Signed-off-by: Jacopo Mondi <jacopo@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; > + } Let's test the other case too. I think you can write this 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; } Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > + > if (!Size().isNull() || !Size(0, 0).isNull()) { > cout << "Null size incorrectly reported as not null" << endl; > return TestFail;
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;