Browse Source

Fixed and tested disk and ball rands

Christophe Riccio 14 years ago
parent
commit
387854dbe3
2 changed files with 35 additions and 3 deletions
  1. 3 3
      glm/gtc/random.inl
  2. 32 0
      test/gtc/gtc_random.cpp

+ 3 - 3
glm/gtc/random.inl

@@ -141,7 +141,7 @@ GLM_FUNC_QUALIFIER detail::tvec4<T> gaussRand
 }
 	
 template <typename T>
-GLM_FUNC_QUALIFIER detail::tvec3<T> diskRand
+GLM_FUNC_QUALIFIER detail::tvec2<T> diskRand
 (
 	T const & Radius
 )
@@ -151,7 +151,7 @@ GLM_FUNC_QUALIFIER detail::tvec3<T> diskRand
 		
 	do
 	{
-		Result = compRand2(-Radius, Radius);
+		Result = linearRand(detail::tvec2<T>(-Radius), detail::tvec2<T>(Radius));
 		LenRadius = length(Result);
 	}
 	while(LenRadius > Radius);
@@ -170,7 +170,7 @@ GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand
 		
 	do
 	{
-		Result = compRand3(-Radius, Radius);
+		Result = linearRand(detail::tvec3<T>(-Radius), detail::tvec3<T>(Radius));
 		LenRadius = length(Result);
 	}
 	while(LenRadius > Radius);

+ 32 - 0
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;
 }