added unprojection into homogenous space for matrices
This commit is contained in:
parent
564cda1345
commit
55189a70b5
3 changed files with 17 additions and 11 deletions
|
@ -23,6 +23,7 @@
|
|||
#ifndef PW_CORE_MATRIX_HPP
|
||||
#define PW_CORE_MATRIX_HPP
|
||||
|
||||
#include "vector.hpp"
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/math.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
|
@ -205,6 +206,15 @@ struct matrix final {
|
|||
}(std::make_index_sequence<RowsSlice>{}); // rowwise expansion
|
||||
}
|
||||
|
||||
constexpr auto unproject(const Scalar& w) const noexcept
|
||||
-> matrix<Scalar, Rows + 1, Cols + 1> {
|
||||
return [&w, this]<std::size_t... Rs>(std::index_sequence<Rs...>) {
|
||||
return matrix<Scalar, Rows + 1, Cols + 1>{
|
||||
(Rs < Rows) ? (*this)[Rs].unproject(0)
|
||||
: vector<Scalar, Cols + 1>::basis(Cols) * w...};
|
||||
}(std::make_index_sequence<Rows + 1>{}); // rowwise expansion
|
||||
}
|
||||
|
||||
//
|
||||
// Iterators
|
||||
//
|
||||
|
|
|
@ -24,20 +24,11 @@
|
|||
#define PW_CORE_POINT_HPP
|
||||
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
template <typename Scalar> struct point final {
|
||||
|
||||
using value_type = Scalar;
|
||||
|
||||
Scalar x{}, y{};
|
||||
|
||||
template <typename ScalarOut>
|
||||
constexpr auto cast() const noexcept -> point<ScalarOut> {
|
||||
return {.x{ScalarOut(x)}, .y{ScalarOut(y)}};
|
||||
}
|
||||
};
|
||||
template <typename Scalar> using point = vector<Scalar, 2>;
|
||||
|
||||
} // namespace pw
|
||||
|
||||
|
|
|
@ -65,4 +65,9 @@ auto main() -> int {
|
|||
|
||||
// octave/matlab style output
|
||||
std::print("\nm33=[{}]\n", m33);
|
||||
|
||||
auto m44 = m33.unproject(1);
|
||||
|
||||
std::print("\nm44=[{}]\n", m44);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue