[libcamera-devel,v2,16/20] libcamera: geometry: Add isNull() function to Rectangle class

Message ID 20200709084128.5316-17-jacopo@jmondi.org
State Accepted
Headers show
Series
  • libcamera: ipu3: Rework configuration
Related show

Commit Message

Jacopo Mondi July 9, 2020, 8:41 a.m. UTC
It's common for code to check if a rectangle is null. Add a helper function
to do so.

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 ++++++
 2 files changed, 7 insertions(+)

Comments

Laurent Pinchart July 10, 2020, 12:13 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Thu, Jul 09, 2020 at 10:41:24AM +0200, Jacopo Mondi wrote:
> It's common for code to check if a rectangle is null. Add a helper function
> to do so.
> 
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  include/libcamera/geometry.h | 1 +
>  src/libcamera/geometry.cpp   | 6 ++++++
>  2 files changed, 7 insertions(+)
> 
> diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
> index 7d4b8bcfe3d8..44561d9cc5a4 100644
> --- a/include/libcamera/geometry.h
> +++ b/include/libcamera/geometry.h
> @@ -18,6 +18,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 24c44fb43acf..af29ed1119fe 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
Laurent Pinchart July 10, 2020, 12:13 p.m. UTC | #2
On Fri, Jul 10, 2020 at 03:13:12PM +0300, Laurent Pinchart wrote:
> Hi Jacopo,
> 
> Thank you for the patch.
> 
> On Thu, Jul 09, 2020 at 10:41:24AM +0200, Jacopo Mondi wrote:
> > It's common for code to check if a rectangle is null. Add a helper function
> > to do so.
> > 
> > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I spoke a bit too fast, you should add a test case for this.

> > ---
> >  include/libcamera/geometry.h | 1 +
> >  src/libcamera/geometry.cpp   | 6 ++++++
> >  2 files changed, 7 insertions(+)
> > 
> > diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
> > index 7d4b8bcfe3d8..44561d9cc5a4 100644
> > --- a/include/libcamera/geometry.h
> > +++ b/include/libcamera/geometry.h
> > @@ -18,6 +18,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 24c44fb43acf..af29ed1119fe 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

Patch

diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index 7d4b8bcfe3d8..44561d9cc5a4 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -18,6 +18,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 24c44fb43acf..af29ed1119fe 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