From patchwork Mon Jul 20 10:47:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8875 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 546AEC0109 for ; Mon, 20 Jul 2020 10:44:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 10B77605BB; Mon, 20 Jul 2020 12:44:19 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7BA1360537 for ; Mon, 20 Jul 2020 12:44:15 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id AE2BC60011; Mon, 20 Jul 2020 10:44:14 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jul 2020 12:47:20 +0200 Message-Id: <20200720104736.19986-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720104736.19986-1-jacopo@jmondi.org> References: <20200720104736.19986-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/19] libcamera: geometry: Add isNull() function to Rectangle class 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" It's common for code to check if a rectangle is null. Add a helper function to do so and test the function in test/geometry.cpp Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- include/libcamera/geometry.h | 1 + src/libcamera/geometry.cpp | 6 ++++++ test/geometry.cpp | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index d858f85cf1f0..02fb63c08f60 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -181,6 +181,7 @@ public: unsigned int width; unsigned int height; + bool isNull() const { return !width && !height; } const std::string toString() const; }; diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index 23181bdec969..b12e1a62f939 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -385,6 +385,12 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs) * \brief The distance between the top and bottom sides */ +/** + * \fn bool Rectangle::isNull() const + * \brief Check if the rectangle is null + * \return True if both the width and height are 0, or false otherwise + */ + /** * \brief Assemble and return a string describing the rectangle * \return A string describing the Rectangle diff --git a/test/geometry.cpp b/test/geometry.cpp index 1a9fc1b8e3ed..08e268c9c312 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -182,6 +182,20 @@ protected: if (!compare(Size(200, 100), Size(100, 200), &operator>=, ">=", true)) return TestFail; + /* Test Rectangle::isNull(). */ + if (!Rectangle(0, 0, 0, 0).isNull() || + !Rectangle(1, 1, 0, 0).isNull()) { + cout << "Null rectangle incorrectly reported as not null" << endl; + return TestFail; + } + + if (Rectangle(0, 0, 0, 1).isNull() || + Rectangle(0, 0, 1, 0).isNull() || + Rectangle(0, 0, 1, 1).isNull()) { + cout << "Non-null rectangle incorrectly reported as null" << endl; + return TestFail; + } + return TestPass; } };