diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f87866..39e2fc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ add_library(${MR_MATH_LIB_NAME} INTERFACE include/mr-math/math.hpp include/mr-math/bound_box.hpp include/mr-math/color.hpp + include/mr-math/debug.hpp ) target_include_directories(${MR_MATH_LIB_NAME} INTERFACE diff --git a/include/mr-math/debug.hpp b/include/mr-math/debug.hpp new file mode 100644 index 0000000..23b8364 --- /dev/null +++ b/include/mr-math/debug.hpp @@ -0,0 +1,114 @@ +#ifndef __MR_DEBUG_HPP_ +#define __MR_DEBUG_HPP_ + +// This file provides template instantiations used by debug visualizers +// and is intended for debug builds only + +#include "vec.hpp" + +namespace mr { +namespace debug { + +// following functions instantiate methods of template structs desired in debug visualization + +inline namespace row { + + void instantiate_row_get(const auto& row) { + volatile auto x = row.get(0); (void)x; + } + +#define MR_INSTANTIATE_ROW2(T) template void instantiate_row_get(const Row&) +#define MR_INSTANTIATE_ROW3(T) template void instantiate_row_get(const Row&) +#define MR_INSTANTIATE_ROW4(T) template void instantiate_row_get(const Row&) +#define MR_INSTANTIATE_ROW2_ROW3_ROW4(T) MR_INSTANTIATE_ROW2(T); MR_INSTANTIATE_ROW3(T); MR_INSTANTIATE_ROW4(T) + + // instantiate types + MR_INSTANTIATE_ROW2_ROW3_ROW4(float); + MR_INSTANTIATE_ROW2_ROW3_ROW4(double); + MR_INSTANTIATE_ROW2_ROW3_ROW4(int); + MR_INSTANTIATE_ROW2_ROW3_ROW4(uint32_t); + +} // namespace row + +inline namespace vec { + + void instantiate_vec_x_y_length(const auto& vec) { + volatile auto x = vec.x(); (void)x; + volatile auto y = vec.y(); (void)y; + volatile auto l = vec.length(); (void)l; + } + + void instantiate_vec_x_y_z_length(const auto& vec) { + instantiate_vec_x_y_length(vec); + volatile auto z = vec.z(); (void)z; + } + + void instantiate_vec_x_y_z_w_length(const auto& vec) { + instantiate_vec_x_y_z_length(vec); + volatile auto w = vec.w(); (void)w; + } + +#define MR_INSTANTIATE_VEC2(T) template void instantiate_vec_x_y_length(const Vec2&) +#define MR_INSTANTIATE_VEC3(T) template void instantiate_vec_x_y_z_length(const Vec3&) +#define MR_INSTANTIATE_VEC4(T) template void instantiate_vec_x_y_z_w_length(const Vec4&) +#define MR_INSTANTIATE_VEC2_VEC3_VEC4(T) MR_INSTANTIATE_VEC2(T); MR_INSTANTIATE_VEC3(T); MR_INSTANTIATE_VEC4(T) + + // instantiate types + MR_INSTANTIATE_VEC2_VEC3_VEC4(float); + MR_INSTANTIATE_VEC2_VEC3_VEC4(double); + MR_INSTANTIATE_VEC2_VEC3_VEC4(int); + MR_INSTANTIATE_VEC2_VEC3_VEC4(uint32_t); + +} // namespace vec + +inline namespace norm { + + void instantiate_norm_x_y(const auto& norm) { + volatile auto x = norm.x(); (void)x; + volatile auto y = norm.y(); (void)y; + } + + void instantiate_norm_x_y_z(const auto& norm) { + instantiate_norm_x_y(norm); + volatile auto z = norm.z(); (void)z; + } + + void instantiate_norm_x_y_z_w(const auto& norm) { + instantiate_norm_x_y_z(norm); + volatile auto w = norm.w(); (void)w; + } + +#define MR_INSTANTIATE_NORM2(T) template void instantiate_norm_x_y(const Norm2&) +#define MR_INSTANTIATE_NORM3(T) template void instantiate_norm_x_y_z(const Norm3&) +#define MR_INSTANTIATE_NORM4(T) template void instantiate_norm_x_y_z_w(const Norm4&) +#define MR_INSTANTIATE_NORM2_NORM3_NORM4(T) MR_INSTANTIATE_NORM2(T); MR_INSTANTIATE_NORM3(T); MR_INSTANTIATE_NORM4(T) + + // instantiate types + MR_INSTANTIATE_NORM2_NORM3_NORM4(float); + MR_INSTANTIATE_NORM2_NORM3_NORM4(double); + MR_INSTANTIATE_NORM2_NORM3_NORM4(int); + MR_INSTANTIATE_NORM2_NORM3_NORM4(uint32_t); + +} // namespace norm + +inline namespace bounb_box { + + void instantiate_aabb_dimensions(const auto& aabb) { + volatile auto d = aabb.dimensions(); (void)d; + } + +#define MR_INSTANTIATE_AABB(T) template void instantiate_aabb_dimensions(const AABB&) + + // instantiate types + MR_INSTANTIATE_AABB(float); + MR_INSTANTIATE_AABB(double); + MR_INSTANTIATE_AABB(int); + MR_INSTANTIATE_AABB(uint32_t); + +} // namespace norm + +} // namespace debug +} // namespace mr + +#endif // __MR_DEBUG_HPP_ + diff --git a/include/mr-math/math.hpp b/include/mr-math/math.hpp index bce165d..015bc1d 100644 --- a/include/mr-math/math.hpp +++ b/include/mr-math/math.hpp @@ -12,4 +12,8 @@ #include "bound_box.hpp" #include "color.hpp" +#ifndef NDEBUG + #include "debug.hpp" +#endif + #endif // __MR_MATH_HPP_ diff --git a/include/mr-math/norm.hpp b/include/mr-math/norm.hpp index fe907b2..5ce602a 100644 --- a/include/mr-math/norm.hpp +++ b/include/mr-math/norm.hpp @@ -146,7 +146,6 @@ namespace mr { private: friend struct Vec; - friend struct Rotation; constexpr Norm(const VecT &v) noexcept : Norm(unchecked, v) {} VecT _data; diff --git a/include/mr-math/row.hpp b/include/mr-math/row.hpp index 891c8da..ff2e63d 100644 --- a/include/mr-math/row.hpp +++ b/include/mr-math/row.hpp @@ -81,6 +81,10 @@ namespace mr { return _data[i]; } + [[nodiscard]] constexpr T get(std::size_t i) const { + return _data[i]; + } + constexpr bool operator==(const Row &other) const noexcept { return stdx::all_of(_data == other._data); } diff --git a/mr-math.natvis b/mr-math.natvis new file mode 100644 index 0000000..d6d714a --- /dev/null +++ b/mr-math.natvis @@ -0,0 +1,137 @@ + + + + + + {{{get(0)}, {get(1)}}} + + get(0) + get(1) + + + + + + {{{get(0)}, {get(1)}, {get(2)}}} + + get(0) + get(1) + get(2) + + + + + + {{{get(0)}, {get(1)}, {get(2)}, {get(3)}}} + + get(0) + get(1) + get(2) + get(3) + + + + + + {{{x()}, {y()}}} + + x() + y() + length() + + + + + + {{{x()}, {y()}, {z()}}} + + x() + y() + z() + length() + + + + + + {{{x()}, {y()}, {z()}, {w()}}} + + x() + y() + z() + w() + length() + + + + + + {{{x()}, {y()}}} + + x() + y() + + + + + + {{{x()}, {y()}, {z()}}} + + x() + y() + z() + + + + + + {{{x()}, {y()}, {z()}, {w()}}} + + x() + y() + z() + w() + + + + + + {_data} rad + + + + + {_data} deg + + + + + R={r()}, G={g()}, B={b()}, A={a()}} + + r() + g() + b() + a() + (uint32_t(r() * 255) << 24) + (uint32_t(g() * 255) << 16) + (uint32_t(b() * 255) << 8) + (uint32_t(a() * 255)), Xb + + + + + + {min} : {max} + + min + max + dimensions() + + + + + + {_data[0]} ... + + _data + + + +