diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-10-13 04:11:18 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-10-15 05:05:17 +0300 |
commit | e229b35edff5aeb2dbe819ec7b4cf9816f90460a (patch) | |
tree | 17d07579c82477398af84dead35a3e1e4b1c93ea /include | |
parent | ccec150589a177654b9039d21163c36ccff85cff (diff) |
libcamera: geometry: Add Size members to grown or shrink by a margin
Add four new member functions to the Size class (two in-place and two
const) to grow and shrink a Size by given margins.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/geometry.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index fdd1b467..fa7ae7bc 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -94,6 +94,20 @@ public: return *this; } + Size &growBy(const Size &margins) + { + width += margins.width; + height += margins.height; + return *this; + } + + Size &shrinkBy(const Size &margins) + { + width = width > margins.width ? width - margins.width : 0; + height = height > margins.height ? height - margins.height : 0; + return *this; + } + __nodiscard constexpr Size alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) const { @@ -128,6 +142,22 @@ public: }; } + __nodiscard constexpr Size grownBy(const Size &margins) const + { + return { + width + margins.width, + height + margins.height + }; + } + + __nodiscard constexpr Size shrunkBy(const Size &margins) const + { + return { + width > margins.width ? width - margins.width : 0, + height > margins.height ? height - margins.height : 0 + }; + } + __nodiscard Size boundedToAspectRatio(const Size &ratio) const; __nodiscard Size expandedToAspectRatio(const Size &ratio) const; |