From patchwork Fri Apr 5 08:02:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 19842 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 58A57C327C for ; Fri, 5 Apr 2024 08:03:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF94961C33; Fri, 5 Apr 2024 10:03:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MOECJvuC"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0442261C21 for ; Fri, 5 Apr 2024 10:03:14 +0200 (CEST) Received: from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 965C622A; Fri, 5 Apr 2024 10:02:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712304155; bh=+hKCEVO6/gp2mzXNZcS47f1+xGV4P6WzFYL4XF2WrsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOECJvuCYlRZKmKEF4bk7SmhNh0bqXw7WgVnRr6cXEc85143hAN+Ry6XtAtq1LzTh JcAdUBNFP7l/cFcdXQwoLB7l81fIhqLV7WjKW7XsEOBZepysYH0Hf/9YaXAndacxWe 3WimxcMubk9Ebm88WUcuWAqoudVIjE2Gs+Smbdg4= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH 1/4] libcamera: geometry: Add floating-point version of Point class Date: Fri, 5 Apr 2024 17:02:56 +0900 Message-Id: <20240405080259.1806453-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240405080259.1806453-1-paul.elder@ideasonboard.com> References: <20240405080259.1806453-1-paul.elder@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" The piecewise linear function (Pwl) class from the Raspberry Pi IPA has its own Point class while one already exists in libcamera's geometry.h header. The reason is because libcamera's Point is on the plane of integer, while Raspberry Pi's is on the plane of reals. While making this a template class might be cleaner, it was deemed to be too intrusive of a change, and it might not feel nice to need to specify the type from a public API point of view. Hence we introduce a FPoint class to designate a Point class on the plane of reals. This is in preparation for copying/moving the Pwl class from the Raspberry Pi IPA to libipa. Signed-off-by: Paul Elder --- include/libcamera/geometry.h | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index d7fdbe70..7d0c0f23 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -49,6 +50,55 @@ static inline bool operator!=(const Point &lhs, const Point &rhs) std::ostream &operator<<(std::ostream &out, const Point &p); +struct FPoint { + constexpr FPoint() + : x(0), y(0) + { + } + + constexpr FPoint(double _x, double _y) + : x(_x), y(_y) + { + } + + constexpr FPoint operator-(FPoint const &p) const + { + return FPoint(x - p.x, y - p.y); + } + + constexpr FPoint operator+(FPoint const &p) const + { + return FPoint(x + p.x, y + p.y); + } + + constexpr double operator%(FPoint const &p) const + { + return x * p.x + y * p.y; + } + + constexpr FPoint operator*(double f) const + { + return FPoint(x * f, y * f); + } + + constexpr FPoint operator/(double f) const + { + return FPoint(x / f, y / f); + } + + constexpr double len2() const + { + return x * x + y * y; + } + + constexpr double len() const + { + return std::sqrt(len2()); + } + + double x, y; +}; + class Size { public: