15#include <libcamera/base/span.h>
26template<
typename T,
unsigned int Rows,
27 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
29template<
typename T,
unsigned int Rows>
36 constexpr Vector(
const std::array<T, Rows> &data)
38 for (
unsigned int i = 0; i < Rows; i++)
44 if (yaml.
size() != Rows) {
46 <<
"Wrong number of values in vector: expected "
47 << Rows <<
", got " << yaml.
size();
52 for (
const auto &
x : yaml.
asList()) {
53 auto value =
x.get<T>();
55 LOG(
Vector, Error) <<
"Failed to read vector value";
78 template<
bool Dependent = false,
typename = std::enable_if_t<Dependent || Rows >= 1>>
86 template<
bool Dependent = false,
typename = std::enable_if_t<Dependent || Rows >= 2>>
94 template<
bool Dependent = false,
typename = std::enable_if_t<Dependent || Rows >= 3>>
104 for (
unsigned int i = 0; i < Rows; i++)
112 for (
unsigned int i = 0; i < Rows; i++)
113 ret[i] = data_[i] - other[i];
120 for (
unsigned int i = 0; i < Rows; i++)
121 ret[i] = data_[i] + other[i];
128 for (
unsigned int i = 0; i < Rows; i++)
129 ret += data_[i] * other[i];
136 for (
unsigned int i = 0; i < Rows; i++)
137 ret[i] = data_[i] * factor;
144 for (
unsigned int i = 0; i < Rows; i++)
145 ret[i] = data_[i] / factor;
152 for (
unsigned int i = 0; i < Rows; i++)
153 ret += data_[i] * data_[i];
163 std::array<T, Rows> data_;
166template<
typename T,
unsigned int Rows>
169 for (
unsigned int i = 0; i < Rows; i++) {
170 if (lhs[i] != rhs[i])
177template<
typename T,
unsigned int Rows>
180 return !(lhs == rhs);
186template<
typename T,
unsigned int Rows>
187std::ostream &
operator<<(std::ostream &out,
const ipa::Vector<T, Rows> &v)
190 for (
unsigned int i = 0; i < Rows; i++) {
192 out << ((i + 1 < Rows) ?
", " :
" ");
A class representing the tree structure of the YAML content.
Definition: yaml_parser.h:26
std::size_t size() const
Retrieve the number of elements in a dictionary or list YamlObject.
Definition: yaml_parser.cpp:84
ListAdapter asList() const
Wrap a list YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:207
Vector class.
Definition: vector.h:32
int readYaml(const libcamera::YamlObject &yaml)
Populate the vector with yaml data.
Definition: vector.h:42
constexpr T x() const
Convenience function to access the first element of the vector.
Definition: vector.h:80
constexpr Vector< T, Rows > operator-(const Vector< T, Rows > &other) const
Subtract one vector from another.
Definition: vector.h:109
constexpr T operator*(const Vector< T, Rows > &other) const
Compute the dot product.
Definition: vector.h:125
constexpr Vector< T, Rows > operator*(T factor) const
Multiply the vector by a scalar.
Definition: vector.h:133
constexpr double length2() const
Get the squared length of the vector.
Definition: vector.h:149
constexpr Vector(const std::array< T, Rows > &data)
Construct vector from supplied data.
Definition: vector.h:36
const T & operator[](size_t i) const
Index to an element in the vector.
Definition: vector.h:65
constexpr double length() const
Get the length of the vector.
Definition: vector.h:157
constexpr T z() const
Convenience function to access the third element of the vector.
Definition: vector.h:96
constexpr Vector()=default
Construct a zero vector.
constexpr Vector< T, Rows > operator/(T factor) const
Divide the vector by a scalar.
Definition: vector.h:141
constexpr Vector< T, Rows > operator+(const Vector< T, Rows > &other) const
Add two vectors together.
Definition: vector.h:117
constexpr Vector< T, Rows > operator-() const
Negate a Vector by negating both all of its coordinates.
Definition: vector.h:101
T & operator[](size_t i)
Definition: vector.h:71
constexpr T y() const
Convenience function to access the second element of the vector.
Definition: vector.h:88
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
#define LOG(category, severity)
Log a message.
#define ASSERT(condition)
Abort program execution if assertion fails.
bool operator==(const Vector< T, Rows > &lhs, const Vector< T, Rows > &rhs)
Compare vectors for equality.
Definition: vector.h:167
bool operator!=(const Vector< T, Rows > &lhs, const Vector< T, Rows > &rhs)
Compare vectors for inequality.
Definition: vector.h:178
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