Explorar o código

Add static constants for vec1

- Tests, too
Jesse Talavera-Greenberg %!s(int64=10) %!d(string=hai) anos
pai
achega
b8ff59a61b
Modificáronse 3 ficheiros con 20 adicións e 0 borrados
  1. 2 0
      glm/detail/type_vec1.hpp
  2. 5 0
      glm/detail/type_vec1.inl
  3. 13 0
      test/core/core_type_vec1.cpp

+ 2 - 0
glm/detail/type_vec1.hpp

@@ -59,6 +59,8 @@ namespace glm
 			static GLM_RELAXED_CONSTEXPR precision prec = P;
 #		endif//GLM_META_PROG_HELPERS
 
+		static const type ZERO;
+		static const type X;
 		// -- Data --
 
 #		if GLM_HAS_ANONYMOUS_UNION

+ 5 - 0
glm/detail/type_vec1.inl

@@ -32,6 +32,11 @@
 
 namespace glm
 {
+	template<typename T, precision P>
+	const tvec1<T, P> tvec1<T, P>::X = tvec1<T, P>(static_cast<T>(1));
+
+	template<typename T, precision P>
+	const tvec1<T, P> tvec1<T, P>::ZERO = tvec1<T, P>(static_cast<T>(0));
 	// -- Implicit basic constructors --
 
 #	if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)

+ 13 - 0
test/core/core_type_vec1.cpp

@@ -166,6 +166,18 @@ int test_vec1_operator_increment()
 	return Error;
 }
 
+int test_vec1_static_const() {
+	int Error = 0;
+
+	Error += (glm::vec1(1.0f) == glm::vec1::X) ? 0 : 1;
+	Error += (glm::ivec1(1) == glm::ivec1::X) ? 0 : 1;
+	Error += (glm::dvec1(1.0) == glm::dvec1::X) ? 0 : 1;
+	Error += (glm::bvec1(false) == glm::bvec1::ZERO) ? 0 : 1;
+	Error += (glm::uvec1(0) == glm::uvec1::ZERO) ? 0 : 1;
+
+	return Error;
+}
+
 int main()
 {
 	int Error = 0;
@@ -178,6 +190,7 @@ int main()
 		assert(glm::vec1::components == 1);
 #	endif
 
+	Error += test_vec1_static_const();
 	Error += test_vec1_size();
 	Error += test_vec1_ctor();
 	Error += test_vec1_operators();