From patchwork Tue Jul 14 23:40:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8805 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BF026BD792 for ; Tue, 14 Jul 2020 23:40:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BE8760932; Wed, 15 Jul 2020 01:40:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="q6xSqenL"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F282C60929 for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 913AF10F6 for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594770021; bh=xGr4RoikmEMcAebjYTKr1Ajk4ZADwnn3qHrk5k20Wkw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=q6xSqenLaoq7rSWXkxGHTyw4//pIgb4wIDCR78uDBeOxKgrbNmC3YrkEsPKalNUrb gBmwfI+WuEyp1ljmHGihKh7/h35dBc16c61I/oyME8MqxPNnpXfXy/rt9GOX8dJnaD Qwrc0HJFs5Ey+TQpG1BMU1Rwxe0oqXqffDbeXPzw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Jul 2020 02:40:09 +0300 Message-Id: <20200714234009.16596-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> References: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] libcamera: geometry: Make Size and Rectangle usable as constexpr X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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(-) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 16c94a4861d6..30aaa7a30fe2 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) { }