[v5,1/3] libcamera: Add rectangle two-point constructor
diff mbox series

Message ID 20240923093317.3500444-2-chenghaoyang@google.com
State Superseded
Headers show
Series
  • Add Face Detection Controls
Related show

Commit Message

Cheng-Hao Yang Sept. 23, 2024, 9:30 a.m. UTC
From: Yudhistira Erlandinata <yerlandinata@chromium.org>

Add a Rectangle constructor that accepts two points:
topLeft and bottomRight.

Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 include/libcamera/geometry.h |  7 +++++++
 src/libcamera/geometry.cpp   |  7 +++++++
 test/geometry.cpp            | 14 ++++++++++++++
 3 files changed, 28 insertions(+)

Comments

Kieran Bingham Sept. 23, 2024, 10:32 a.m. UTC | #1
Quoting Harvey Yang (2024-09-23 10:30:44)
> From: Yudhistira Erlandinata <yerlandinata@chromium.org>
> 
> Add a Rectangle constructor that accepts two points:
> topLeft and bottomRight.
> 
> Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
> Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>  include/libcamera/geometry.h |  7 +++++++
>  src/libcamera/geometry.cpp   |  7 +++++++
>  test/geometry.cpp            | 14 ++++++++++++++
>  3 files changed, 28 insertions(+)
> 
> diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
> index 3e6f0f5d..5949d55c 100644
> --- a/include/libcamera/geometry.h
> +++ b/include/libcamera/geometry.h
> @@ -262,6 +262,13 @@ public:
>         {
>         }
>  
> +       constexpr Rectangle(const Point &point1, const Point &point2)
> +               : Rectangle(std::min(point1.x, point2.x), std::max(point1.y, point2.y),
> +                           std::max(point1.x, point2.x) - std::min(point1.x, point2.x),
> +                           std::max(point1.y, point2.y) - std::min(point1.y, point2.y))
> +       {
> +       }
> +
>         int x;
>         int y;
>         unsigned int width;
> diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
> index 00015136..b608e4f0 100644
> --- a/src/libcamera/geometry.cpp
> +++ b/src/libcamera/geometry.cpp
> @@ -629,6 +629,13 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)
>   * \param[in] size The desired Rectangle size
>   */
>  
> +/**
> + * \fn Rectangle::Rectangle(const Point &point1, const Point &point2)
> + * \brief Construct a Rectangle with the two given points
> + * \param[in] point1 One of the corner point of the rectangle

"One corner point of the rectangle"
or
"One of the corner points of the rectangle"

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> + * \param[in] point2 The diagonal corner point from \a point1
> + */
> +
>  /**
>   * \var Rectangle::x
>   * \brief The horizontal coordinate of the rectangle's top-left corner
> diff --git a/test/geometry.cpp b/test/geometry.cpp
> index 64169206..3ed2cc23 100644
> --- a/test/geometry.cpp
> +++ b/test/geometry.cpp
> @@ -481,6 +481,20 @@ protected:
>                         return TestFail;
>                 }
>  
> +               Point topLeft(3, 3);
> +               Point bottomRight(30, 30);
> +               Point topRight(30, 3);
> +               Point bottomLeft(3, 30);
> +               Rectangle rect1(topLeft, bottomRight);
> +               Rectangle rect2(topRight, bottomLeft);
> +               Rectangle rect3(bottomRight, topLeft);
> +               Rectangle rect4(bottomLeft, topRight);
> +
> +               if (rect1 != rect2 || rect1 != rect3 || rect1 != rect4) {
> +                       cout << "Point-from-point construction failed" << endl;
> +                       return TestFail;
> +               }
> +
>                 return TestPass;
>         }
>  };
> -- 
> 2.46.0.792.g87dc391469-goog
>
Cheng-Hao Yang Sept. 24, 2024, 11:04 a.m. UTC | #2
Hi Kieran,

On Mon, Sep 23, 2024 at 6:32 PM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Quoting Harvey Yang (2024-09-23 10:30:44)
> > From: Yudhistira Erlandinata <yerlandinata@chromium.org>
> >
> > Add a Rectangle constructor that accepts two points:
> > topLeft and bottomRight.
> >
> > Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
> > Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
> > Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> > ---
> >  include/libcamera/geometry.h |  7 +++++++
> >  src/libcamera/geometry.cpp   |  7 +++++++
> >  test/geometry.cpp            | 14 ++++++++++++++
> >  3 files changed, 28 insertions(+)
> >
> > diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
> > index 3e6f0f5d..5949d55c 100644
> > --- a/include/libcamera/geometry.h
> > +++ b/include/libcamera/geometry.h
> > @@ -262,6 +262,13 @@ public:
> >         {
> >         }
> >
> > +       constexpr Rectangle(const Point &point1, const Point &point2)
> > +               : Rectangle(std::min(point1.x, point2.x), std::max(point1.y, point2.y),
> > +                           std::max(point1.x, point2.x) - std::min(point1.x, point2.x),
> > +                           std::max(point1.y, point2.y) - std::min(point1.y, point2.y))
> > +       {
> > +       }
> > +
> >         int x;
> >         int y;
> >         unsigned int width;
> > diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
> > index 00015136..b608e4f0 100644
> > --- a/src/libcamera/geometry.cpp
> > +++ b/src/libcamera/geometry.cpp
> > @@ -629,6 +629,13 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)
> >   * \param[in] size The desired Rectangle size
> >   */
> >
> > +/**
> > + * \fn Rectangle::Rectangle(const Point &point1, const Point &point2)
> > + * \brief Construct a Rectangle with the two given points
> > + * \param[in] point1 One of the corner point of the rectangle
>
> "One corner point of the rectangle"
> or
> "One of the corner points of the rectangle"

Sorry to miss this in v6. Fixed in v7.

BR,
Harvey

>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>
>
> > + * \param[in] point2 The diagonal corner point from \a point1
> > + */
> > +
> >  /**
> >   * \var Rectangle::x
> >   * \brief The horizontal coordinate of the rectangle's top-left corner
> > diff --git a/test/geometry.cpp b/test/geometry.cpp
> > index 64169206..3ed2cc23 100644
> > --- a/test/geometry.cpp
> > +++ b/test/geometry.cpp
> > @@ -481,6 +481,20 @@ protected:
> >                         return TestFail;
> >                 }
> >
> > +               Point topLeft(3, 3);
> > +               Point bottomRight(30, 30);
> > +               Point topRight(30, 3);
> > +               Point bottomLeft(3, 30);
> > +               Rectangle rect1(topLeft, bottomRight);
> > +               Rectangle rect2(topRight, bottomLeft);
> > +               Rectangle rect3(bottomRight, topLeft);
> > +               Rectangle rect4(bottomLeft, topRight);
> > +
> > +               if (rect1 != rect2 || rect1 != rect3 || rect1 != rect4) {
> > +                       cout << "Point-from-point construction failed" << endl;
> > +                       return TestFail;
> > +               }
> > +
> >                 return TestPass;
> >         }
> >  };
> > --
> > 2.46.0.792.g87dc391469-goog
> >

Patch
diff mbox series

diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index 3e6f0f5d..5949d55c 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -262,6 +262,13 @@  public:
 	{
 	}
 
+	constexpr Rectangle(const Point &point1, const Point &point2)
+		: Rectangle(std::min(point1.x, point2.x), std::max(point1.y, point2.y),
+			    std::max(point1.x, point2.x) - std::min(point1.x, point2.x),
+			    std::max(point1.y, point2.y) - std::min(point1.y, point2.y))
+	{
+	}
+
 	int x;
 	int y;
 	unsigned int width;
diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index 00015136..b608e4f0 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -629,6 +629,13 @@  std::ostream &operator<<(std::ostream &out, const SizeRange &sr)
  * \param[in] size The desired Rectangle size
  */
 
+/**
+ * \fn Rectangle::Rectangle(const Point &point1, const Point &point2)
+ * \brief Construct a Rectangle with the two given points
+ * \param[in] point1 One of the corner point of the rectangle
+ * \param[in] point2 The diagonal corner point from \a point1
+ */
+
 /**
  * \var Rectangle::x
  * \brief The horizontal coordinate of the rectangle's top-left corner
diff --git a/test/geometry.cpp b/test/geometry.cpp
index 64169206..3ed2cc23 100644
--- a/test/geometry.cpp
+++ b/test/geometry.cpp
@@ -481,6 +481,20 @@  protected:
 			return TestFail;
 		}
 
+		Point topLeft(3, 3);
+		Point bottomRight(30, 30);
+		Point topRight(30, 3);
+		Point bottomLeft(3, 30);
+		Rectangle rect1(topLeft, bottomRight);
+		Rectangle rect2(topRight, bottomLeft);
+		Rectangle rect3(bottomRight, topLeft);
+		Rectangle rect4(bottomLeft, topRight);
+
+		if (rect1 != rect2 || rect1 != rect3 || rect1 != rect4) {
+			cout << "Point-from-point construction failed" << endl;
+			return TestFail;
+		}
+
 		return TestPass;
 	}
 };