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>
This commit is contained in:
Niklas Söderlund
2019-06-12 01:07:52 +02:00
parent 6bd094ad68
commit 22e0005fdd
2 changed files with 18 additions and 0 deletions

View File

@@ -92,6 +92,8 @@ public:
{
}
bool contains(const Size &size) const;
std::string toString() const;
Size min;

View File

@@ -266,6 +266,22 @@ bool operator<(const Size &lhs, const Size &rhs)
* \brief The vertical step
*/
/**
* \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