From e229b35edff5aeb2dbe819ec7b4cf9816f90460a Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 13 Oct 2021 04:11:18 +0300 Subject: 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 Reviewed-by: Jacopo Mondi --- include/libcamera/geometry.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include/libcamera') 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; -- cgit v1.2.1