mirror of
https://github.com/g-truc/glm.git
synced 2025-04-07 06:25:00 +00:00
Fix const, add more tests
This commit is contained in:
parent
eae9caf804
commit
c0e28237b2
7 changed files with 459 additions and 186 deletions
|
@ -22,54 +22,29 @@
|
|||
#endif
|
||||
|
||||
#include "../gtc/type_ptr.hpp"
|
||||
#include "../gtc/vec1.hpp"
|
||||
#include "type_trait.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
/// @addtogroup gtx_range
|
||||
/// @{
|
||||
|
||||
# if GLM_COMPILER & GLM_COMPILER_VC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4100) // unreferenced formal parameter
|
||||
# endif
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<1, T, Q> const& v)
|
||||
{
|
||||
return v.length();
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<2, T, Q> const& v)
|
||||
{
|
||||
return v.length();
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<3, T, Q> const& v)
|
||||
{
|
||||
return v.length();
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<4, T, Q> const& v)
|
||||
{
|
||||
return v.length();
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(qua<T, Q> const& v)
|
||||
{
|
||||
return v.length();
|
||||
}
|
||||
#if GLM_COMPILER & GLM_COMPILER_VC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4100) // unreferenced formal parameter
|
||||
#endif
|
||||
|
||||
/// @warning This is not same as `type<genType>::components`, calling this returns total elements (for mat4 returns 16 instead of 4).
|
||||
template<typename genType>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(genType const& m)
|
||||
/*GLM_DEPRECATED*/ GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(genType const& v)
|
||||
{
|
||||
return m.length() * m[0].length();
|
||||
return type<std::remove_cv<genType>::type>::elements;
|
||||
}
|
||||
|
||||
#if GLM_COMPILER & GLM_COMPILER_VC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
template<typename genType>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename genType::value_type const * begin(genType const& v)
|
||||
{
|
||||
|
@ -79,7 +54,7 @@ namespace glm
|
|||
template<typename genType>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename genType::value_type const * end(genType const& v)
|
||||
{
|
||||
return begin(v) + components(v);
|
||||
return begin(v) + type<std::remove_cv<genType>::type>::elements;
|
||||
}
|
||||
|
||||
template<typename genType>
|
||||
|
@ -91,12 +66,8 @@ namespace glm
|
|||
template<typename genType>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename genType::value_type * end(genType& v)
|
||||
{
|
||||
return begin(v) + components(v);
|
||||
return begin(v) + type<std::remove_cv<genType>::type>::elements;
|
||||
}
|
||||
|
||||
# if GLM_COMPILER & GLM_COMPILER_VC
|
||||
# pragma warning(pop)
|
||||
# endif
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
|
157
glm/gtx/span.hpp
157
glm/gtx/span.hpp
|
@ -20,27 +20,29 @@
|
|||
# pragma message("GLM: GLM_GTX_span extension included")
|
||||
#endif
|
||||
|
||||
#if !(GLM_LANG & GLM_LANG_CXX11)
|
||||
// This requirement is due to `std::enable_if`
|
||||
// `std::enable_if` support (and few more)
|
||||
// Required for all functions below
|
||||
#if !(GLM_LANG & GLM_LANG_CXX11_FLAG)
|
||||
# error "GLM_GTX_span requiers at least C++11, using C++20 or C++23 is recommended for full functionality"
|
||||
#endif
|
||||
|
||||
// GLM_MESSAGES info
|
||||
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
|
||||
# if (GLM_LANG & GLM_LANG_CXX20) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
||||
# if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
||||
# pragma message("GLM: GLM_GTX_span extension will include std::span")
|
||||
# endif
|
||||
# if (GLM_LANG & GLM_LANG_CXX23) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L
|
||||
# if (GLM_LANG & GLM_LANG_CXX23_FLAG) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L
|
||||
# pragma message("GLM: GLM_GTX_span extension will include std::mdspan")
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "../gtc/type_precision.hpp"
|
||||
#include "../gtc/type_ptr.hpp"
|
||||
#include "type_trait.hpp"
|
||||
|
||||
#include <valarray>
|
||||
#include <type_traits>
|
||||
|
||||
#if GLM_LANG & GLM_LANG_CXX20
|
||||
// Version-specific includes
|
||||
#if GLM_LANG & GLM_LANG_CXX20_FLAG
|
||||
// Feature testing
|
||||
# include <version>
|
||||
|
||||
|
@ -60,141 +62,80 @@ namespace glm
|
|||
/// @addtogroup gtx_span
|
||||
/// @{
|
||||
|
||||
# if (GLM_LANG & GLM_LANG_CXX20_FLAG)
|
||||
template<typename T>
|
||||
struct is_vec : std::false_type {};
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
struct is_vec<vec<L, T, Q>> : std::true_type {};
|
||||
|
||||
template<typename T>
|
||||
struct is_quat : std::false_type {};
|
||||
template<typename T, qualifier Q>
|
||||
struct is_quat<qua<T, Q>> : std::true_type {};
|
||||
|
||||
template<typename T>
|
||||
struct is_mat : std::false_type {};
|
||||
template<length_t L1, length_t L2, typename T, qualifier Q>
|
||||
struct is_mat<mat<L1, L2, T, Q>> : std::true_type {};
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX17)
|
||||
template<typename T>
|
||||
inline constexpr bool is_vec_v = is_vec<T>::value;
|
||||
template<typename T>
|
||||
inline constexpr bool is_quat_v = is_quat<T>::value;
|
||||
template<typename T>
|
||||
inline constexpr bool is_mat_v = is_mat<T>::value;
|
||||
#endif
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_vec<T>::value || is_quat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_vec<T>::value || is_quat<T>::value>::type>
|
||||
#endif
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components()
|
||||
{
|
||||
return T::length();
|
||||
}
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_mat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_mat<T>::value>::type>
|
||||
#endif
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components()
|
||||
{
|
||||
return T::length() * T::col_type::length();
|
||||
}
|
||||
# if GLM_COMPILER & GLM_COMPILER_VC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4100) // unreferenced formal parameter
|
||||
requires (type<std::remove_cvref_t<T>>::elements > 0)
|
||||
# else
|
||||
template<typename T, typename = typename std::enable_if<
|
||||
(
|
||||
type<
|
||||
typename std::remove_reference<
|
||||
typename std::remove_cv<T>::type
|
||||
>::type
|
||||
>::elements > 0
|
||||
)>::type>
|
||||
# endif
|
||||
|
||||
/// Utility function if you don't have the type and dont use `decltype` (it is from C++11 so this function won't exist for earlier anyway)
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_vec<T>::value || is_quat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_vec<T>::value || is_quat<T>::value>::type>
|
||||
#endif
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(T const&)
|
||||
{
|
||||
return components<T>();
|
||||
}
|
||||
# if GLM_COMPILER & GLM_COMPILER_VC
|
||||
# pragma warning(pop)
|
||||
# endif
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_vec<T>::value || is_quat<T>::value || is_mat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_vec<T>::value || is_quat<T>::value || is_mat<T>::value>::type>
|
||||
#endif
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::valarray<typename T::value_type> valarray(T const& v)
|
||||
{
|
||||
return std::valarray<typename T::value_type>(value_ptr(v), components<T>());
|
||||
return std::valarray<typename T::value_type>(value_ptr(v), type<T>::elements);
|
||||
}
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX20) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
||||
#if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_vec<T>::value || is_quat<T>::value || is_mat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_vec<T>::value || is_quat<T>::value || is_mat<T>::value>::type>
|
||||
#endif
|
||||
requires (type<std::remove_cvref_t<T>>::elements > 0)
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::span<typename T::value_type> span(T & v)
|
||||
{
|
||||
return std::span<typename T::value_type>(value_ptr(v), components<T>());
|
||||
using TN = std::remove_cvref_t<T>;
|
||||
return std::span<typename T::value_type>(value_ptr(v), type<TN>::elements);
|
||||
}
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_vec<T>::value || is_quat<T>::value || is_mat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_vec<T>::value || is_quat<T>::value || is_mat<T>::value>::type>
|
||||
#endif
|
||||
requires (type<std::remove_cvref_t<T>>::elements > 0)
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::span<const typename T::value_type> span(T const& v)
|
||||
{
|
||||
return std::span<const typename T::value_type>(value_ptr(v), components<T>());
|
||||
using TN = std::remove_cvref_t<T>;
|
||||
return std::span<const typename T::value_type>(value_ptr(v), type<TN>::elements);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX23) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L
|
||||
#if (GLM_LANG & GLM_LANG_CXX23_FLAG) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_vec<T>::value || is_quat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_vec<T>::value || is_quat<T>::value>::type>
|
||||
#endif
|
||||
requires (type<std::remove_cvref_t<T>>::rows == 1)
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::mdspan<typename T::value_type> span(T & v)
|
||||
{
|
||||
return std::mdspan<typename T::value_type>(value_ptr(v), components<T>());
|
||||
using TN = std::remove_cvref_t<T>;
|
||||
static_assert(type<TN>::cols >= 1);
|
||||
return std::mdspan<typename T::value_type>(value_ptr(v), type<TN>::cols);
|
||||
}
|
||||
|
||||
#if (GLM_LANG & GLM_LANG_CXX20)
|
||||
template<typename T>
|
||||
requires is_vec<T>::value || is_quat<T>::value
|
||||
#else
|
||||
template<typename T, typename = typename std::enable_if<is_vec<T>::value || is_quat<T>::value>::type>
|
||||
#endif
|
||||
requires (type<std::remove_cvref_t<T>>::rows == 1)
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::mdspan<const typename T::value_type> span(T const& v)
|
||||
{
|
||||
return std::mdspan<const typename T::value_type>(value_ptr(v), components<T>());
|
||||
using TN = std::remove_cvref_t<T>;
|
||||
static_assert(type<TN>::cols >= 1);
|
||||
return std::mdspan<const typename T::value_type>(value_ptr(v), type<TN>::cols);
|
||||
}
|
||||
|
||||
template<length_t L1, length_t L2, typename T, qualifier Q>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(mat<L1, L2, T, Q> & m)
|
||||
template<typename T>
|
||||
requires (type<std::remove_cvref_t<T>>::rows > 1)
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(T & m)
|
||||
{
|
||||
return std::mdspan<T>(value_ptr(m), L1, L2);
|
||||
using TN = std::remove_cvref_t<T>;
|
||||
static_assert(type<TN>::cols >= 1);
|
||||
return std::mdspan<typename T::value_type>(value_ptr(m), type<TN>::cols, type<TN>::rows);
|
||||
}
|
||||
|
||||
template<length_t L1, length_t L2, typename T, qualifier Q>
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(mat<L1, L2, T, Q> const& m)
|
||||
template<typename T>
|
||||
requires (type<std::remove_cvref_t<T>>::rows > 1)
|
||||
GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(T const& m)
|
||||
{
|
||||
return std::mdspan<const T>(value_ptr(m), L1, L2);
|
||||
using TN = std::remove_cvref_t<T>;
|
||||
static_assert(type<TN>::cols >= 1);
|
||||
return std::mdspan<const typename T::value_type>(value_ptr(m), type<TN>::cols, type<TN>::rows);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,12 +31,20 @@ namespace glm
|
|||
template<typename T>
|
||||
struct type
|
||||
{
|
||||
#if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
// with C++20, you can use std::remove_cvref for all of those
|
||||
// with C++11, you can use std::remove_cv for the first two
|
||||
static_assert(!std::is_const<T>::value); // use std::remove_const
|
||||
static_assert(!std::is_volatile<T>::value); // use std::remove_volatile
|
||||
static_assert(!std::is_reference<T>::value); // use std::remove_reference
|
||||
#endif
|
||||
static bool const is_vec = false;
|
||||
static bool const is_mat = false;
|
||||
static bool const is_quat = false;
|
||||
static length_t const components = 0;
|
||||
static length_t const cols = 0;
|
||||
static length_t const rows = 0;
|
||||
static length_t const elements = cols * rows;
|
||||
};
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
|
@ -46,6 +54,9 @@ namespace glm
|
|||
static bool const is_mat = false;
|
||||
static bool const is_quat = false;
|
||||
static length_t const components = L;
|
||||
static length_t const cols = L;
|
||||
static length_t const rows = 1;
|
||||
static length_t const elements = cols * rows;
|
||||
};
|
||||
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
|
@ -57,6 +68,7 @@ namespace glm
|
|||
static length_t const components = C;
|
||||
static length_t const cols = C;
|
||||
static length_t const rows = R;
|
||||
static length_t const elements = cols * rows;
|
||||
};
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
|
@ -66,6 +78,9 @@ namespace glm
|
|||
static bool const is_mat = false;
|
||||
static bool const is_quat = true;
|
||||
static length_t const components = 4;
|
||||
static length_t const cols = components;
|
||||
static length_t const rows = 1;
|
||||
static length_t const elements = cols * rows;
|
||||
};
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
|
@ -75,6 +90,9 @@ namespace glm
|
|||
static bool const is_mat = false;
|
||||
static bool const is_quat = true;
|
||||
static length_t const components = 8;
|
||||
static length_t const cols = components;
|
||||
static length_t const rows = 1;
|
||||
static length_t const elements = cols * rows;
|
||||
};
|
||||
|
||||
/// @}
|
||||
|
|
|
@ -5,7 +5,7 @@ option(GLM_PERF_TEST_ENABLE "Build perf tests" OFF)
|
|||
|
||||
if(GLM_PERF_TEST_ENABLE)
|
||||
add_definitions(-DGLM_TEST_PERF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (GLM_TEST_ENABLE_SIMD_FMA)
|
||||
add_definitions(-DGLM_FORCE_FMA)
|
||||
|
@ -78,6 +78,43 @@ function(glmCreateTestGTC NAME)
|
|||
NAME ${SAMPLE_NAME}
|
||||
COMMAND $<TARGET_FILE:${SAMPLE_NAME}> )
|
||||
target_link_libraries(${SAMPLE_NAME} PRIVATE glm::glm)
|
||||
|
||||
# Add labels for summary
|
||||
if(NAME MATCHES "^bug_")
|
||||
set_tests_properties(
|
||||
${SAMPLE_NAME}
|
||||
PROPERTIES
|
||||
LABELS "bug"
|
||||
)
|
||||
endif()
|
||||
if(NAME MATCHES "^core_")
|
||||
set_tests_properties(
|
||||
${SAMPLE_NAME}
|
||||
PROPERTIES
|
||||
LABELS "core"
|
||||
)
|
||||
endif()
|
||||
if(NAME MATCHES "^ext_")
|
||||
set_tests_properties(
|
||||
${SAMPLE_NAME}
|
||||
PROPERTIES
|
||||
LABELS "ext"
|
||||
)
|
||||
endif()
|
||||
if(NAME MATCHES "^gtc_")
|
||||
set_tests_properties(
|
||||
${SAMPLE_NAME}
|
||||
PROPERTIES
|
||||
LABELS "gtc"
|
||||
)
|
||||
endif()
|
||||
if((NAME MATCHES "^gtx_") OR (NAME STREQUAL "gtx"))
|
||||
set_tests_properties(
|
||||
${SAMPLE_NAME}
|
||||
PROPERTIES
|
||||
LABELS "gtx"
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(GLM_TEST_ENABLE)
|
||||
|
|
|
@ -48,6 +48,7 @@ glmCreateTestGTC(gtx_rotate_normalized_axis)
|
|||
glmCreateTestGTC(gtx_rotate_vector)
|
||||
glmCreateTestGTC(gtx_scalar_multiplication)
|
||||
glmCreateTestGTC(gtx_scalar_relational)
|
||||
glmCreateTestGTC(gtx_span)
|
||||
glmCreateTestGTC(gtx_spline)
|
||||
glmCreateTestGTC(gtx_string_cast)
|
||||
glmCreateTestGTC(gtx_structured_bindings)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
|
@ -5,10 +6,61 @@
|
|||
|
||||
#if GLM_HAS_RANGE_FOR
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/range.hpp>
|
||||
#include <glm/gtx/type_trait.hpp>
|
||||
|
||||
static int test_vec()
|
||||
static int test_vec2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec2 const v(1, 2);
|
||||
|
||||
int count = 0;
|
||||
glm::ivec2 Result(0);
|
||||
for(int x : v)
|
||||
{
|
||||
Result[count] = x;
|
||||
count++;
|
||||
}
|
||||
Error += count == 2 ? 0 : 1;
|
||||
Error += v == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 v(1, 2);
|
||||
for(int& x : v)
|
||||
x = 0;
|
||||
Error += glm::all(glm::equal(v, glm::ivec2(0))) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 const v(1, 2);
|
||||
if(std::accumulate(begin(v), end(v), 0) != 3) // Sum all elements
|
||||
Error += 1;
|
||||
if(std::distance(begin(v), end(v)) != 2) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#if GLM_LANG & GLM_LANG_CXX20_FLAG
|
||||
{
|
||||
glm::ivec2 const v(1, 2);
|
||||
# ifdef __cpp_lib_ranges_fold
|
||||
if(std::ranges::fold_left(v, 0, std::plus<>()) != 3) // Sum all elements
|
||||
Error += 1;
|
||||
# endif
|
||||
if(std::ranges::distance(begin(v), end(v)) != 2) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec3()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
|
@ -33,6 +85,72 @@ static int test_vec()
|
|||
Error += glm::all(glm::equal(v, glm::ivec3(0))) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const v(1, 2, 3);
|
||||
if(std::accumulate(begin(v), end(v), 0) != 6) // Sum all elements
|
||||
Error += 1;
|
||||
if(std::distance(begin(v), end(v)) != 3) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#if GLM_LANG & GLM_LANG_CXX20_FLAG
|
||||
{
|
||||
glm::ivec3 const v(1, 2, 3);
|
||||
# ifdef __cpp_lib_ranges_fold
|
||||
if(std::ranges::fold_left(v, 0, std::plus<>()) != 6) // Sum all elements
|
||||
Error += 1;
|
||||
# endif
|
||||
if(std::ranges::distance(begin(v), end(v)) != 3) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec4 const v(1, 2, 3, 4);
|
||||
|
||||
int count = 0;
|
||||
glm::ivec4 Result(0);
|
||||
for(int x : v)
|
||||
{
|
||||
Result[count] = x;
|
||||
count++;
|
||||
}
|
||||
Error += count == 4 ? 0 : 1;
|
||||
Error += v == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 v(1, 2, 3, 4);
|
||||
for(int& x : v)
|
||||
x = 0;
|
||||
Error += glm::all(glm::equal(v, glm::ivec4(0))) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const v(1, 2, 3, 4);
|
||||
if(std::accumulate(begin(v), end(v), 0) != 10) // Sum all elements
|
||||
Error += 1;
|
||||
if(std::distance(begin(v), end(v)) != 4) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#if GLM_LANG & GLM_LANG_CXX20_FLAG
|
||||
{
|
||||
glm::ivec4 const v(1, 2, 3, 4);
|
||||
# ifdef __cpp_lib_ranges_fold
|
||||
if(std::ranges::fold_left(v, 0, std::plus<>()) != 10) // Sum all elements
|
||||
Error += 1;
|
||||
# endif
|
||||
if(std::ranges::distance(begin(v), end(v)) != 4) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
@ -40,12 +158,50 @@ static int test_quat()
|
|||
{
|
||||
int Error = 0;
|
||||
|
||||
//TODO
|
||||
{
|
||||
glm::quat const q(1, 2, 3, 4);
|
||||
|
||||
int count = 0;
|
||||
glm::quat Result(0, 0, 0, 0);
|
||||
for(float x : q)
|
||||
{
|
||||
Result[count] = x;
|
||||
count++;
|
||||
}
|
||||
Error += count == 4 ? 0 : 1;
|
||||
Error += q == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::quat q(1, 2, 3, 4);
|
||||
for(float& x : q)
|
||||
x = 0;
|
||||
Error += glm::all(glm::equal(q, glm::quat(0, 0, 0, 0))) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::quat const q(1, 2, 3, 4);
|
||||
if(std::accumulate(begin(q), end(q), 0.0f) != 10.0f) // Sum all elements
|
||||
Error += 1;
|
||||
if(std::distance(begin(q), end(q)) != 4) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#if GLM_LANG & GLM_LANG_CXX20_FLAG
|
||||
{
|
||||
glm::quat const q(1, 2, 3, 4);
|
||||
# ifdef __cpp_lib_ranges_fold
|
||||
if(std::ranges::fold_left(q, 0.0f, std::plus<>()) != 10.0f) // Sum all elements
|
||||
Error += 1;
|
||||
# endif
|
||||
if(std::ranges::distance(begin(q), end(q)) != 4) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat()
|
||||
static int test_mat4x3()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
|
@ -66,20 +222,98 @@ static int test_mat()
|
|||
{
|
||||
glm::mat4x3 m(1.0f);
|
||||
|
||||
for (float& x : m) { x = 0; }
|
||||
for(float& x : m)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
glm::vec4 v(1, 1, 1, 1);
|
||||
Error += glm::all(glm::equal(m*v, glm::vec3(0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
// Sum all using std::accumulate
|
||||
{
|
||||
glm::mat4x3 const m(1.0f);
|
||||
if(std::accumulate(begin(m), end(m), 0.0f) != 3.0f) // Sum all elements
|
||||
Error += 1;
|
||||
if(std::distance(begin(m), end(m)) != 12) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#if GLM_LANG & GLM_LANG_CXX20_FLAG
|
||||
// Sum all using ranges
|
||||
{
|
||||
glm::mat4x3 const m(1.0f);
|
||||
# ifdef __cpp_lib_ranges_fold
|
||||
if(std::ranges::fold_left(m, 0.0f, std::plus<>()) != 3.0f) // Sum all elements
|
||||
Error += 1;
|
||||
# endif
|
||||
if(std::ranges::distance(begin(m), end(m)) != 12) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat4()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mat4 m(1.0f);
|
||||
|
||||
int count = 0;
|
||||
float Sum = 0.0f;
|
||||
for(float x : m)
|
||||
{
|
||||
count++;
|
||||
Sum += x;
|
||||
}
|
||||
Error += count == 16 ? 0 : 1;
|
||||
Error += glm::equal(Sum, 4.0f, 0.001f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4 m(1.0f);
|
||||
|
||||
for(float& x : m)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
glm::vec4 v(1, 1, 1, 1);
|
||||
Error += glm::all(glm::equal(m*v, glm::vec4(0, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4 const m(1.0f);
|
||||
if(std::accumulate(begin(m), end(m), 0.0f) != 4.0f) // Sum all elements
|
||||
Error += 1;
|
||||
if(std::distance(begin(m), end(m)) != 16) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#if GLM_LANG & GLM_LANG_CXX20_FLAG
|
||||
{
|
||||
glm::mat4 const m(1.0f);
|
||||
# ifdef __cpp_lib_ranges_fold
|
||||
if(std::ranges::fold_left(m, 0, std::plus<>()) != 4.0f) // Sum all elements
|
||||
Error += 1;
|
||||
# endif
|
||||
if(std::ranges::distance(begin(m), end(m)) != 16) // Count number of elements
|
||||
Error += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
Error += test_vec();
|
||||
Error += test_vec2();
|
||||
Error += test_vec3();
|
||||
Error += test_vec4();
|
||||
Error += test_quat();
|
||||
Error += test_mat();
|
||||
Error += test_mat4x3();
|
||||
Error += test_mat4();
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,22 +3,48 @@
|
|||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#if GLM_HAS_RANGE_FOR
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/span.hpp>
|
||||
|
||||
static int test_vec()
|
||||
#if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
||||
static int test_span_vec2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
//TODO
|
||||
/*{
|
||||
{
|
||||
glm::ivec2 const v(1, 2);
|
||||
|
||||
int count = 0;
|
||||
glm::ivec2 Result(0);
|
||||
for(int x : glm::span(v))
|
||||
{
|
||||
Result[count] = x;
|
||||
count++;
|
||||
}
|
||||
Error += count == 2 ? 0 : 1;
|
||||
Error += v == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 v(1, 2);
|
||||
for(int& x : glm::span(v))
|
||||
x = 0;
|
||||
Error += glm::all(glm::equal(v, glm::ivec2(0))) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_span_vec3()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec3 const v(1, 2, 3);
|
||||
|
||||
int count = 0;
|
||||
glm::ivec3 Result(0);
|
||||
for(int x : v)
|
||||
for(int x : glm::span(v))
|
||||
{
|
||||
Result[count] = x;
|
||||
count++;
|
||||
|
@ -29,34 +55,80 @@ static int test_vec()
|
|||
|
||||
{
|
||||
glm::ivec3 v(1, 2, 3);
|
||||
for(int& x : v)
|
||||
for(int& x : glm::span(v))
|
||||
x = 0;
|
||||
Error += glm::all(glm::equal(v, glm::ivec3(0))) ? 0 : 1;
|
||||
}*/
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_quat()
|
||||
static int test_span_vec4()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
//TODO
|
||||
{
|
||||
glm::ivec4 const v(1, 2, 3, 4);
|
||||
|
||||
int count = 0;
|
||||
glm::ivec4 Result(0);
|
||||
for(int x : glm::span(v))
|
||||
{
|
||||
Result[count] = x;
|
||||
count++;
|
||||
}
|
||||
Error += count == 4 ? 0 : 1;
|
||||
Error += v == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 v(1, 2, 3, 4);
|
||||
for(int& x : glm::span(v))
|
||||
x = 0;
|
||||
Error += glm::all(glm::equal(v, glm::ivec4(0))) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat()
|
||||
static int test_span_quat()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
//TODO
|
||||
/*{
|
||||
{
|
||||
glm::quat const q(1, 2, 3, 4);
|
||||
|
||||
int count = 0;
|
||||
glm::quat Result(0, 0, 0, 0);
|
||||
for(float x : glm::span(q))
|
||||
{
|
||||
Result[count] = x;
|
||||
count++;
|
||||
}
|
||||
Error += count == 4 ? 0 : 1;
|
||||
Error += q == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::quat q(1, 2, 3, 4);
|
||||
for(float& x : glm::span(q))
|
||||
x = 0;
|
||||
Error += glm::all(glm::equal(q, glm::quat(0, 0, 0, 0))) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_span_mat()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mat4x3 m(1.0f);
|
||||
|
||||
int count = 0;
|
||||
float Sum = 0.0f;
|
||||
for(float x : m)
|
||||
for(float x : glm::span(m))
|
||||
{
|
||||
count++;
|
||||
Sum += x;
|
||||
|
@ -68,28 +140,27 @@ static int test_mat()
|
|||
{
|
||||
glm::mat4x3 m(1.0f);
|
||||
|
||||
for (float& x : m) { x = 0; }
|
||||
for(float& x : glm::span(m))
|
||||
x = 0;
|
||||
glm::vec4 v(1, 1, 1, 1);
|
||||
Error += glm::all(glm::equal(m*v, glm::vec3(0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}*/
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
Error += test_vec();
|
||||
Error += test_quat();
|
||||
Error += test_mat();
|
||||
//TODO std::valarray
|
||||
#if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
||||
Error += test_span_vec2();
|
||||
Error += test_span_vec3();
|
||||
Error += test_span_vec4();
|
||||
Error += test_span_quat();
|
||||
Error += test_span_mat();
|
||||
#endif
|
||||
//TODO std::mdspan
|
||||
return Error;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif//GLM_HAS_RANGE_FOR
|
||||
|
|
Loading…
Add table
Reference in a new issue