libcamera: geometry: Add comparison operators to geometry classes
Add equality and inequality comparison operators for the Rectangle, Size and SizeRange classes. For the Size class, also add ordering operators. Sizes are first compared on combined width and height, then on area, and finally on width only to achieve a stable ordering. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
@@ -21,6 +21,12 @@ struct Rectangle {
|
||||
const std::string toString() const;
|
||||
};
|
||||
|
||||
bool operator==(const Rectangle &lhs, const Rectangle &rhs);
|
||||
static inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
struct Size {
|
||||
Size()
|
||||
: Size(0, 0)
|
||||
@@ -36,6 +42,29 @@ struct Size {
|
||||
unsigned int height;
|
||||
};
|
||||
|
||||
bool operator==(const Size &lhs, const Size &rhs);
|
||||
bool operator<(const Size &lhs, const Size &rhs);
|
||||
|
||||
static inline bool operator!=(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
static inline bool operator<=(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return lhs < rhs || lhs == rhs;
|
||||
}
|
||||
|
||||
static inline bool operator>(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return !(lhs <= rhs);
|
||||
}
|
||||
|
||||
static inline bool operator>=(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
struct SizeRange {
|
||||
SizeRange()
|
||||
{
|
||||
@@ -51,6 +80,12 @@ struct SizeRange {
|
||||
Size max;
|
||||
};
|
||||
|
||||
bool operator==(const SizeRange &lhs, const SizeRange &rhs);
|
||||
static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
#endif /* __LIBCAMERA_GEOMETRY_H__ */
|
||||
|
||||
Reference in New Issue
Block a user