From patchwork Thu Jun 25 01:23:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 4200 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 431CAC0100 for ; Thu, 25 Jun 2020 01:23:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C19B9609A5; Thu, 25 Jun 2020 03:23:37 +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="iB/ormJo"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC134603BB for ; Thu, 25 Jun 2020 03:23:35 +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 551152A8 for ; Thu, 25 Jun 2020 03:23:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593048215; bh=rFMVBSEfvpD9njOdgvuBduHjh3ZbpjtCllsIrcBilfI=; h=From:To:Subject:Date:From; b=iB/ormJo7JYd2Js9cHBcOUHmu4J93ilji80DdRpZ2EJk9745KAtpwCGdqLXEVkf5J CGZXZKqaSkcoef7OQqqUwwpIBtGTvMlM6BaNFYtD5uTdFTxjOa4MgXKHZsegakwA2O k9qCZI359uetKbw6CboMAf2KNySyfrNXNQYhZvIs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 25 Jun 2020 04:23:30 +0300 Message-Id: <20200625012330.7639-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: geometry: Add isNull() function to Size 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 size is null. Add a helper function to do so. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- Changes since v1: - Add test --- include/libcamera/geometry.h | 1 + src/libcamera/geometry.cpp | 6 ++++++ test/geometry.cpp | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index edda42cf34cc..7d4b8bcfe3d8 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -41,6 +41,7 @@ struct Size { 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 fd78cf2c0ab7..24c44fb43acf 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -107,6 +107,12 @@ bool operator==(const Rectangle &lhs, const Rectangle &rhs) * \brief The Size height */ +/** + * \fn bool Size::isNull() const + * \brief Check if the size is null + * \return True if both the width and height are 0, or false otherwise + */ + /** * \brief Assemble and return a string describing the size * \return A string describing the size diff --git a/test/geometry.cpp b/test/geometry.cpp index 27e65565d7c6..904ad92c9448 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -36,6 +36,16 @@ protected: int run() { + if (!Size().isNull() || !Size(0, 0).isNull()) { + cout << "Null size incorrectly reported as not null" << endl; + return TestFail; + } + + if (Size(0, 100).isNull() || Size(100, 0).isNull() || Size(100, 100).isNull()) { + cout << "Non-null size incorrectly reported as null" << endl; + return TestFail; + } + /* Test Size equality and inequality. */ if (!compare(Size(100, 100), Size(100, 100), &operator==, "==", true)) return TestFail;