From b5f3b9915ca8bc049e1eec3e918c234330991a0e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 15 Jul 2020 02:00:37 +0300 Subject: libcamera: geometry: Make Size and Rectangle usable as constexpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are use cases for declaring constexpr Size and Rectangle instances. Make it possible. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/geometry.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'include/libcamera/geometry.h') diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 16c94a48..30aaa7a3 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -16,12 +16,12 @@ namespace libcamera { class Size { public: - Size() + constexpr Size() : Size(0, 0) { } - Size(unsigned int w, unsigned int h) + constexpr Size(unsigned int w, unsigned int h) : width(w), height(h) { } @@ -32,7 +32,8 @@ public: bool isNull() const { return !width && !height; } const std::string toString() const; - Size alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) const + constexpr Size alignedDownTo(unsigned int hAlignment, + unsigned int vAlignment) const { return { width / hAlignment * hAlignment, @@ -40,7 +41,8 @@ public: }; } - Size alignedUpTo(unsigned int hAlignment, unsigned int vAlignment) const + constexpr Size alignedUpTo(unsigned int hAlignment, + unsigned int vAlignment) const { return { (width + hAlignment - 1) / hAlignment * hAlignment, @@ -48,7 +50,7 @@ public: }; } - Size boundedTo(const Size &bound) const + constexpr Size boundedTo(const Size &bound) const { return { std::min(width, bound.width), @@ -56,7 +58,7 @@ public: }; } - Size expandedTo(const Size &expand) const + constexpr Size expandedTo(const Size &expand) const { return { std::max(width, expand.width), @@ -131,17 +133,17 @@ static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs) class Rectangle { public: - Rectangle() + constexpr Rectangle() : Rectangle(0, 0, 0, 0) { } - Rectangle(int xpos, int ypos, const Size &size) + constexpr Rectangle(int xpos, int ypos, const Size &size) : x(xpos), y(ypos), width(size.width), height(size.height) { } - Rectangle(int xpos, int ypos, unsigned int w, unsigned int h) + constexpr Rectangle(int xpos, int ypos, unsigned int w, unsigned int h) : x(xpos), y(ypos), width(w), height(h) { } -- cgit v1.2.1