From 695b058096ec9175d0ed417a054deb6c5b2aacfa Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 24 Sep 2011 23:36:42 +0100 Subject: [PATCH 1/7] Fixed and tested circular and spherical rands --- glm/gtc/random.inl | 4 ++-- test/gtc/gtc_random.cpp | 44 +++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/glm/gtc/random.inl b/glm/gtc/random.inl index 4a05b8f8..105d2f66 100644 --- a/glm/gtc/random.inl +++ b/glm/gtc/random.inl @@ -194,8 +194,8 @@ GLM_FUNC_QUALIFIER detail::tvec3 sphericalRand T const & Radius ) { - T z = compRand1(T(-1), T(1)); - T a = compRand1(T(0), T(6.283185307179586476925286766559f)); + T z = linearRand(T(-1), T(1)); + T a = linearRand(T(0), T(6.283185307179586476925286766559f)); T r = sqrt(T(1) - z * z); diff --git a/test/gtc/gtc_random.cpp b/test/gtc/gtc_random.cpp index 58334468..2dd1a142 100644 --- a/test/gtc/gtc_random.cpp +++ b/test/gtc/gtc_random.cpp @@ -32,8 +32,8 @@ 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; @@ -69,33 +71,33 @@ int test_normalizedRand3() 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 main() { int Error = 0; Error += test_linearRand(); - //Error += test_normalizedRand2(); - //Error += test_normalizedRand3(); + Error += test_circularRand(); + Error += test_sphericalRand(); return Error; } From 387854dbe31974579ae1489fc7be1e3604fb6cd4 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 24 Sep 2011 23:51:49 +0100 Subject: [PATCH 2/7] Fixed and tested disk and ball rands --- glm/gtc/random.inl | 6 +++--- test/gtc/gtc_random.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/glm/gtc/random.inl b/glm/gtc/random.inl index 105d2f66..9310a205 100644 --- a/glm/gtc/random.inl +++ b/glm/gtc/random.inl @@ -141,7 +141,7 @@ GLM_FUNC_QUALIFIER detail::tvec4 gaussRand } template -GLM_FUNC_QUALIFIER detail::tvec3 diskRand +GLM_FUNC_QUALIFIER detail::tvec2 diskRand ( T const & Radius ) @@ -151,7 +151,7 @@ GLM_FUNC_QUALIFIER detail::tvec3 diskRand do { - Result = compRand2(-Radius, Radius); + Result = linearRand(detail::tvec2(-Radius), detail::tvec2(Radius)); LenRadius = length(Result); } while(LenRadius > Radius); @@ -170,7 +170,7 @@ GLM_FUNC_QUALIFIER detail::tvec3 ballRand do { - Result = compRand3(-Radius, Radius); + Result = linearRand(detail::tvec3(-Radius), detail::tvec3(Radius)); LenRadius = length(Result); } while(LenRadius > Radius); diff --git a/test/gtc/gtc_random.cpp b/test/gtc/gtc_random.cpp index 2dd1a142..e1690b69 100644 --- a/test/gtc/gtc_random.cpp +++ b/test/gtc/gtc_random.cpp @@ -91,6 +91,36 @@ int test_sphericalRand() 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; + + + + return Error; +} + int main() { int Error = 0; @@ -98,6 +128,8 @@ int main() Error += test_linearRand(); Error += test_circularRand(); Error += test_sphericalRand(); + Error += test_diskRand(); + Error += test_ballRand(); return Error; } From ca88ff50dde426bbf85f0c49cd65a87c176be2ca Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Sep 2011 02:25:26 +0100 Subject: [PATCH 3/7] Fixed build --- glm/gtc/random.inl | 4 ++-- test/gtc/gtc_random.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/glm/gtc/random.inl b/glm/gtc/random.inl index 9310a205..0d9f4e60 100644 --- a/glm/gtc/random.inl +++ b/glm/gtc/random.inl @@ -92,8 +92,8 @@ GLM_FUNC_QUALIFIER genType gaussRand do { - x1 = compRand1(genType(-1), genType(1)); - x2 = compRand1(genType(-1), genType(1)); + x1 = linearRand(genType(-1), genType(1)); + x2 = linearRand(genType(-1), genType(1)); w = x1 * x1 + x2 * x2; } while(w > genType(1)); diff --git a/test/gtc/gtc_random.cpp b/test/gtc/gtc_random.cpp index e1690b69..08f3cec2 100644 --- a/test/gtc/gtc_random.cpp +++ b/test/gtc/gtc_random.cpp @@ -69,6 +69,7 @@ int test_sphericalRand() 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::sphericalRand(1.0f)); @@ -98,6 +99,7 @@ int test_diskRand() { float ResultFloat = 0.0f; double ResultDouble = 0.0f; + for(std::size_t i = 0; i < 100000; ++i) { ResultFloat += glm::length(glm::diskRand(2.0f)); @@ -116,7 +118,20 @@ 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); + } return Error; } From 97e07f6660c2fb5759efa8e82ac2610d1e47ace1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Sep 2011 05:09:34 +0100 Subject: [PATCH 4/7] Typo / style --- glm/core/func_common.inl | 4 ++-- glm/gtx/noise.inl | 42 ++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/glm/core/func_common.inl b/glm/core/func_common.inl index d7943873..06a45018 100644 --- a/glm/core/func_common.inl +++ b/glm/core/func_common.inl @@ -156,13 +156,13 @@ namespace detail // floor template <> - GLM_FUNC_QUALIFIER detail::thalf floor(detail::thalf const& x) + GLM_FUNC_QUALIFIER detail::thalf floor(detail::thalf const & x) { return detail::thalf(::std::floor(x.toFloat())); } template - GLM_FUNC_QUALIFIER genType floor(genType const& x) + GLM_FUNC_QUALIFIER genType floor(genType const & x) { GLM_STATIC_ASSERT(detail::type::is_float, "'floor' only accept floating-point inputs"); diff --git a/glm/gtx/noise.inl b/glm/gtx/noise.inl index 50841c20..938a0ef8 100644 --- a/glm/gtx/noise.inl +++ b/glm/gtx/noise.inl @@ -695,52 +695,52 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec3 const & v) detail::tvec4 const D(0.0, 0.5, 1.0, 2.0); // First corner - detail::tvec3 i = floor(v + dot(v, detail::tvec3(C.y))); - detail::tvec3 x0 = v - i + dot(i, detail::tvec3(C.x)); + detail::tvec3 i(floor(v + dot(v, detail::tvec3(C.y)))); + detail::tvec3 x0(v - i + dot(i, detail::tvec3(C.x))); // Other corners - detail::tvec3 g = step(detail::tvec3(x0.y, x0.z, x0.x), x0); - detail::tvec3 l = T(1) - g; - detail::tvec3 i1 = min(g, detail::tvec3(l.z, l.x, l.y)); - detail::tvec3 i2 = max(g, detail::tvec3(l.z, l.x, l.y)); + detail::tvec3 g(step(detail::tvec3(x0.y, x0.z, x0.x), x0)); + detail::tvec3 l(T(1) - g); + detail::tvec3 i1(min(g, detail::tvec3(l.z, l.x, l.y))); + detail::tvec3 i2(max(g, detail::tvec3(l.z, l.x, l.y))); // x0 = x0 - 0.0 + 0.0 * C.xxx; // x1 = x0 - i1 + 1.0 * C.xxx; // x2 = x0 - i2 + 2.0 * C.xxx; // x3 = x0 - 1.0 + 3.0 * C.xxx; - detail::tvec3 x1 = x0 - i1 + C.x; - detail::tvec3 x2 = x0 - i2 + C.y; // 2.0*C.x = 1/3 = C.y - detail::tvec3 x3 = x0 - D.y; // -1.0+3.0*C.x = -0.5 = -D.y + detail::tvec3 x1(x0 - i1 + C.x); + detail::tvec3 x2(x0 - i2 + C.y); // 2.0*C.x = 1/3 = C.y + detail::tvec3 x3(x0 - D.y); // -1.0+3.0*C.x = -0.5 = -D.y // Permutations i = mod289(i); - detail::tvec4 p = permute(permute(permute( + detail::tvec4 p(permute(permute(permute( i.z + detail::tvec4(T(0), i1.z, i2.z, T(1))) + i.y + detail::tvec4(T(0), i1.y, i2.y, T(1))) + - i.x + detail::tvec4(T(0), i1.x, i2.x, T(1))); + i.x + detail::tvec4(T(0), i1.x, i2.x, T(1)))); // Gradients: 7x7 points over a square, mapped onto an octahedron. // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) T n_ = T(0.142857142857); // 1.0/7.0 - detail::tvec3 ns = n_ * detail::tvec3(D.w, D.y, D.z) - detail::tvec3(D.x, D.z, D.x); + detail::tvec3 ns(n_ * detail::tvec3(D.w, D.y, D.z) - detail::tvec3(D.x, D.z, D.x)); - detail::tvec4 j = p - T(49) * floor(p * ns.z * ns.z); // mod(p,7*7) + detail::tvec4 j(p - T(49) * floor(p * ns.z * ns.z)); // mod(p,7*7) - detail::tvec4 x_ = floor(j * ns.z); - detail::tvec4 y_ = floor(j - T(7) * x_); // mod(j,N) + detail::tvec4 x_(floor(j * ns.z)); + detail::tvec4 y_(floor(j - T(7) * x_)); // mod(j,N) - detail::tvec4 x = x_ * ns.x + ns.y; - detail::tvec4 y = y_ * ns.x + ns.y; - detail::tvec4 h = T(1) - abs(x) - abs(y); + detail::tvec4 x(x_ * ns.x + ns.y); + detail::tvec4 y(y_ * ns.x + ns.y); + detail::tvec4 h(T(1) - abs(x) - abs(y)); detail::tvec4 b0(x.x, x.y, y.x, y.y); detail::tvec4 b1(x.z, x.w, y.z, y.w); // vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; // vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; - detail::tvec4 s0 = floor(b0) * T(2) + T(1); - detail::tvec4 s1 = floor(b1) * T(2) + T(1); - detail::tvec4 sh = -step(h, detail::tvec4(0.0)); + detail::tvec4 s0(floor(b0) * T(2) + T(1)); + detail::tvec4 s1(floor(b1) * T(2) + T(1)); + detail::tvec4 sh(-step(h, detail::tvec4(0.0))); detail::tvec4 a0 = detail::tvec4(b0.x, b0.z, b0.y, b0.w) + detail::tvec4(s0.x, s0.z, s0.y, s0.w) * detail::tvec4(sh.x, sh.x, sh.y, sh.y); detail::tvec4 a1 = detail::tvec4(b1.x, b1.z, b1.y, b1.w) + detail::tvec4(s1.x, s1.z, s1.y, s1.w) * detail::tvec4(sh.z, sh.z, sh.w, sh.w); From 82ffd4aaf3e8136849427e24626a66a12d23453a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Sep 2011 05:17:30 +0100 Subject: [PATCH 5/7] Added binary operator tests --- test/core/core_type_vec3.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index a7e470e2..fdfc3c8c 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -11,12 +11,35 @@ static 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; + } + + return Error; } int test_vec3_size() From 426082bfbfecb9465eeddaaa3581912dc3f23967 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Sep 2011 05:38:30 +0100 Subject: [PATCH 6/7] Added vec3 operator tests --- test/core/core_type_vec3.cpp | 95 ++++++++++++++++++++++++++++++++++++ test/gtx/gtx_noise.cpp | 6 +-- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index fdfc3c8c..625a7786 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -37,6 +37,101 @@ static int test_vec3_operators() 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; diff --git a/test/gtx/gtx_noise.cpp b/test/gtx/gtx_noise.cpp index c3f46a88..16f3de22 100644 --- a/test/gtx/gtx_noise.cpp +++ b/test/gtx/gtx_noise.cpp @@ -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]; } From 92f0f44a2f287ed59aaf5893e063ac8dc58e26f8 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Sep 2011 05:47:26 +0100 Subject: [PATCH 7/7] Added vec4 operators tests --- test/core/core_type_vec3.cpp | 2 +- test/core/core_type_vec4.cpp | 128 +++++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 6 deletions(-) diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index 625a7786..dd2cb63a 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -9,7 +9,7 @@ #include -static int test_vec3_operators() +int test_vec3_operators() { int Error = 0; diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index 23933b18..fda101d3 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -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()