Compare commits

..

1 Commits

Author SHA1 Message Date
ef9c7ac15d
Added spaceship operator. 2023-01-02 17:12:23 +01:00
6 changed files with 18 additions and 95 deletions

View File

@ -7,12 +7,6 @@
#include <cmath> #include <cmath>
#include <cassert> #include <cassert>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem.
#if GLM_ENABLE_CONSTEXPR_MATH == GLM_ENABLE
# include <gcem.hpp>
#endif
// END @MEWIN
namespace glm{ namespace glm{
namespace detail namespace detail
{ {
@ -40,12 +34,10 @@ namespace detail
template<length_t L, typename T, qualifier Q, bool Aligned> template<length_t L, typename T, qualifier Q, bool Aligned>
struct compute_sqrt struct compute_sqrt
{ {
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& x)
GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& x)
{ {
return detail::functor1<vec, L, T, T, Q>::call(GLM_MATH_BASE_NS::sqrt, x); return detail::functor1<vec, L, T, T, Q>::call(std::sqrt, x);
} }
// END @MEWIN
}; };
template<length_t L, typename T, qualifier Q, bool Aligned> template<length_t L, typename T, qualifier Q, bool Aligned>
@ -131,13 +123,9 @@ namespace detail
} }
// sqrt // sqrt
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. using std::sqrt;
using GLM_MATH_BASE_NS::sqrt;
// END @MEWIN
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER vec<L, T, Q> sqrt(vec<L, T, Q> const& x)
GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR vec<L, T, Q> sqrt(vec<L, T, Q> const& x)
// END @MEWIN
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'sqrt' only accept floating-point inputs"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'sqrt' only accept floating-point inputs");
return detail::compute_sqrt<L, T, Q, detail::is_aligned<Q>::value>::call(x); return detail::compute_sqrt<L, T, Q, detail::is_aligned<Q>::value>::call(x);

View File

@ -7,9 +7,7 @@ namespace detail
template<length_t L, typename T, qualifier Q, bool Aligned> template<length_t L, typename T, qualifier Q, bool Aligned>
struct compute_length struct compute_length
{ {
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER static T call(vec<L, T, Q> const& v)
GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR static T call(vec<L, T, Q> const& v)
// END @MEWIN
{ {
return sqrt(dot(v, v)); return sqrt(dot(v, v));
} }
@ -18,9 +16,7 @@ namespace detail
template<length_t L, typename T, qualifier Q, bool Aligned> template<length_t L, typename T, qualifier Q, bool Aligned>
struct compute_distance struct compute_distance
{ {
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER static T call(vec<L, T, Q> const& p0, vec<L, T, Q> const& p1)
GLM_FUNC_QUALIFIER static GLM_MATH_CONSTEXPR T call(vec<L, T, Q> const& p0, vec<L, T, Q> const& p1)
// END @MEWIN
{ {
return length(p1 - p0); return length(p1 - p0);
} }
@ -129,9 +125,7 @@ namespace detail
// length // length
template<typename genType> template<typename genType>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER genType length(genType x)
GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR genType length(genType x)
// END @MEWIN
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length' accepts only floating-point inputs"); GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length' accepts only floating-point inputs");
@ -139,9 +133,7 @@ namespace detail
} }
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER T length(vec<L, T, Q> const& v)
GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR T length(vec<L, T, Q> const& v)
// END @MEWIN
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'length' accepts only floating-point inputs"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'length' accepts only floating-point inputs");
@ -150,9 +142,7 @@ namespace detail
// distance // distance
template<typename genType> template<typename genType>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER genType distance(genType const& p0, genType const& p1)
GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR genType distance(genType const& p0, genType const& p1)
// END @MEWIN
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'distance' accepts only floating-point inputs"); GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'distance' accepts only floating-point inputs");
@ -160,9 +150,7 @@ namespace detail
} }
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_QUALIFIER T distance(vec<L, T, Q> const& p0, vec<L, T, Q> const& p1)
GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR T distance(vec<L, T, Q> const& p0, vec<L, T, Q> const& p1)
// END @MEWIN
{ {
return detail::compute_distance<L, T, Q, detail::is_aligned<Q>::value>::call(p0, p1); return detail::compute_distance<L, T, Q, detail::is_aligned<Q>::value>::call(p0, p1);
} }

View File

