15#include <libcamera/base/span.h>
28template<
typename T,
unsigned int Rows,
29 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
31template<
typename T,
unsigned int Rows>
38 constexpr Vector(
const std::array<T, Rows> &data)
40 for (
unsigned int i = 0; i < Rows; i++)
57 template<
bool Dependent = false,
typename = std::enable_if_t<Dependent || Rows >= 1>>
65 template<
bool Dependent = false,
typename = std::enable_if_t<Dependent || Rows >= 2>>
73 template<
bool Dependent = false,
typename = std::enable_if_t<Dependent || Rows >= 3>>
83 for (
unsigned int i = 0; i < Rows; i++)
91 for (
unsigned int i = 0; i < Rows; i++)
92 ret[i] = data_[i] - other[i];
99 for (
unsigned int i = 0; i < Rows; i++)
100 ret[i] = data_[i] + other[i];
107 for (
unsigned int i = 0; i < Rows; i++)
108 ret += data_[i] * other[i];
115 for (
unsigned int i = 0; i < Rows; i++)
116 ret[i] = data_[i] * factor;
123 for (
unsigned int i = 0; i < Rows; i++)
124 ret[i] = data_[i] / factor;
131 for (
unsigned int i = 0; i < Rows; i++)
132 ret += data_[i] * data_[i];
142 std::array<T, Rows> data_;
145template<
typename T,
unsigned int Rows,
unsigned int Cols>
150 for (
unsigned int i = 0; i < Rows; i++) {
152 for (
unsigned int j = 0; j < Cols; j++)
153 sum += m[i][j] * v[j];
160template<
typename T,
unsigned int Rows>
163 for (
unsigned int i = 0; i < Rows; i++) {
164 if (lhs[i] != rhs[i])
171template<
typename T,
unsigned int Rows>
174 return !(lhs == rhs);
178bool vectorValidateYaml(
const YamlObject &obj,
unsigned int size);
184template<
typename T,
unsigned int Rows>
185std::ostream &
operator<<(std::ostream &out,
const ipa::Vector<T, Rows> &v)
188 for (
unsigned int i = 0; i < Rows; i++) {
190 out << ((i + 1 < Rows) ?
", " :
" ");
197template<
typename T,
unsigned int Rows>
198struct YamlObject::Getter<ipa::Vector<T, Rows>> {
199 std::optional<ipa::Vector<T, Rows>>
get(
const YamlObject &obj)
const
201 if (!ipa::vectorValidateYaml(obj, Rows))
204 ipa::Vector<T, Rows> vector;
207 for (
const YamlObject &entry : obj.asList()) {
208 const auto value = entry.get<T>();
211 vector[i++] = *value;
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:27
std::optional< T > get() const
Parse the YamlObject as a T value.
Definition yaml_parser.h:174
Matrix class.
Definition matrix.h:31
Vector class.
Definition vector.h:34
constexpr T y() const
Convenience function to access the second element of the vector.
Definition vector.h:67
constexpr T x() const
Convenience function to access the first element of the vector.
Definition vector.h:59
constexpr Vector< T, Rows > operator-(const Vector< T, Rows > &other) const
Subtract one vector from another.
Definition vector.h:88
constexpr Vector()=default
Construct a zero vector.
constexpr Vector< T, Rows > operator*(T factor) const
Multiply the vector by a scalar.
Definition vector.h:112
constexpr Vector< T, Rows > operator+(const Vector< T, Rows > &other) const
Add two vectors together.
Definition vector.h:96
constexpr Vector< T, Rows > operator/(T factor) const
Divide the vector by a scalar.
Definition vector.h:120
constexpr Vector(const std::array< T, Rows > &data)
Construct vector from supplied data.
Definition vector.h:38
constexpr Vector< T, Rows > operator-() const
Negate a Vector by negating both all of its coordinates.
Definition vector.h:80
constexpr double length() const
Get the length of the vector.
Definition vector.h:136
const T & operator[](size_t i) const
Index to an element in the vector.
Definition vector.h:44
constexpr T operator*(const Vector< T, Rows > &other) const
Compute the dot product.
Definition vector.h:104
constexpr double length2() const
Get the squared length of the vector.
Definition vector.h:128
constexpr T z() const
Convenience function to access the third element of the vector.
Definition vector.h:75
T & operator[](size_t i)
Index to an element in the vector.
Definition vector.h:50
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:46
#define ASSERT(condition)
Abort program execution if assertion fails.
Definition log.h:126
bool operator==(const Vector< T, Rows > &lhs, const Vector< T, Rows > &rhs)
Compare vectors for equality.
Definition vector.h:161
Matrix< U, Rows, Cols > operator*(T d, const Matrix< U, Rows, Cols > &m)
Multiply the matrix by a scalar.
Definition matrix.h:103
bool operator!=(const Vector< T, Rows > &lhs, const Vector< T, Rows > &rhs)
Compare vectors for inequality.
Definition vector.h:172
Top-level libcamera namespace.
Definition backtrace.h:17
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition geometry.cpp:91