From patchwork Tue Sep 3 10:35:25 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: 21152 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 82DD1C324C for ; Tue, 3 Sep 2024 10:38:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 61123634E5; Tue, 3 Sep 2024 12:38:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Mx864aX2"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5A180634CB for ; Tue, 3 Sep 2024 12:38:14 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42bb72a5e0bso45351025e9.1 for ; Tue, 03 Sep 2024 03:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725359894; x=1725964694; 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=Mx864aX2E1XpwRy5cAw/R1stUB+kKL/THeWQklhaHBPM+cK9iqNpAo0KWNlEdqzsn9 MsQi4HoZZ/dZpTLhqSDiiuFyuEwfWHakAZnfpJq6gTg70uNybfaYwMoGlzSBHKtaq4bK hzRqU6jkTu4XgZLbyF5+UI2AW3PkHN1yQY+Ec= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725359894; x=1725964694; 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=MwzdN8BP+nNe70S3SW49jz0p9oyFKLHF+wNUOy15fWXZrwJgyqqEsirFqgL7kPGy3X KfBCc3fV1bc/4mivC6UK+I5Un55hy9Z9m7zRJrufIYAuf6QSrs5ui19f28vadTbC7gJE AWUXL1Ws/cLjk9AA4d6yCBpgXibytTP3DLChFqJ0G40E/xHeBbphGrdPuRF2JradSxxy ab0rZiS3j4jOddRNkuhEK/IFpjp/T+7hEN4dsOXtzhkeeo5mB23Ltz/Hf48c49jeULSX 3QhrtyMf2iSsDe/AEGc7DCvavD9Mcn1IQtSW+27IIaYPhun7kSf0HJHRNX+zrvldXip/ JyRA== X-Gm-Message-State: AOJu0Yx/Zt1KVJIiE9eR59EfqDAiD9TEi7v9qATQRWBr2pzELVW9Er1Z 2zBQqTUmaa/1LPq5l8SFPVBL//aO5xwjqufEKQFqUSaqQoO6a/G5nuPNiSzEES1DeO/WXh0EW0X 01w== X-Google-Smtp-Source: AGHT+IHbi2T8U/X3wv4woOhAGf+DD0lD90uD9ZCMDiGYs0a0Imw3L+NcP15bJospwbMKKJCjp7gDsw== X-Received: by 2002:a5d:46d2:0:b0:374:ba83:8d73 with SMTP id ffacd0b85a97d-374ba838e6bmr6787577f8f.8.1725359893455; Tue, 03 Sep 2024 03:38:13 -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-374bfbfc7b7sm8929393f8f.88.2024.09.03.03.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:38:13 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yudhistira Erlandinata , Harvey Yang Subject: [PATCH v4 1/3] libcamera: Add rectangle two-point constructor Date: Tue, 3 Sep 2024 10:35:25 +0000 Message-ID: <20240903103810.3288042-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903103810.3288042-1-chenghaoyang@chromium.org> References: <20240903103810.3288042-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 --- 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