diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-04-11 18:50:16 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-04-18 18:13:07 +0300 |
commit | 66337b96b142684cfb471bc7055781e1b9f116f3 (patch) | |
tree | 3b84ec4c29f8569a52af0558745f93182e940d44 /include | |
parent | 72afcbb0873215dd31de098e0461586ba913dcfb (diff) |
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/geometry.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 80f79c6b..3dbbced5 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -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__ */ |