[libcamera-devel] [PATCH v2 04/16] libcamera: geometry: SizeRange: Add contains()
Niklas Söderlund
niklas.soderlund at ragnatech.se
Wed Jun 12 02:43:47 CEST 2019
Add a method to check if a Size can fit inside a SizeRange. When
determining if a size is containable take step values into account if
they are not set to 0.
Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
include/libcamera/geometry.h | 2 ++
src/libcamera/geometry.cpp | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index 03962d7d09fac2b0..52f4d010de76f840 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -92,6 +92,8 @@ public:
{
}
+ bool contains(const Size &size) const;
+
std::string toString() const;
Size min;
diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index 6a1d1d78870b23ec..a4d472d9fce2e226 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -107,6 +107,7 @@ bool operator==(const Rectangle &lhs, const Rectangle &rhs)
* \brief The Size height
*/
+
/**
* \brief Assemble and return a string describing the size
* \return A string describing the size
@@ -261,6 +262,22 @@ bool operator<(const Size &lhs, const Size &rhs)
* \brief The vertical step
*/
+/**
+ * \brief Test if a size can be contained in the range
+ * \param[in] size Size to check
+ * \returns True if \a size can be contained
+ */
+bool SizeRange::contains(const Size &size) const
+{
+ if (size.width < min.width || size.width > max.width ||
+ size.height < min.height || size.height > max.height ||
+ (hStep && (size.width - min.width) % hStep) ||
+ (vStep && (size.height - min.height) % vStep))
+ return false;
+
+ return true;
+}
+
/**
* \brief Assemble and return a string describing the size range
* \return A string describing the SizeRange
--
2.21.0
More information about the libcamera-devel
mailing list