libcamera: geometry: Add isNull() function to Rectangle class
It's common for code to check if a rectangle is null. Add a helper function to do so and test the function in test/geometry.cpp Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
d405d1fd5e
commit
dd0793ed1b
3 changed files with 21 additions and 0 deletions
|
@ -181,6 +181,7 @@ public:
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
|
|
||||||
|
bool isNull() const { return !width && !height; }
|
||||||
const std::string toString() const;
|
const std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -385,6 +385,12 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs)
|
||||||
* \brief The distance between the top and bottom sides
|
* \brief The distance between the top and bottom sides
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \fn bool Rectangle::isNull() const
|
||||||
|
* \brief Check if the rectangle is null
|
||||||
|
* \return True if both the width and height are 0, or false otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Assemble and return a string describing the rectangle
|
* \brief Assemble and return a string describing the rectangle
|
||||||
* \return A string describing the Rectangle
|
* \return A string describing the Rectangle
|
||||||
|
|
|
@ -182,6 +182,20 @@ protected:
|
||||||
if (!compare(Size(200, 100), Size(100, 200), &operator>=, ">=", true))
|
if (!compare(Size(200, 100), Size(100, 200), &operator>=, ">=", true))
|
||||||
return TestFail;
|
return TestFail;
|
||||||
|
|
||||||
|
/* Test Rectangle::isNull(). */
|
||||||
|
if (!Rectangle(0, 0, 0, 0).isNull() ||
|
||||||
|
!Rectangle(1, 1, 0, 0).isNull()) {
|
||||||
|
cout << "Null rectangle incorrectly reported as not null" << endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Rectangle(0, 0, 0, 1).isNull() ||
|
||||||
|
Rectangle(0, 0, 1, 0).isNull() ||
|
||||||
|
Rectangle(0, 0, 1, 1).isNull()) {
|
||||||
|
cout << "Non-null rectangle incorrectly reported as null" << endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
return TestPass;
|
return TestPass;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue