diff --git a/src/core/include/pw/core/geometry.hpp b/src/core/include/pw/core/geometry.hpp index c460c76..cf56fb0 100644 --- a/src/core/include/pw/core/geometry.hpp +++ b/src/core/include/pw/core/geometry.hpp @@ -23,7 +23,6 @@ #ifndef PW_CORE_GEOMETRY_HPP #define PW_CORE_GEOMETRY_HPP -#include <cstddef> #include <pw/core/aabb.hpp> #include <pw/core/globals.hpp> #include <pw/core/resource.hpp> diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index cdc9b0c..3e84e7f 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -23,13 +23,10 @@ #ifndef PW_CORE_MATRIX_HPP #define PW_CORE_MATRIX_HPP -#include "vector.hpp" -#include <cstddef> #include <pw/core/globals.hpp> #include <pw/core/math.hpp> #include <pw/core/vector.hpp> -#include <print> #include <type_traits> #include <utility> @@ -52,7 +49,12 @@ struct matrix final { using transpose_type = matrix<Scalar, Cols, Rows>; using minor_type = matrix<Scalar, Cols - 1, Rows - 1>; - vector<vector<Scalar, Cols>, Rows> m_{}; + using reference = row_type&; + using const_reference = const row_type&; + using pointer = row_type*; + using const_pointer = const row_type*; + + vector<row_type, Rows> m_{}; auto&& data(this auto&& self) { return std::forward<decltype(self)>(self).m_[0].data(); @@ -200,6 +202,13 @@ struct matrix final { std::make_index_sequence<ColsSlice>{}, c)...}; }(std::make_index_sequence<RowsSlice>{}); // rowwise expansion } + + // + // Iterators + // + constexpr const_pointer begin() const { return &m_[0]; } + + constexpr const_pointer end() const { return &m_[Rows]; } }; template <> constexpr float matrix<float, 1, 1>::determinant() const noexcept { @@ -215,7 +224,7 @@ template <typename Scalar, unsigned int Ra, unsigned int CaRb, unsigned int Cb> constexpr auto operator*(const matrix<Scalar, Ra, CaRb>& A, const matrix<Scalar, CaRb, Cb>& B) noexcept { matrix<Scalar, Ra, Cb> result{}; - [&]<std::size_t... Ia>(std::index_sequence<Ia...>) { + [&result, &A, &B]<std::size_t... Ia>(std::index_sequence<Ia...>) { ( [&]<std::size_t... Ib>(auto&& Ai, std::index_sequence<Ib...>) { ( @@ -237,7 +246,7 @@ constexpr auto operator*(const matrix<ScalarA, Ra, Ca>& A, // first step - should move to concepts to allow for std::array and // std::span to be allowed vector<std::common_type_t<ScalarA, ScalarB>, Ca> result{}; - [&]<std::size_t... Ia>(std::index_sequence<Ia...>) { + [&result, &A, &B]<std::size_t... Ia>(std::index_sequence<Ia...>) { ( [&]<std::size_t... Ib>(auto&& Ai, std::index_sequence<Ib...>) { ((result[Ib] += A[Ai][Ib] * B[Ib]), ...); diff --git a/src/core/tests/pwcore_test_matrix.cpp b/src/core/tests/pwcore_test_matrix.cpp index 884837e..b7d5161 100644 --- a/src/core/tests/pwcore_test_matrix.cpp +++ b/src/core/tests/pwcore_test_matrix.cpp @@ -1,4 +1,5 @@ #include <pw/core/debug.hpp> +#include <pw/core/formatter.hpp> #include <pw/core/matrix.hpp> #include <pw/core/serialize.hpp> #include <pw/core/vector.hpp> @@ -50,18 +51,18 @@ auto main() -> int { auto m33 = pw::matrix<float, 3, 3>::identity(); - m33.slice_test<2, 2>(0, 0); - auto m22_slice = m33.slice<2, 2>(0, 0); std::print("{}\n", typeid(m22_slice).name()); - auto vvv = pw::vector { 1.f, 2, 3, 4 }; + auto vvv = pw::vector{1.f, 2, 3, 4}; auto vvv_swizzle = vvv.slice(std::make_index_sequence<2>{}); - pw::debug::d() << "matrix<3,3>.slice() -> \n" << pw::serialize::to_string(m33) << "\n to \n" << pw::serialize::to_string(m22_slice); + + // octave style output + std::print("\nm33=[{}]\n", m33); } diff --git a/src/core/tests/pwcore_test_vector.cpp b/src/core/tests/pwcore_test_vector.cpp index 2aa13ed..c577c42 100644 --- a/src/core/tests/pwcore_test_vector.cpp +++ b/src/core/tests/pwcore_test_vector.cpp @@ -1,6 +1,7 @@ #include <pw/core/serialize.hpp> #include <pw/core/vector.hpp> +#include <pw/core/formatter.hpp> #include <print> #include <tuple> @@ -76,5 +77,7 @@ auto main() -> int { std::print("min((1.3f,0.9f,2.3f),({} {} {})) -> ({} {} {})\n", vec3f.x(), vec3f.y(), vec3f.z(), min_ab.x(), min_ab.y(), min_ab.z()); + std::print("{}", vec3f); + return 0; }