From 695b058096ec9175d0ed417a054deb6c5b2aacfa Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 24 Sep 2011 23:36:42 +0100 Subject: [PATCH] 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; }