From patchwork Wed Oct 2 05:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 21467 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 6E156BD80A for ; Wed, 2 Oct 2024 05:50:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2BF0163524; Wed, 2 Oct 2024 07:50:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZgQ7nnBq"; 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 502C163512 for ; Wed, 2 Oct 2024 07:50:15 +0200 (CEST) Received: from ideasonboard.com (unknown [5.77.88.238]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C5E72741; Wed, 2 Oct 2024 07:48:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1727848123; bh=Ap9U8t93dlAPWb1HEcjODNBNakr9/cjN29sKX2PRuqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZgQ7nnBqpDEHg3/sCrdjNjQR34DTpEOnks0TVOg4EavrJrUcxVQ2fpElDOcou0/mO cxUOp4CdJ8XOQS9P4y3YyPnPhP0SrF/XjcGGzTJB+5MxicupLjbl75UnqqxnS40PfK 5NGdlRkghvQDR9k0lIY6iMB55gi/nEtyPGQS5Fvs= From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Yudhistira Erlandinata , Harvey Yang , Jacopo Mondi Subject: [PATCH v10 2/5] libcamera: geometry: Add two-point Rectangle constructor Date: Wed, 2 Oct 2024 07:49:59 +0200 Message-ID: <20241002055002.6271-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241002055002.6271-1-jacopo.mondi@ideasonboard.com> References: <20241001191354.55056-1-jacopo.mondi@ideasonboard.com> <20241002055002.6271-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 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" From: Yudhistira Erlandinata Add a constructor to the Rectangle class that accepts two points. The constructed Rectangle spans all the space between the two given points. Signed-off-by: Yudhistira Erlandinata Co-developed-by: Harvey Yang Reviewed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi Reviewed-by: Harvey Yang Reviewed-by: Laurent Pinchart --- include/libcamera/geometry.h | 9 +++++++++ src/libcamera/geometry.cpp | 7 +++++++ test/geometry.cpp | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 3e6f0f5d7fab..9ca5865a3d0d 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -262,6 +262,15 @@ public: { } + constexpr Rectangle(const Point &point1, const Point &point2) + : Rectangle(std::min(point1.x, point2.x), std::min(point1.y, point2.y), + static_cast(std::max(point1.x, point2.x)) - + static_cast(std::min(point1.x, point2.x)), + static_cast(std::max(point1.y, point2.y)) - + static_cast(std::min(point1.y, point2.y))) + { + } + int x; int y; unsigned int width; diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index 85a7f53a6f6c..90ccf8c19f97 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -635,6 +635,13 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr) * \param[in] size The desired Rectangle size */ +/** + * \fn Rectangle::Rectangle(const Point &point1, const Point &point2) + * \brief Construct a Rectangle from two opposite corners + * \param[in] point1 One of corners of the rectangle + * \param[in] point2 The opposite corner of \a point1 + */ + /** * \var Rectangle::x * \brief The horizontal coordinate of the rectangle's top-left corner diff --git a/test/geometry.cpp b/test/geometry.cpp index 64169206ad16..5760fa3c885a 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -481,6 +481,20 @@ protected: return TestFail; } + Point topLeft(3, 3); + Point bottomRight(30, 30); + Point topRight(30, 3); + Point bottomLeft(3, 30); + Rectangle rect1(topLeft, bottomRight); + Rectangle rect2(topRight, bottomLeft); + Rectangle rect3(bottomRight, topLeft); + Rectangle rect4(bottomLeft, topRight); + + if (rect1 != rect2 || rect1 != rect3 || rect1 != rect4) { + cout << "Point-to-point construction failed" << endl; + return TestFail; + } + return TestPass; } };