This commit is contained in:
Christophe 2019-08-07 14:13:16 +02:00
commit 22af215da4
3 changed files with 56 additions and 4 deletions

View File

@ -1,2 +0,0 @@
{
}

View File

@ -71,13 +71,13 @@ namespace detail
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER T lxNorm(vec<3, T, Q> const& x, vec<3, T, Q> const& y, unsigned int Depth) GLM_FUNC_QUALIFIER T lxNorm(vec<3, T, Q> const& x, vec<3, T, Q> const& y, unsigned int Depth)
{ {
return pow(pow(y.x - x.x, T(Depth)) + pow(y.y - x.y, T(Depth)) + pow(y.z - x.z, T(Depth)), T(1) / T(Depth)); return pow(pow(abs(y.x - x.x), T(Depth)) + pow(abs(y.y - x.y), T(Depth)) + pow(abs(y.z - x.z), T(Depth)), T(1) / T(Depth));
} }
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER T lxNorm(vec<3, T, Q> const& v, unsigned int Depth) GLM_FUNC_QUALIFIER T lxNorm(vec<3, T, Q> const& v, unsigned int Depth)
{ {
return pow(pow(v.x, T(Depth)) + pow(v.y, T(Depth)) + pow(v.z, T(Depth)), T(1) / T(Depth)); return pow(pow(abs(v.x), T(Depth)) + pow(abs(v.y), T(Depth)) + pow(abs(v.z), T(Depth)), T(1) / T(Depth));
} }
}//namespace glm }//namespace glm

View File

@ -1,9 +1,63 @@
#define GLM_ENABLE_EXPERIMENTAL #define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/norm.hpp> #include <glm/gtx/norm.hpp>
int test_lxNorm()
{
int Error(0);
{
unsigned int depth_1 = 1;
float normA = glm::lxNorm(glm::vec3(2, 3, 1), depth_1);
float normB = glm::l1Norm(glm::vec3(2, 3, 1));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 6.f, 0.00001f) ? 0 : 1;
}
{
unsigned int depth_1 = 1;
float normA = glm::lxNorm(glm::vec3(-1, -2, -3), depth_1);
float normB = glm::l1Norm(glm::vec3(-1, -2, -3));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 6.f, 0.00001f) ? 0 : 1;
}
{
unsigned int depth_2 = 2;
float normA = glm::lxNorm(glm::vec3(2, 3, 1), depth_2);
float normB = glm::l2Norm(glm::vec3(2, 3, 1));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 3.741657387f, 0.00001f) ? 0 : 1;
}
{
unsigned int depth_2 = 2;
float normA = glm::lxNorm(glm::vec3(-1, -2, -3), depth_2);
float normB = glm::l2Norm(glm::vec3(-1, -2, -3));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 3.741657387f, 0.00001f) ? 0 : 1;
}
{
unsigned int oddDepth = 3;
float norm = glm::lxNorm(glm::vec3(2, 3, 1), oddDepth);
Error += glm::epsilonEqual(norm, 3.301927249f, 0.00001f) ? 0 : 1;
}
{
unsigned int oddDepth = 3;
float norm = glm::lxNorm(glm::vec3(-1, -2, -3), oddDepth);
Error += glm::epsilonEqual(norm, 3.301927249f, 0.00001f) ? 0 : 1;
}
return Error;
}
int main() int main()
{ {
int Error(0); int Error(0);
Error += test_lxNorm();
return Error; return Error;
} }