Added constexpr relational operators
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
/// @ref core
|
||||
/// @file glm/detail/func_vector_relational.inl
|
||||
|
||||
#include "compute_vector_relational.hpp"
|
||||
|
||||
@@ -10,58 +9,119 @@
|
||||
# define GLM_BUG_VC_INIT
|
||||
#endif
|
||||
|
||||
namespace glm
|
||||
namespace glm{
|
||||
namespace detail
|
||||
{
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> lessThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
enum relational_type
|
||||
{
|
||||
assert(x.length() == y.length());
|
||||
LESS,
|
||||
LESS_EQUAL,
|
||||
GREATER,
|
||||
GREATER_EQUAL
|
||||
};
|
||||
|
||||
template <relational_type R>
|
||||
struct relational
|
||||
{
|
||||
template<typename T>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct relational<LESS>
|
||||
{
|
||||
template<typename T>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1)
|
||||
{
|
||||
return Src0 < Src1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct relational<LESS_EQUAL>
|
||||
{
|
||||
template<typename T>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1)
|
||||
{
|
||||
return Src0 <= Src1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct relational<GREATER>
|
||||
{
|
||||
template<typename T>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1)
|
||||
{
|
||||
return Src0 > Src1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct relational<GREATER_EQUAL>
|
||||
{
|
||||
template<typename T>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1)
|
||||
{
|
||||
return Src0 >= Src1;
|
||||
}
|
||||
};
|
||||
|
||||
template<length_t I, length_t N, relational_type R>
|
||||
struct loop_relational
|
||||
{
|
||||
template<typename vecBType, typename vecType>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static void call(vecBType& Dst, vecType const& Src0, vecType const& Src1)
|
||||
{
|
||||
Dst[I] = relational<R>::call(Src0[I], Src1[I]);
|
||||
loop_relational<I + 1, N, R>::call(Dst, Src0, Src1);
|
||||
}
|
||||
};
|
||||
|
||||
template <length_t N, relational_type R>
|
||||
struct loop_relational<N, N, R>
|
||||
{
|
||||
template<typename vecBType, typename vecType>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static void call(vecBType&, vecType const&, vecType const&)
|
||||
{}
|
||||
};
|
||||
}//namespace detail
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> lessThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
{
|
||||
vec<L, bool, Q> Result GLM_BUG_VC_INIT;
|
||||
for(length_t i = 0; i < x.length(); ++i)
|
||||
Result[i] = x[i] < y[i];
|
||||
|
||||
detail::loop_relational<0, L, detail::LESS>::call(Result, x, y);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> lessThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> lessThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
{
|
||||
assert(x.length() == y.length());
|
||||
|
||||
vec<L, bool, Q> Result GLM_BUG_VC_INIT;
|
||||
for(length_t i = 0; i < x.length(); ++i)
|
||||
Result[i] = x[i] <= y[i];
|
||||
detail::loop_relational<0, L, detail::LESS_EQUAL>::call(Result, x, y);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> greaterThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> greaterThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
{
|
||||
assert(x.length() == y.length());
|
||||
|
||||
vec<L, bool, Q> Result GLM_BUG_VC_INIT;
|
||||
for(length_t i = 0; i < x.length(); ++i)
|
||||
Result[i] = x[i] > y[i];
|
||||
detail::loop_relational<0, L, detail::GREATER>::call(Result, x, y);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> greaterThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> greaterThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
{
|
||||
assert(x.length() == y.length());
|
||||
|
||||
vec<L, bool, Q> Result GLM_BUG_VC_INIT;
|
||||
for(length_t i = 0; i < x.length(); ++i)
|
||||
Result[i] = x[i] >= y[i];
|
||||
detail::loop_relational<0, L, detail::GREATER_EQUAL>::call(Result, x, y);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
{
|
||||
assert(x.length() == y.length());
|
||||
|
||||
vec<L, bool, Q> Result GLM_BUG_VC_INIT;
|
||||
for(length_t i = 0; i < x.length(); ++i)
|
||||
Result[i] = detail::compute_equal<T, std::numeric_limits<T>::is_iec559>::call(x[i], y[i]);
|
||||
@@ -71,8 +131,6 @@ namespace glm
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
|
||||
{
|
||||
assert(x.length() == y.length());
|
||||
|
||||
vec<L, bool, Q> Result GLM_BUG_VC_INIT;
|
||||
for(length_t i = 0; i < x.length(); ++i)
|
||||
Result[i] = !detail::compute_equal<T, std::numeric_limits<T>::is_iec559>::call(x[i], y[i]);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace glm
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<typename genType>
|
||||
GLM_FUNC_DECL bool equal(genType const& x, genType const& y, genType const& epsilon);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR bool equal(genType const& x, genType const& y, genType const& epsilon);
|
||||
|
||||
/// Returns the component-wise comparison of |x - y| >= epsilon.
|
||||
/// True if this expression is not satisfied.
|
||||
@@ -38,7 +38,7 @@ namespace glm
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<typename genType>
|
||||
GLM_FUNC_DECL bool notEqual(genType const& x, genType const& y, genType const& epsilon);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR bool notEqual(genType const& x, genType const& y, genType const& epsilon);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
namespace glm
|
||||
{
|
||||
template<typename genType>
|
||||
GLM_FUNC_QUALIFIER bool equal(genType const& x, genType const& y, genType const& epsilon)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool equal(genType const& x, genType const& y, genType const& epsilon)
|
||||
{
|
||||
return abs(x - y) <= epsilon;
|
||||
}
|
||||
|
||||
template<typename genType>
|
||||
GLM_FUNC_QUALIFIER bool notEqual(genType const& x, genType const& y, genType const& epsilon)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool notEqual(genType const& x, genType const& y, genType const& epsilon)
|
||||
{
|
||||
return abs(x - y) > epsilon;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace glm
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon);
|
||||
|
||||
/// Returns the component-wise comparison of |x - y| < epsilon.
|
||||
/// True if this expression is satisfied.
|
||||
@@ -45,7 +45,7 @@ namespace glm
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon);
|
||||
|
||||
/// Returns the component-wise comparison of |x - y| >= epsilon.
|
||||
/// True if this expression is not satisfied.
|
||||
@@ -56,7 +56,7 @@ namespace glm
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon);
|
||||
|
||||
/// Returns the component-wise comparison of |x - y| >= epsilon.
|
||||
/// True if this expression is not satisfied.
|
||||
@@ -67,7 +67,7 @@ namespace glm
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
@@ -8,25 +8,25 @@
|
||||
namespace glm
|
||||
{
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon)
|
||||
{
|
||||
return equal(x, y, vec<L, T, Q>(epsilon));
|
||||
}
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon)
|
||||
{
|
||||
return lessThanEqual(abs(x - y), epsilon);
|
||||
}
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon)
|
||||
{
|
||||
return notEqual(x, y, vec<L, T, Q>(epsilon));
|
||||
}
|
||||
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon)
|
||||
{
|
||||
return greaterThan(abs(x - y), epsilon);
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ namespace glm
|
||||
union
|
||||
{
|
||||
struct { T x, y, z, w;};
|
||||
};
|
||||
|
||||
typename detail::storage<4, T, detail::is_aligned<Q>::value>::type data;
|
||||
typename detail::storage<4, T, detail::is_aligned<Q>::value>::type data;
|
||||
};
|
||||
# else
|
||||
T x, y, z, w;
|
||||
# endif
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace glm
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThan.xml">GLSL lessThan man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> lessThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> lessThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
|
||||
/// Returns the component-wise comparison of result x <= y.
|
||||
///
|
||||
@@ -43,7 +43,7 @@ namespace glm
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThanEqual.xml">GLSL lessThanEqual man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> lessThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> lessThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
|
||||
/// Returns the component-wise comparison of result x > y.
|
||||
///
|
||||
@@ -53,7 +53,7 @@ namespace glm
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThan.xml">GLSL greaterThan man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> greaterThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> greaterThan(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
|
||||
/// Returns the component-wise comparison of result x >= y.
|
||||
///
|
||||
@@ -63,7 +63,7 @@ namespace glm
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThanEqual.xml">GLSL greaterThanEqual man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, bool, Q> greaterThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<L, bool, Q> greaterThanEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
|
||||
|
||||
/// Returns the component-wise comparison of result x == y.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user