From patchwork Fri Aug 30 21:00:19 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: 21125 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 76644C323E for ; Fri, 30 Aug 2024 21:03:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1D29563469; Fri, 30 Aug 2024 23:03:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Znn+t7K0"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D08B66341E for ; Fri, 30 Aug 2024 23:03:16 +0200 (CEST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-37189d8e637so1427218f8f.3 for ; Fri, 30 Aug 2024 14:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725051796; x=1725656596; 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=G4Ba3c7hJrcxKDqyLM6k3uK9nWWuDQPgRDSBllLf93U=; b=Znn+t7K0GAUgJ3mYyU1es3M17E7h7Hu4T5zObvWyyrz7HZYQGkT4QSrIs90132+93O GIpYlqZ2A/ArcaWv6zjkOhge6X4FKctOL931k/G8rsDib0CD26NHYfnIHTF5+47V5ZnO qkKMoY/qRM7zpUWbXuiBWVlj1gABdeGYCgIa4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725051796; x=1725656596; 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=G4Ba3c7hJrcxKDqyLM6k3uK9nWWuDQPgRDSBllLf93U=; b=g+CrcFGmMwy5S2+faznJmaCmHkyT4Y15nIxmedT0AVjtjReXdFm1tJkOaDEV52NM5U u4q/YEEySuJYh8bPqVFka/yPsdBmGyy2twVl5Pf4wQh6N2qbu5mJ6W9S2f+y2lCZny64 3i9KU+wNtOR4JYD2zImqnHEsA7FGIYa11POwMoD+Q9NhDnaZgF73qxiphsqyEW0rZGg8 8XTMNdCzPn6QQbFmhsgQ4ErJ1wq+LbRR5y+L9AzJnJ3Sx0zgUCTSIm2KAhMo5YJqjXvP P057CD3+SeMwFPtEkWRje0On2lPesnQ3vgLlvZwFxKwinNcJtAC1naZL4Tqvd5MwZ3Mq kZcw== X-Gm-Message-State: AOJu0YwWxbX0igYGzBeRyy+M3q32jKS8hB5HWLgjj1OgDQzwEmkpB0N5 DzioBwF837kgsEWSNbitrBUOiat+3stDf6E66Y5tJ8pJkG0YM94qjMxo/quf4GgiIHq3bu4FMZc QoA== X-Google-Smtp-Source: AGHT+IEfVzOuCShs8QkBLfsmcCXuk7hNSeaf71IT7P9hmMhUOjiHuXwtzG4n9jmLwajBDbbjtrxjTQ== X-Received: by 2002:adf:cd0c:0:b0:374:ba3f:d00c with SMTP id ffacd0b85a97d-374bf1e4d69mr89063f8f.59.1725051795874; Fri, 30 Aug 2024 14:03:15 -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 ffacd0b85a97d-3749efb37efsm4935529f8f.109.2024.08.30.14.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 14:03:15 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yudhistira Erlandinata , Harvey Yang Subject: [PATCH v3 1/3] libcamera: Add rectangle two-point constructor Date: Fri, 30 Aug 2024 21:00:19 +0000 Message-ID: <20240830210313.30691-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240830210313.30691-1-chenghaoyang@chromium.org> References: <20240830210313.30691-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