Merge branch '0.9.3' of ssh://ogl-math.git.sourceforge.net/gitroot/ogl-math/ogl-math into 0.9.3
This commit is contained in:
@@ -9,14 +9,132 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
static int test_vec3_operators()
|
||||
int test_vec3_operators()
|
||||
{
|
||||
glm::vec3 A(1.0f);
|
||||
glm::vec3 B(1.0f);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f);
|
||||
glm::vec3 B(1.0f);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
glm::vec3 C = A + B;
|
||||
Error += C == glm::vec3(5, 7, 9) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = B - A;
|
||||
Error += D == glm::vec3(3, 3, 3) ? 0 : 1;
|
||||
|
||||
glm::vec3 E = A * B;
|
||||
Error += E == glm::vec3(4, 10, 18) ? 0 : 1;
|
||||
|
||||
glm::vec3 F = B / A;
|
||||
Error += F == glm::vec3(4, 2.5, 2) ? 0 : 1;
|
||||
|
||||
glm::vec3 G = A + 1.0f;
|
||||
Error += G == glm::vec3(2, 3, 4) ? 0 : 1;
|
||||
|
||||
glm::vec3 H = B - 1.0f;
|
||||
Error += H == glm::vec3(3, 4, 5) ? 0 : 1;
|
||||
|
||||
glm::vec3 I = A * 2.0f;
|
||||
Error += I == glm::vec3(2, 4, 6) ? 0 : 1;
|
||||
|
||||
glm::vec3 J = B / 2.0f;
|
||||
Error += J == glm::vec3(2, 2.5, 3) ? 0 : 1;
|
||||
|
||||
glm::vec3 K = 1.0f + A;
|
||||
Error += K == glm::vec3(2, 3, 4) ? 0 : 1;
|
||||
|
||||
glm::vec3 L = 1.0f - B;
|
||||
Error += L == glm::vec3(-3, -4, -5) ? 0 : 1;
|
||||
|
||||
glm::vec3 M = 2.0f * A;
|
||||
Error += M == glm::vec3(2, 4, 6) ? 0 : 1;
|
||||
|
||||
glm::vec3 N = 2.0f / B;
|
||||
Error += N == glm::vec3(0.5, 2.0 / 5.0, 2.0 / 6.0) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
A += B;
|
||||
Error += A == glm::vec3(5, 7, 9) ? 0 : 1;
|
||||
|
||||
A += 1.0f;
|
||||
Error += A == glm::vec3(6, 8, 10) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
B -= A;
|
||||
Error += B == glm::vec3(3, 3, 3) ? 0 : 1;
|
||||
|
||||
B -= 1.0f;
|
||||
Error += B == glm::vec3(2, 2, 2) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
A *= B;
|
||||
Error += A == glm::vec3(4, 10, 18) ? 0 : 1;
|
||||
|
||||
A *= 2.0f;
|
||||
Error += A == glm::vec3(8, 20, 36) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
B /= A;
|
||||
Error += B == glm::vec3(4, 2.5, 2) ? 0 : 1;
|
||||
|
||||
B /= 2.0f;
|
||||
Error += B == glm::vec3(2, 1.25, 1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B = -A;
|
||||
Error += B == glm::vec3(-1.0f, -2.0f, -3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B = --A;
|
||||
Error += B == glm::vec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B = A--;
|
||||
Error += B == glm::vec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B = ++A;
|
||||
Error += B == glm::vec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B = A++;
|
||||
Error += B == glm::vec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_size()
|
||||
|
||||
@@ -43,12 +43,130 @@ int test_hvec4()
|
||||
|
||||
int test_vec4_operators()
|
||||
{
|
||||
glm::vec4 A(1.0f);
|
||||
glm::vec4 B(1.0f);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f);
|
||||
glm::vec4 B(1.0f);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
glm::vec4 C = A + B;
|
||||
Error += C == glm::vec4(5, 7, 9, 11) ? 0 : 1;
|
||||
|
||||
glm::vec4 D = B - A;
|
||||
Error += D == glm::vec4(3, 3, 3, 3) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = A * B;
|
||||
Error += E == glm::vec4(4, 10, 18, 28) ? 0 : 1;
|
||||
|
||||
glm::vec4 F = B / A;
|
||||
Error += F == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
|
||||
|
||||
glm::vec4 G = A + 1.0f;
|
||||
Error += G == glm::vec4(2, 3, 4, 5) ? 0 : 1;
|
||||
|
||||
glm::vec4 H = B - 1.0f;
|
||||
Error += H == glm::vec4(3, 4, 5, 6) ? 0 : 1;
|
||||
|
||||
glm::vec4 I = A * 2.0f;
|
||||
Error += I == glm::vec4(2, 4, 6, 8) ? 0 : 1;
|
||||
|
||||
glm::vec4 J = B / 2.0f;
|
||||
Error += J == glm::vec4(2, 2.5, 3, 3.5) ? 0 : 1;
|
||||
|
||||
glm::vec4 K = 1.0f + A;
|
||||
Error += K == glm::vec4(2, 3, 4, 5) ? 0 : 1;
|
||||
|
||||
glm::vec4 L = 1.0f - B;
|
||||
Error += L == glm::vec4(-3, -4, -5, -6) ? 0 : 1;
|
||||
|
||||
glm::vec4 M = 2.0f * A;
|
||||
Error += M == glm::vec4(2, 4, 6, 8) ? 0 : 1;
|
||||
|
||||
glm::vec4 N = 2.0f / B;
|
||||
Error += N == glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
A += B;
|
||||
Error += A == glm::vec4(5, 7, 9, 11) ? 0 : 1;
|
||||
|
||||
A += 1.0f;
|
||||
Error += A == glm::vec4(6, 8, 10, 12) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
B -= A;
|
||||
Error += B == glm::vec4(3, 3, 3, 3) ? 0 : 1;
|
||||
|
||||
B -= 1.0f;
|
||||
Error += B == glm::vec4(2, 2, 2, 2) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
A *= B;
|
||||
Error += A == glm::vec4(4, 10, 18, 28) ? 0 : 1;
|
||||
|
||||
A *= 2.0f;
|
||||
Error += A == glm::vec4(8, 20, 36, 56) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
B /= A;
|
||||
Error += B == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
|
||||
|
||||
B /= 2.0f;
|
||||
Error += B == glm::vec4(2, 1.25, 1, 7.0f / 4.0f / 2.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B = -A;
|
||||
Error += B == glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B = --A;
|
||||
Error += B == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B = A--;
|
||||
Error += B == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B = ++A;
|
||||
Error += B == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B = A++;
|
||||
Error += B == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec4_size()
|
||||
|
||||
@@ -33,7 +33,7 @@ int test_linearRand()
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_normalizedRand2()
|
||||
int test_circularRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
@@ -41,21 +41,23 @@ int test_normalizedRand2()
|
||||
std::size_t Max = 100000;
|
||||
float ResultFloat = 0.0f;
|
||||
double ResultDouble = 0.0f;
|
||||
double Radius = 2.0f;
|
||||
|
||||
for(std::size_t i = 0; i < Max; ++i)
|
||||
{
|
||||
ResultFloat += glm::length(glm::normalizedRand2(1.0f, 1.0f));
|
||||
ResultDouble += glm::length(glm::normalizedRand2(1.0f, 1.0f));
|
||||
ResultFloat += glm::length(glm::circularRand(1.0f));
|
||||
ResultDouble += glm::length(glm::circularRand(Radius));
|
||||
}
|
||||
|
||||
Error += glm::equalEpsilon(ResultFloat, float(Max), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDouble, double(Max), 0.01) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDouble, double(Max) * double(Radius), 0.01) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_normalizedRand3()
|
||||
int test_sphericalRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
@@ -67,22 +69,67 @@ int test_normalizedRand3()
|
||||
double ResultDoubleA = 0.0f;
|
||||
double ResultDoubleB = 0.0f;
|
||||
double ResultDoubleC = 0.0f;
|
||||
|
||||
for(std::size_t i = 0; i < Max; ++i)
|
||||
{
|
||||
ResultFloatA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
|
||||
ResultDoubleA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
|
||||
ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f));
|
||||
ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0));
|
||||
ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f));
|
||||
ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0));
|
||||
ResultFloatA += glm::length(glm::sphericalRand(1.0f));
|
||||
ResultDoubleA += glm::length(glm::sphericalRand(1.0));
|
||||
ResultFloatB += glm::length(glm::sphericalRand(2.0f));
|
||||
ResultDoubleB += glm::length(glm::sphericalRand(2.0));
|
||||
ResultFloatC += glm::length(glm::sphericalRand(3.0f));
|
||||
ResultDoubleC += glm::length(glm::sphericalRand(3.0));
|
||||
}
|
||||
|
||||
Error += glm::equalEpsilon(ResultFloatA, float(Max), 100.0f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 100.0) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 100.0001f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 100.0001) ? 0 : 1;
|
||||
Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1;
|
||||
Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatA, float(Max), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 0.0001) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatC, float(Max * 3), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleC, double(Max * 3), 0.01) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_diskRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float ResultFloat = 0.0f;
|
||||
double ResultDouble = 0.0f;
|
||||
|
||||
for(std::size_t i = 0; i < 100000; ++i)
|
||||
{
|
||||
ResultFloat += glm::length(glm::diskRand(2.0f));
|
||||
ResultDouble += glm::length(glm::diskRand(2.0));
|
||||
}
|
||||
|
||||
Error += ResultFloat < 200000.f ? 0 : 1;
|
||||
Error += ResultDouble < 200000.0 ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_ballRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float ResultFloat = 0.0f;
|
||||
double ResultDouble = 0.0f;
|
||||
|
||||
for(std::size_t i = 0; i < 100000; ++i)
|
||||
{
|
||||
ResultFloat += glm::length(glm::ballRand(2.0f));
|
||||
ResultDouble += glm::length(glm::ballRand(2.0));
|
||||
}
|
||||
|
||||
Error += ResultFloat < 200000.f ? 0 : 1;
|
||||
Error += ResultDouble < 200000.0 ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
@@ -94,8 +141,10 @@ int main()
|
||||
int Error = 0;
|
||||
|
||||
Error += test_linearRand();
|
||||
Error += test_normalizedRand2();
|
||||
Error += test_normalizedRand3();
|
||||
Error += test_circularRand();
|
||||
Error += test_sphericalRand();
|
||||
Error += test_diskRand();
|
||||
Error += test_ballRand();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ int test_simplex()
|
||||
for(std::size_t y = 0; y < Size; ++y)
|
||||
for(std::size_t x = 0; x < Size; ++x)
|
||||
{
|
||||
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec2(x / 16.f, y / 16.f)) * 128.f + 127.f);
|
||||
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec2(x / 32.f, y / 32.f)) * 128.f + 127.f);
|
||||
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
|
||||
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
|
||||
}
|
||||
@@ -40,7 +40,7 @@ int test_simplex()
|
||||
for(std::size_t y = 0; y < Size; ++y)
|
||||
for(std::size_t x = 0; x < Size; ++x)
|
||||
{
|
||||
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec3(x / 16.f, y / 16.f, 0.5f)) * 128.f + 127.f);
|
||||
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec3(x / 32.f, y / 32.f, 0.5f)) * 128.f + 127.f);
|
||||
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
|
||||
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
|
||||
}
|
||||
@@ -57,7 +57,7 @@ int test_simplex()
|
||||
for(std::size_t y = 0; y < Size; ++y)
|
||||
for(std::size_t x = 0; x < Size; ++x)
|
||||
{
|
||||
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)) * 128.f + 127.f);
|
||||
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec4(x / 32.f, y / 32.f, 0.5f, 0.5f)) * 128.f + 127.f);
|
||||
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
|
||||
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user