Browse Source

Fixed error: comparing floating point with == or != is unsafe

Groove 7 years ago
parent
commit
2e3fc5da83
3 changed files with 7 additions and 4 deletions
  1. 3 1
      glm/gtx/rotate_vector.hpp
  2. 2 2
      glm/gtx/rotate_vector.inl
  3. 2 1
      test/gtx/gtx_rotate_vector.cpp

+ 3 - 1
glm/gtx/rotate_vector.hpp

@@ -14,8 +14,10 @@
 #pragma once
 #pragma once
 
 
 // Dependency:
 // Dependency:
-#include "../glm.hpp"
 #include "../gtx/transform.hpp"
 #include "../gtx/transform.hpp"
+#include "../gtc/epsilon.hpp"
+#include "../ext/vector_relational.hpp"
+#include "../glm.hpp"
 
 
 #ifndef GLM_ENABLE_EXPERIMENTAL
 #ifndef GLM_ENABLE_EXPERIMENTAL
 #	error "GLM: GLM_GTX_rotate_vector is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
 #	error "GLM: GLM_GTX_rotate_vector is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."

+ 2 - 2
glm/gtx/rotate_vector.inl

@@ -177,8 +177,8 @@ namespace glm
 		vec<3, T, Q> const& Up
 		vec<3, T, Q> const& Up
 	)
 	)
 	{
 	{
-		if(all(equal(Normal, Up)))
-			return mat<4, 4, T, Q>(T(1));
+		if(all(equal(Normal, Up, epsilon<T>())))
+			return mat<4, 4, T, Q>(static_cast<T>(1));
 
 
 		vec<3, T, Q> RotationAxis = cross(Up, Normal);
 		vec<3, T, Q> RotationAxis = cross(Up, Normal);
 		T Angle = acos(dot(Normal, Up));
 		T Angle = acos(dot(Normal, Up));

+ 2 - 1
test/gtx/gtx_rotate_vector.cpp

@@ -1,6 +1,7 @@
 #define GLM_ENABLE_EXPERIMENTAL
 #define GLM_ENABLE_EXPERIMENTAL
-#include <glm/gtc/constants.hpp>
 #include <glm/gtx/rotate_vector.hpp>
 #include <glm/gtx/rotate_vector.hpp>
+#include <glm/gtc/constants.hpp>
+#include <glm/ext/vector_relational.hpp>
 
 
 int test_rotate()
 int test_rotate()
 {
 {