From patchwork Mon Sep 23 14:45:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 21335 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 D50C6C0F1B for ; Mon, 23 Sep 2024 14:49:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4683D63513; Mon, 23 Sep 2024 16:49:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Y8dMUsPH"; dkim-atps=neutral Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 19488618DE for ; Mon, 23 Sep 2024 16:49:31 +0200 (CEST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2053525bd90so40746725ad.0 for ; Mon, 23 Sep 2024 07:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727102969; x=1727707769; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5+PG4w4fqPObQDpO2iRBORfJQmqvEOjWQ7wghuQIuCM=; b=Y8dMUsPHswF6CM4XXlZbEKRYL4syUuzNFT3UCcARJ2a5fj4+vDHUZQpqDCc7jtQJ6g gBBgkVYgMvSaRcMSG/qPeOBe2ji4TNorN+G6AO5ozx8Or6Zcav+dYBzGMqx7fYlSoYWQ LJaONzLcO60l8O9n33KXIrLqzL5HRCc3PsQec= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727102969; x=1727707769; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5+PG4w4fqPObQDpO2iRBORfJQmqvEOjWQ7wghuQIuCM=; b=MDvVV/kkpgS3VCqCEksZaR1hpPElfh65UjlW7CRn7B5XsqzOT9IKg7MWvZjZad8M6D vjR+IU/Oz9J3uoYGE1/LJkA48EohIKEBUAEMqv9PO9aCZdKBC6v72Hr36ZABvCpx1T5e GfVWzM+WZnKekhSh8BitSgjyhi/Vh3Mnq5ApyaHBIruFSFv+Ev+dGokLfjAS74LhU550 6+ykkZPdAPw2Mu3V+DCErNjbYdmkssPmUkALoVHpAiQeI8X/Yu+KfN0tUaDdlSZM5X94 HcFlwJTaXjbKC0JsbsOHf3rNUROlM0kGFOTLEDrYQ76o6tDccchPEUjdD7zxlv017iuz 8DzQ== X-Gm-Message-State: AOJu0YxGfsLn0Z9dRDKs6zqj82Bw+PFGfP7JoGSoeSR/BXtQfTbA3lrc PR9r5Vcs9DLSvvdF0SpWiSSKheuKNgMl0BbEMJaHGPsWxdAfXgUjhwXDQQDhYwrWEt4O9QHGLl0 = X-Google-Smtp-Source: AGHT+IGJ+LkT4qW5QHTQHV79ZeSYa4dQ9PPMCCUoGWi6U7Ugf9vM0c7hUvAc3j5RGTw4AGMHP2MGcA== X-Received: by 2002:a17:902:fc4c:b0:202:2ee4:16ce with SMTP id d9443c01a7336-208d85aac00mr153039765ad.61.1727102969322; Mon, 23 Sep 2024 07:49:29 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (0.223.81.34.bc.googleusercontent.com. [34.81.223.0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20794735719sm133857435ad.275.2024.09.23.07.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 07:49:28 -0700 (PDT) From: Harvey Yang X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yudhistira Erlandinata , Harvey Yang , Jacopo Mondi Subject: [PATCH v6 1/3] libcamera: Add rectangle two-point constructor Date: Mon, 23 Sep 2024 14:45:03 +0000 Message-ID: <20240923144921.1729183-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240923144921.1729183-1-chenghaoyang@google.com> References: <20240923144921.1729183-1-chenghaoyang@google.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 Rectangle constructor that accepts two points: topLeft and bottomRight. Signed-off-by: Yudhistira Erlandinata Co-developed-by: Harvey Yang Reviewed-by: Jacopo Mondi --- include/libcamera/geometry.h | 7 +++++++ src/libcamera/geometry.cpp | 7 +++++++ test/geometry.cpp | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 3e6f0f5d..5949d55c 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -262,6 +262,13 @@ public: { } + constexpr Rectangle(const Point &point1, const Point &point2) + : Rectangle(std::min(point1.x, point2.x), std::max(point1.y, point2.y), + std::max(point1.x, point2.x) - std::min(point1.x, point2.x), + std::max(point1.y, point2.y) - 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 00015136..b608e4f0 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -629,6 +629,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 with the two given points + * \param[in] point1 One of the corner point of the rectangle + * \param[in] point2 The diagonal corner point from \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 64169206..3ed2cc23 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-from-point construction failed" << endl; + return TestFail; + } + return TestPass; } };