summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-06-12 01:07:52 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-06-19 02:23:01 +0200
commit22e0005fdd4c1431ee412af7f80c2edfb323125e (patch)
treebe93f34c8ecea7456820164d9e6bf95c8e2b40e1
parent6bd094ad68fe41c4245863b855d9653a4e636287 (diff)
libcamera: geometry: SizeRange: Add contains()
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@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--include/libcamera/geometry.h2
-rw-r--r--src/libcamera/geometry.cpp16
2 files changed, 18 insertions, 0 deletions
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index 03962d7d..52f4d010 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 e598f6ad..32b0faea 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -267,6 +267,22 @@ bool operator<(const Size &lhs, const Size &rhs)
*/
/**
+ * \brief Test if a size is contained in the range
+ * \param[in] size Size to check
+ * \returns True if \a size is contained in the range
+ */
+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
*/