43template<
typename T,
int N>
67 for (
int i = 0; i < N; ++i) m_data[i] = p[i];
77 for (
int i = 0; i < N; ++i) m_data[i] = v[i];
88 template<std::convertible_to<T>... Vals>
89 constexpr explicit Homogeneous(Vals... vals)
noexcept requires(
sizeof...(Vals) == N + 1) {
91 ((m_data[i++] = vals), ...);
106 constexpr const T&
w()
const {
return m_data[N]; }
112 constexpr T&
w() {
return m_data[N]; }
116 constexpr const T&
operator[](
int index)
const {
return m_data[index]; }
122 constexpr const T&
at(
int index)
const {
return m_data.at(index); }
133 constexpr bool is_point() const noexcept {
return m_data[N] != 0; }
139 constexpr bool is_vector() const noexcept {
return m_data[N] == 0; }
154 if (std::is_constant_evaluated())
throw "Compile-time error: Cannot convert a homogeneous vector (w=0) to a Point.";
155 else throw std::runtime_error(
"Cannot convert a homogeneous vector (w=0) to a Point.");
158 const T inv_w = 1.0 / m_data[N];
159 for (
int i = 0; i < N; ++i) result_coords[i] = m_data[i] * inv_w;
173 if (std::is_constant_evaluated())
throw "Compile-time error: Cannot convert a homogeneous point (w!=0) to a Vec.";
174 else throw std::runtime_error(
"Logical error: Cannot convert a homogeneous point (w!=0) to a Vec.");
177 for (
int i = 0; i < N; ++i) result_coords[i] = m_data[i];
178 return result_coords;
206 os <<
"HCoord" << N << (h.
is_point() ?
"[P] " :
"[V] ") << h.
raw();
A template class for an N-dimensional homogeneous coordinate.
Definition homogeneous.hpp:44
constexpr const Vector< T, N+1 > & raw() const noexcept
Provides read-only access to the underlying raw (N+1)-dimensional vector.
Definition homogeneous.hpp:187
constexpr Homogeneous(const Vector< T, N > &v) noexcept
Constructs a homogeneous coordinate from a Vec (vector).
Definition homogeneous.hpp:76
friend Homogeneous operator*(const Matrix< T, N+1, N+1 > &mat, const Homogeneous &h)
Multiplication operator for a matrix and a homogeneous coordinate.
Definition homogeneous.hpp:218
constexpr Vector< T, N > to_vector() const
Converts the homogeneous coordinate back to a Vec.
Definition homogeneous.hpp:171
constexpr bool is_vector() const noexcept
Checks if this homogeneous coordinate represents a vector.
Definition homogeneous.hpp:139
constexpr T & operator[](int index)
Returns the value of the homogeneous coordinate at the specified index.
Definition homogeneous.hpp:119
friend std::ostream & operator<<(std::ostream &os, const Homogeneous &h)
Stream insertion operator for printing the homogeneous coordinate.
Definition homogeneous.hpp:205
constexpr T & w()
Returns a reference to the w-component of the homogeneous coordinate.
Definition homogeneous.hpp:112
constexpr Homogeneous(const Point< T, N > &p) noexcept
Constructs a homogeneous coordinate from a Point.
Definition homogeneous.hpp:66
constexpr Vector< T, N+1 > & raw() noexcept
Provides mutable access to the underlying raw (N+1)-dimensional vector.
Definition homogeneous.hpp:193
constexpr bool is_point() const noexcept
Checks if this homogeneous coordinate represents a point.
Definition homogeneous.hpp:133
constexpr Homogeneous(Vals... vals) noexcept
Constructs a homogeneous coordinate from a list of values.
Definition homogeneous.hpp:89
constexpr const T & at(int index) const
Returns the value of the homogeneous coordinate at the specified index.
Definition homogeneous.hpp:122
constexpr const T & operator[](int index) const
Returns the value of the homogeneous coordinate at the specified index.
Definition homogeneous.hpp:116
constexpr Homogeneous() noexcept
Default constructor.
Definition homogeneous.hpp:59
constexpr Homogeneous(const Vector< T, N+1 > &data) noexcept
Explicitly constructs from a raw (N+1)-dimensional vector.
Definition homogeneous.hpp:100
constexpr const T & w() const
Returns the w-component of the homogeneous coordinate.
Definition homogeneous.hpp:106
constexpr Point< T, N > to_point() const
Converts the homogeneous coordinate back to a Point.
Definition homogeneous.hpp:152
A template class for RxC dimensional mathematical matrices.
Definition matrix.hpp:267
A template class for an N-dimensional point in space.
Definition point.hpp:37
A template class for N-dimensional mathematical vectors.
Definition vector.hpp:35
Defines a generic, RxC-dimensional, constexpr-friendly matrix class and its views.
The namespace for math library implementation.
Definition bounding_box.hpp:9
Homogeneous< Float, 3 > Homo3
A 3-dimensional homogeneous coordinate using the library's default Float type.
Definition homogeneous.hpp:226
Defines a generic, N-dimensional Point class and its geometric operations.