Patch Detail
Show a patch.
GET /api/patches/20246/?format=api
{ "id": 20246, "url": "https://patchwork.libcamera.org/api/patches/20246/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20246/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20240610141941.2947785-2-paul.elder@ideasonboard.com>", "date": "2024-06-10T14:19:38", "name": "[v7,1/4] ipa: libipa: Add Vector class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "d2e9ceffc1f6c8862f53230eebfc32cec234314b", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20246/mbox/", "series": [ { "id": 4378, "url": "https://patchwork.libcamera.org/api/series/4378/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4378", "date": "2024-06-10T14:19:37", "name": "ipa: Move Pwl from Raspberry Pi to libipa", "version": 7, "mbox": "https://patchwork.libcamera.org/series/4378/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20246/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20246/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 7F63CBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 10 Jun 2024 14:19:59 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1A30D65462;\n\tMon, 10 Jun 2024 16:19:59 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D0E176545E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 10 Jun 2024 16:19:56 +0200 (CEST)", "from neptunite.hamster-moth.ts.net\n\t(h175-177-049-156.catv02.itscom.jp [175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 79E26397;\n\tMon, 10 Jun 2024 16:19:43 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"BrZFMlcr\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718029184;\n\tbh=BLnh+ptKbEyHeQuuG6zFI3xWUTgYZbc+2amx9P36+aw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=BrZFMlcrYccZOCXndCTeb3Ar2qI6Pz+c5cp8UDXcBjJpDI/6vtrXJPGGMzSOIqeRY\n\t5fUhX/PlX1o5b5/sQwCUfaAIlApgEXA2R6/q43aOD/ZXDz6VSr9gkpzKmRlIoVW/Ti\n\tcs/U8O6eknSb2ORAbsCXm6kXiNQWBWUaJT3gYV4k=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Paul Elder <paul.elder@ideasonboard.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v7 1/4] ipa: libipa: Add Vector class", "Date": "Mon, 10 Jun 2024 23:19:38 +0900", "Message-Id": "<20240610141941.2947785-2-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.39.2", "In-Reply-To": "<20240610141941.2947785-1-paul.elder@ideasonboard.com>", "References": "<20240610141941.2947785-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add a vector class to libipa. The original purpose of this is to replace\nthe floating-point Point class that Raspberry Pi used in their Pwl, as\nthat implementation of Point seemed more akin to a Vector than a Point.\n\nThis is added to libipa instead of to geometry.h to avoid public API\nissues, plus this is not expected to be needed by applications.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\nChanges in v7:\n- fix documentation\n- fix license and copyright\n- remove toString()\n\nNo change in v6\n\nNew in v5\n---\n src/ipa/libipa/vector.cpp | 145 +++++++++++++++++++++++++++\n src/ipa/libipa/vector.h | 199 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 344 insertions(+)\n create mode 100644 src/ipa/libipa/vector.cpp\n create mode 100644 src/ipa/libipa/vector.h", "diff": "diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\nnew file mode 100644\nindex 000000000000..e7d0be95812c\n--- /dev/null\n+++ b/src/ipa/libipa/vector.cpp\n@@ -0,0 +1,145 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * Vector and related operations\n+ */\n+\n+#include \"vector.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+/**\n+ * \\file vector.h\n+ * \\brief Vector class\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Vector)\n+\n+namespace ipa {\n+\n+/**\n+ * \\class Vector\n+ * \\brief Vector class\n+ * \\tparam T Type of numerical values to be stored in the vector\n+ * \\tparam D Number of dimension of the vector (= number of elements)\n+ */\n+\n+/**\n+ * \\fn Vector::Vector()\n+ * \\brief Construct a zero vector\n+ */\n+\n+/**\n+ * \\fn Vector::Vector(const std::array<T, D> &data)\n+ * \\brief Construct vector from supplied data\n+ * \\param data Data from which to construct a vector\n+ *\n+ * The size of \\a data must be equal to the dimension size D of the vector.\n+ */\n+\n+/**\n+ * \\fn Vector::readYaml\n+ * \\brief Populate the vector with yaml data\n+ * \\param yaml Yaml data to populate the vector with\n+ *\n+ * Any existing data in the vector will be overwritten. The size of the data\n+ * read from \\a yaml must be equal to the dimension size D of the vector.\n+ *\n+ * The yaml data is expected to be a list with elements of type T.\n+ *\n+ * \\return 0 on success, negative error code otherwise\n+ */\n+\n+/**\n+ * \\fn T Vector::operator[](size_t i) const\n+ * \\brief Index to an element in the vector\n+ * \\param i Index of element to retrieve\n+ * \\return Element at index \\a i from the vector\n+ */\n+\n+/**\n+ * \\fn T &Vector::operator[](size_t i)\n+ * \\copydoc Vector::operator[](size_t i) const\n+ */\n+\n+/**\n+ * \\fn Vector::x()\n+ * \\brief Convenience function to access the first element of the vector\n+ */\n+\n+/**\n+ * \\fn Vector::y()\n+ * \\brief Convenience function to access the second element of the vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator-() const\n+ * \\brief Negate a Vector by negating both all of its coordinates\n+ * \\return The negated vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator-(Vector const &other) const\n+ * \\brief Subtract one vector from another\n+ * \\param[in] other The other vector\n+ * \\return The difference of \\a other from this vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator+()\n+ * \\brief Add two vectors together\n+ * \\param[in] other The other vector\n+ * \\return The sum of the two vectors\n+ */\n+\n+/**\n+ * \\fn Vector::operator*(const Vector<T, D> &other) const\n+ * \\brief Compute the dot product\n+ * \\param[in] other The other vector\n+ * \\return The dot product of the two vectors\n+ */\n+\n+/**\n+ * \\fn Vector::operator*(T factor) const\n+ * \\brief Multiply the vector by a scalar\n+ * \\param[in] factor The factor\n+ * \\return The vector multiplied by \\a factor\n+ */\n+\n+/**\n+ * \\fn Vector::operator/()\n+ * \\brief Divide the vector by a scalar\n+ * \\param[in] factor The factor\n+ * \\return The vector divided by \\a factor\n+ */\n+\n+/**\n+ * \\fn Vector::len2()\n+ * \\brief Get the squared length of the vector\n+ * \\return The squared length of the vector\n+ */\n+\n+/**\n+ * \\fn Vector::len()\n+ * \\brief Get the length of the vector\n+ * \\return The length of the vector\n+ */\n+\n+/**\n+ * \\fn bool operator==(const Vector<T, D> &lhs, const Vector<T, D> &rhs)\n+ * \\brief Compare vectors for equality\n+ * \\return True if the two vectors are equal, false otherwise\n+ */\n+\n+/**\n+ * \\fn bool operator!=(const Vector<T, D> &lhs, const Vector<T, D> &rhs)\n+ * \\brief Compare vectors for inequality\n+ * \\return True if the two vectors are not equal, false otherwise\n+ */\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\nnew file mode 100644\nindex 000000000000..b5a6a0e021e0\n--- /dev/null\n+++ b/src/ipa/libipa/vector.h\n@@ -0,0 +1,199 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * Vector and related operations\n+ */\n+#pragma once\n+\n+#include <algorithm>\n+#include <array>\n+#include <cmath>\n+#include <sstream>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/span.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(Vector)\n+\n+namespace ipa {\n+\n+#ifndef __DOXYGEN__\n+template<typename T, unsigned int D,\n+\t std::enable_if_t<std::is_arithmetic_v<T> && D >= 2> * = nullptr>\n+#else\n+template<typename T, unsigned int D>\n+#endif /* __DOXYGEN__ */\n+class Vector\n+{\n+public:\n+\tVector() = default;\n+\n+\tVector(const std::array<T, D> &data)\n+\t{\n+\t\tASSERT(data.size() == D);\n+\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tdata_[i] = data[i];\n+\t}\n+\n+\t~Vector() = default;\n+\n+\tint readYaml(const libcamera::YamlObject &yaml)\n+\t{\n+\t\tif (yaml.size() != D) {\n+\t\t\tLOG(Vector, Error)\n+\t\t\t\t<< \"Wrong number of values in vector: expected \"\n+\t\t\t\t<< D << \", got \" << yaml.size();\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tunsigned int i = 0;\n+\t\tfor (const auto &x : yaml.asList()) {\n+\t\t\tauto value = x.get<T>();\n+\t\t\tif (!value) {\n+\t\t\t\tLOG(Vector, Error) << \"Failed to read vector value\";\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\tdata_[i++] = *value;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tconst T operator[](size_t i) const\n+\t{\n+\t\tASSERT(0 < i && i < data_.size());\n+\t\treturn data_[i];\n+\t}\n+\n+\tT &operator[](size_t i)\n+\t{\n+\t\tASSERT(0 < i && i < data_.size());\n+\t\treturn data_[i];\n+\t}\n+\n+\tconst T x() const\n+\t{\n+\t\treturn data_[0];\n+\t}\n+\n+\tconst T y() const\n+\t{\n+\t\treturn data_[1];\n+\t}\n+\n+\tconstexpr Vector<T, D> operator-() const\n+\t{\n+\t\tVector<T, D> ret;\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tret[i] = -data_[i];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr Vector<T, D> operator-(const Vector<T, D> &other) const\n+\t{\n+\t\tVector<T, D> ret;\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tret[i] = data_[i] - other[i];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr Vector<T, D> operator+(const Vector<T, D> &other) const\n+\t{\n+\t\tVector<T, D> ret;\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tret[i] = data_[i] + other[i];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr T operator*(const Vector<T, D> &other) const\n+\t{\n+\t\tT ret = 0;\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tret += data_[i] * other[i];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr Vector<T, D> operator*(T factor) const\n+\t{\n+\t\tVector<T, D> ret;\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tret[i] = data_[i] * factor;\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr Vector<T, D> operator/(T factor) const\n+\t{\n+\t\tVector<T, D> ret;\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tret[i] = data_[i] / factor;\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr T len2() const\n+\t{\n+\t\tT ret = 0;\n+\t\tfor (unsigned int i = 0; i < D; i++)\n+\t\t\tret += data_[i] * data_[i];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr double len() const\n+\t{\n+\t\treturn std::sqrt(len2());\n+\t}\n+\n+private:\n+\tstd::array<T, D> data_;\n+};\n+\n+#ifndef __DOXYGEN__\n+template<typename T, unsigned int D,\n+\t std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n+#endif /* __DOXYGEN__ */\n+bool operator==(const Vector<T, D> &lhs, const Vector<T, D> &rhs)\n+{\n+\tfor (unsigned int i = 0; i < D; i++)\n+\t\tif (lhs[i] != rhs[i])\n+\t\t\treturn false;\n+\n+\treturn true;\n+}\n+\n+#ifndef __DOXYGEN__\n+template<typename T, unsigned int D,\n+\t std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n+#endif /* __DOXYGEN__ */\n+bool operator!=(const Vector<T, D> &lhs, const Vector<T, D> &rhs)\n+{\n+\tfor (unsigned int i = 0; i < D; i++)\n+\t\tif (lhs[i] != rhs[i])\n+\t\t\treturn true;\n+\n+\treturn false;\n+}\n+\n+} /* namespace ipa */\n+\n+#ifndef __DOXYGEN__\n+template<typename T, unsigned int D>\n+std::ostream &operator<<(std::ostream &out, const ipa::Vector<T, D> &v)\n+{\n+\tout << \"Vector { \";\n+\tfor (unsigned int i = 0; i < D; i++) {\n+\t\tout << v[i];\n+\t\tout << ((i + 1 < D) ? \", \" : \" \");\n+\t}\n+\tout << \" }\";\n+\n+\treturn out;\n+}\n+#endif /* __DOXYGEN__ */\n+\n+} /* namespace libcamera */\n", "prefixes": [ "v7", "1/4" ] }