@ -308,26 +308,7 @@
# define GLM_CONSTEXPR # define GLM_CONSTEXPR
#endif #endif
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem.
#if !defined(GLM_ENABLE_CONSTEXPR_MATH)
# if (GLM_LANG & GLM_LANG_CXX17_FLAG)
# define GLM_ENABLE_CONSTEXPR_MATH __has_include(<gcem.hpp>)
# else
# define GLM_ENABLE_CONSTEXPR_MATH 0
# endif
#endif
#if GLM_ENABLE_CONSTEXPR_MATH == GLM_ENABLE
# define GLM_MATH_CONSTEXPR GLM_CONSTEXPR
# define GLM_MATH_BASE_NS gcem
#else
# define GLM_MATH_CONSTEXPR GLM_INLINE
# define GLM_MATH_BASE_NS std
#endif
// END @MEWIN
// //
#if GLM_HAS_CONSTEXPR #if GLM_HAS_CONSTEXPR
# if (GLM_COMPILER & GLM_COMPILER_CLANG) # if (GLM_COMPILER & GLM_COMPILER_CLANG)
# if __has_feature(cxx_if_constexpr) # if __has_feature(cxx_if_constexpr)

View File

@ -20,12 +20,6 @@
#include "detail/type_vec4.hpp" #include "detail/type_vec4.hpp"
#include <cmath> #include <cmath>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem.
#if GLM_ENABLE_CONSTEXPR_MATH == GLM_ENABLE
# include <gcem.hpp>
#endif
// END @MEWIN
namespace glm namespace glm
{ {
/// @addtogroup core_func_exponential /// @addtogroup core_func_exponential
@ -97,9 +91,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sqrt.xml">GLSL sqrt man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sqrt.xml">GLSL sqrt man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_DECL vec<L, T, Q> sqrt(vec<L, T, Q> const& v);
GLM_FUNC_DECL GLM_MATH_CONSTEXPR vec<L, T, Q> sqrt(vec<L, T, Q> const& v);
// END @MEWIN
/// Returns the reciprocal of the positive square root of v. /// Returns the reciprocal of the positive square root of v.
/// ///

View File

@ -27,9 +27,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/length.xml">GLSL length man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/length.xml">GLSL length man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_DECL T length(vec<L, T, Q> const& x);
GLM_FUNC_DECL GLM_MATH_CONSTEXPR T length(vec<L, T, Q> const& x);
// END @MEWIN
/// Returns the distance between p0 and p1, i.e., length(p0 - p1). /// Returns the distance between p0 and p1, i.e., length(p0 - p1).
/// ///
@ -39,9 +37,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/distance.xml">GLSL distance man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/distance.xml">GLSL distance man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. GLM_FUNC_DECL T distance(vec<L, T, Q> const& p0, vec<L, T, Q> const& p1);
GLM_FUNC_DECL GLM_MATH_CONSTEXPR T distance(vec<L, T, Q> const& p0, vec<L, T, Q> const& p1);
// END @MEWIN
/// Returns the dot product of x and y, i.e., result = x * y. /// Returns the dot product of x and y, i.e., result = x * y.
/// ///

View File

@ -1,4 +1,3 @@
// @MEWIN - 2023-01-02 - Added support for spaceship operator.
#pragma once #pragma once
@ -8,48 +7,27 @@
namespace glm namespace glm
{ {
template<length_t L, typename T, qualifier Q> template<length_t l, typename T, qualifier q>
struct vec; GLM_FUNC_DECL GLM_CONSTEXPR std::strong_ordering operator<=>(const glm::vec<l, T, q>& left, const glm::vec<l, T, q>& right)
template<length_t C, length_t R, typename T, qualifier Q>
struct mat;
template<length_t L, typename T, qualifier Q>
GLM_FUNC_DECL GLM_CONSTEXPR std::strong_ordering operator<=>(const vec<L, T, Q>& left, const vec<L, T, Q>& right)
{ {
if (left[0] != right[0]) { if (left[0] != right[0]) {
return left[0] <=> right[0]; return left[0] <=> right[0];
} }
if constexpr (L > 1) { if constexpr (l > 1) {
if (left[1] != right[1]) { if (left[1] != right[1]) {
return left[1] <=> right[1]; return left[1] <=> right[1];
} }
} }
if constexpr (L > 2) { if constexpr (l > 2) {
if (left[2] != right[2]) { if (left[2] != right[2]) {
return left[2] <=> right[2]; return left[2] <=> right[2];
} }
} }
if constexpr (L > 3) { if constexpr (l > 3) {
if (left[3] != right[3]) { if (left[3] != right[3]) {
return left[3] <=> right[3]; return left[3] <=> right[3];
} }
} }
return std::strong_ordering::equal; return std::strong_ordering::equal;
} }
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_DECL GLM_CONSTEXPR std::strong_ordering operator<=>(const mat<C, R, T, Q>& left, const mat<C, R, T, Q>& right)
{
for (int col = 0; col < C; ++col)
{
for (int row = 0; row < R; ++row)
{
if (left[col][row] != right[col][row]) {
return left[col][row] <=> right[col][row];
}
}
}
return std::strong_ordering::equal;
}
} }