15 #include <libcamera/base/span.h> 28 template<
typename T,
unsigned int Rows,
29 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
31 template<
typename T,
unsigned int Rows>
36 constexpr
Vector() =
default;
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_;
145 template<
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];
160 template<
typename T,
unsigned int Rows>
163 for (
unsigned int i = 0; i < Rows; i++) {
164 if (lhs[i] != rhs[i])
171 template<
typename T,
unsigned int Rows>
174 return !(lhs == rhs);
178 bool vectorValidateYaml(
const YamlObject &obj,
unsigned int size);
184 template<
typename T,
unsigned int Rows>
185 std::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) ?
", " :
" ");
197 template<
typename T,
unsigned int Rows>
198 struct YamlObject::Getter<ipa::
Vector<T, Rows>> {
199 std::optional<ipa::Vector<T, Rows>>
get(
const YamlObject &obj)
const 201 if (!ipa::vectorValidateYaml(obj, Rows))
208 const auto value = entry.get<T>();
211 vector[i++] = *value;
T & operator[](size_t i)
Index to an element in the vector.
Definition: vector.h:50
const T & operator[](size_t i) const
Index to an element in the vector.
Definition: vector.h:44
Top-level libcamera namespace.
Definition: backtrace.h:17
constexpr Vector< T, Rows > operator+(const Vector< T, Rows > &other) const
Add two vectors together.
Definition: vector.h:96
ListAdapter asList() const
Wrap a list YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:206
constexpr double length2() const
Get the squared length of the vector.
Definition: vector.h:128
bool operator==(const Vector< T, Rows > &lhs, const Vector< T, Rows > &rhs)
Compare vectors for equality.
Definition: vector.h:161
#define ASSERT(condition)
Abort program execution if assertion fails.
constexpr double length() const
Get the length of the vector.
Definition: vector.h:136
constexpr T x() const
Convenience function to access the first element of the vector.
Definition: vector.h:59
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
constexpr Vector()=default
Construct a zero vector.
constexpr Vector(const std::array< T, Rows > &data)
Construct vector from supplied data.
Definition: vector.h:38
constexpr Vector< T, Rows > operator-(const Vector< T, Rows > &other) const
Subtract one vector from another.
Definition: vector.h:88
Vector class.
Definition: vector.h:33
constexpr Vector< T, Rows > operator-() const
Negate a Vector by negating both all of its coordinates.
Definition: vector.h:80
constexpr T z() const
Convenience function to access the third element of the vector.
Definition: vector.h:75
A class representing the tree structure of the YAML content.
Definition: yaml_parser.h:27
bool operator!=(const Vector< T, Rows > &lhs, const Vector< T, Rows > &rhs)
Compare vectors for inequality.
Definition: vector.h:172
constexpr T y() const
Convenience function to access the second element of the vector.
Definition: vector.h:67
constexpr Vector< T, Rows > operator/(T factor) const
Divide the vector by a scalar.
Definition: vector.h:120
Matrix class.
Definition: matrix.h:30
constexpr Vector< T, Rows > operator*(T factor) const
Multiply the vector by a scalar.
Definition: vector.h:112
constexpr T operator*(const Vector< T, Rows > &other) const
Compute the dot product.
Definition: vector.h:104