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>
This commit is contained in:
Laurent Pinchart 2021-10-13 04:11:18 +03:00
parent ccec150589
commit e229b35edf
3 changed files with 115 additions and 5 deletions

View file

@ -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;