From patchwork Tue Sep 3 10:39:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21154 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 86322BF415 for ; Tue, 3 Sep 2024 10:40:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D9C5634E9; Tue, 3 Sep 2024 12:40:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QSFcnAHM"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A394634E0 for ; Tue, 3 Sep 2024 12:40:22 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42bb7298bdeso57621595e9.1 for ; Tue, 03 Sep 2024 03:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725360021; x=1725964821; 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=dLRDrex9H8OhgXs/1LaRi31s0x2nDQspD1Ge9HvfBaQ=; b=QSFcnAHMHJRLiRO4NJQW2YO/b5iNJHUs8juPRK+4ygMXZPeFM/hjFDpmG5TFvUQJ+U lsmM2+Koy20rU+39/d6xaMsqoDVKwx+UFlpjKr8xPFPCugPWkr9uaJXzRv28qWFs7q30 R3D/ZAO8i0H3IyHUE0tLBxe5eO5x4d75xoseY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725360021; x=1725964821; 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=dLRDrex9H8OhgXs/1LaRi31s0x2nDQspD1Ge9HvfBaQ=; b=VkUpeAAqD6PshzUgIHjb3XQT+/quNQPzhi7dLQe36G+QgH6PVjz72+cwHg5Ysm3gI3 fJGJi4hw1A9BLK4lnBr5ATt8CjbwRPAUZ96tAe2SgYOTWEvyxxpyKgnS9jUkfTrRUxyl QGRPZfy/dUA6inG9zLiHrfsfDiaQFTwT2PKIGgyWENc6kRPfxImXmEnqnB+6N4dBtLVU oyX8PUa1VUrcZ/VquGkRWRnuvkHE4xfN7GWudsGaLEOj/5qRMOT4KOSUqbUvs5aM5StA a1nmtuP8sH72lYRkSZ0gtz6voDLMTqU91AMAqPdsGlQfvSKFY5u0nnYAJkVa+uRqXAR2 uoCg== X-Gm-Message-State: AOJu0YxqyL9/4yq+x8hvCkS9uS2/U+cnOf8fLqgRAP5O2xNoDDQzaih5 830l8kVrRONyQM783hzGaXduFFFiiIEnFc+MGFSssGOE0IObpxbLsvTIcxQ5s/YP9vMjYeLMwCM OUQ== X-Google-Smtp-Source: AGHT+IG3Tjoh88Q/PglJtdjLbsuRAaHGXabsqM9BOmDWMOg1H+NInAB7wI0VaURBfzhbEIbGz7aabQ== X-Received: by 2002:adf:f608:0:b0:374:c05f:2313 with SMTP id ffacd0b85a97d-374c05f2775mr6967226f8f.45.1725360021317; Tue, 03 Sep 2024 03:40:21 -0700 (PDT) Received: from chenghaoyang-germany.c.googlers.com.com (161.126.77.34.bc.googleusercontent.com. [34.77.126.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6deb239sm170546025e9.5.2024.09.03.03.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:40:21 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yudhistira Erlandinata , Harvey Yang , Jacopo Mondi Subject: [PATCH v4 1/3] libcamera: Add rectangle two-point constructor Date: Tue, 3 Sep 2024 10:39:17 +0000 Message-ID: <20240903104018.3289112-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903104018.3289112-1-chenghaoyang@chromium.org> References: <20240903104018.3289112-1-chenghaoyang@chromium.org> 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 | 2 ++ src/libcamera/geometry.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 3e6f0f5d7..dc56f180f 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -262,6 +262,8 @@ public: { } + constexpr Rectangle(const Point &topLeft, const Point &bottomRight); + int x; int y; unsigned int width; diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index 000151364..029b8dad2 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -629,6 +629,20 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr) * \param[in] size The desired Rectangle size */ +/** + * \fn Rectangle::Rectangle(const Point &topLeft, const Point &bottomRight) + * \brief Construct a Rectangle with the two given points + * \param[in] topLeft The top-left corner + * \param[in] bottomRight The bottom-right corner + */ +constexpr Rectangle::Rectangle(const Point &topLeft, const Point &bottomRight) + : x(topLeft.x), y(topLeft.y), + width(bottomRight.x - x), + height(bottomRight.y - y) +{ + ASSERT(bottomRight.x >= x && bottomRight.y >= y); +} + /** * \var Rectangle::x * \brief The horizontal coordinate of the rectangle's top-left corner