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

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

Commit Message

Harvey Yang Aug. 23, 2024, 1:07 p.m. UTC
From: Yudhistira Erlandinata <yerlandinata@chromium.org>

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

BUG=b:308714092
TEST=emerge-geralt libcamera-mtkisp7

Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
---
 include/libcamera/geometry.h | 10 ++++++++++
 src/libcamera/geometry.cpp   |  7 +++++++
 2 files changed, 17 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index 3e6f0f5d7..4566c95b3 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -8,6 +8,8 @@ 
 #pragma once
 
 #include <algorithm>
+#include <cassert>
+#include <cstdlib>
 #include <ostream>
 #include <string>
 
@@ -262,6 +264,14 @@  public:
 	{
 	}
 
+	constexpr Rectangle(const Point &topLeft, const Point &bottomRight)
+		: x(topLeft.x), y(topLeft.y),
+		  width(bottomRight.x - x),
+		  height(bottomRight.y - y)
+	{
+		assert(bottomRight.x >= x && bottomRight.y >= y);
+	}
+
 	int x;
 	int y;
 	unsigned int width;
diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index 000151364..008b8ea04 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 &topLeft, const Point &bottomRight)
+ * \brief Construct a Rectangle with the two given points.
+ * \param[in] topLeft The top-left corner
+ * \param[in] bottomRight The bottom-right corner
+ */
+
 /**
  * \var Rectangle::x
  * \brief The horizontal coordinate of the rectangle's top-left corner