From 9604a7549fc664ba70b5b4e95e153df48e2403a3 Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Mon, 5 Oct 2015 19:26:30 -0400 Subject: [PATCH] Add IDENTITY and ZERO constants for all matrices - Tests, too --- glm/detail/type_mat2x2.hpp | 4 ++++ glm/detail/type_mat2x2.inl | 7 +++++++ glm/detail/type_mat2x3.hpp | 5 +++++ glm/detail/type_mat2x3.inl | 7 +++++++ glm/detail/type_mat2x4.hpp | 5 +++++ glm/detail/type_mat2x4.inl | 7 +++++++ glm/detail/type_mat3x2.hpp | 5 +++++ glm/detail/type_mat3x2.inl | 7 +++++++ glm/detail/type_mat3x3.hpp | 5 +++++ glm/detail/type_mat3x3.inl | 8 ++++++++ glm/detail/type_mat3x4.hpp | 5 +++++ glm/detail/type_mat3x4.inl | 7 +++++++ glm/detail/type_mat4x2.hpp | 5 +++++ glm/detail/type_mat4x2.inl | 7 +++++++ glm/detail/type_mat4x3.hpp | 5 +++++ glm/detail/type_mat4x3.inl | 7 +++++++ glm/detail/type_mat4x4.hpp | 5 +++++ glm/detail/type_mat4x4.inl | 7 +++++++ test/core/core_type_mat2x2.cpp | 11 +++++++++++ test/core/core_type_mat2x3.cpp | 12 ++++++++++++ test/core/core_type_mat2x4.cpp | 11 +++++++++++ test/core/core_type_mat3x2.cpp | 12 ++++++++++++ test/core/core_type_mat3x3.cpp | 11 +++++++++++ test/core/core_type_mat3x4.cpp | 11 +++++++++++ test/core/core_type_mat4x2.cpp | 11 +++++++++++ test/core/core_type_mat4x3.cpp | 11 +++++++++++ test/core/core_type_mat4x4.cpp | 11 +++++++++++ 27 files changed, 209 insertions(+) diff --git a/glm/detail/type_mat2x2.hpp b/glm/detail/type_mat2x2.hpp index 13840689..78faf314 100644 --- a/glm/detail/type_mat2x2.hpp +++ b/glm/detail/type_mat2x2.hpp @@ -61,6 +61,10 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif private: col_type value[2]; diff --git a/glm/detail/type_mat2x2.inl b/glm/detail/type_mat2x2.inl index 202839f4..b7f09d7d 100644 --- a/glm/detail/type_mat2x2.inl +++ b/glm/detail/type_mat2x2.inl @@ -50,6 +50,13 @@ namespace detail } }//namespace detail +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat2x2 tmat2x2::ZERO(static_cast(0)); + + template + const tmat2x2 tmat2x2::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat2x3.hpp b/glm/detail/type_mat2x3.hpp index 755c7cb9..0477c0f9 100644 --- a/glm/detail/type_mat2x3.hpp +++ b/glm/detail/type_mat2x3.hpp @@ -57,6 +57,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + private: col_type value[2]; diff --git a/glm/detail/type_mat2x3.inl b/glm/detail/type_mat2x3.inl index 267f0c0c..23018c19 100644 --- a/glm/detail/type_mat2x3.inl +++ b/glm/detail/type_mat2x3.inl @@ -32,6 +32,13 @@ namespace glm { +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat2x3 tmat2x3::ZERO(static_cast(0)); + + template + const tmat2x3 tmat2x3::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat2x4.hpp b/glm/detail/type_mat2x4.hpp index 4cba2cb8..36840f12 100644 --- a/glm/detail/type_mat2x4.hpp +++ b/glm/detail/type_mat2x4.hpp @@ -57,6 +57,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + private: col_type value[2]; diff --git a/glm/detail/type_mat2x4.inl b/glm/detail/type_mat2x4.inl index 766640e4..ebb9170c 100644 --- a/glm/detail/type_mat2x4.inl +++ b/glm/detail/type_mat2x4.inl @@ -32,6 +32,13 @@ namespace glm { +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat2x4 tmat2x4::ZERO(static_cast(0)); + + template + const tmat2x4 tmat2x4::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat3x2.hpp b/glm/detail/type_mat3x2.hpp index 52890f19..06549837 100644 --- a/glm/detail/type_mat3x2.hpp +++ b/glm/detail/type_mat3x2.hpp @@ -57,6 +57,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + private: col_type value[3]; diff --git a/glm/detail/type_mat3x2.inl b/glm/detail/type_mat3x2.inl index d112a054..7e3ff4be 100644 --- a/glm/detail/type_mat3x2.inl +++ b/glm/detail/type_mat3x2.inl @@ -32,6 +32,13 @@ namespace glm { +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat3x2 tmat3x2::ZERO(static_cast(0)); + + template + const tmat3x2 tmat3x2::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat3x3.hpp b/glm/detail/type_mat3x3.hpp index 58b2e7fe..4ef3708d 100644 --- a/glm/detail/type_mat3x3.hpp +++ b/glm/detail/type_mat3x3.hpp @@ -56,6 +56,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + template friend tvec3 operator/(tmat3x3 const & m, tvec3 const & v); template diff --git a/glm/detail/type_mat3x3.inl b/glm/detail/type_mat3x3.inl index 6f936036..ec6f3eb6 100644 --- a/glm/detail/type_mat3x3.inl +++ b/glm/detail/type_mat3x3.inl @@ -56,6 +56,14 @@ namespace detail } }//namespace detail +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat3x3 tmat3x3::ZERO(static_cast(0)); + + template + const tmat3x3 tmat3x3::IDENTITY(static_cast(1)); +# endif + // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat3x4.hpp b/glm/detail/type_mat3x4.hpp index 4bf6ab18..f9c7b908 100644 --- a/glm/detail/type_mat3x4.hpp +++ b/glm/detail/type_mat3x4.hpp @@ -57,6 +57,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + private: col_type value[3]; diff --git a/glm/detail/type_mat3x4.inl b/glm/detail/type_mat3x4.inl index 8862df47..16ff84d3 100644 --- a/glm/detail/type_mat3x4.inl +++ b/glm/detail/type_mat3x4.inl @@ -32,6 +32,13 @@ namespace glm { +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat3x4 tmat3x4::ZERO(static_cast(0)); + + template + const tmat3x4 tmat3x4::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat4x2.hpp b/glm/detail/type_mat4x2.hpp index 5c050e26..b3c27261 100644 --- a/glm/detail/type_mat4x2.hpp +++ b/glm/detail/type_mat4x2.hpp @@ -57,6 +57,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + private: col_type value[4]; diff --git a/glm/detail/type_mat4x2.inl b/glm/detail/type_mat4x2.inl index d012b884..187b4579 100644 --- a/glm/detail/type_mat4x2.inl +++ b/glm/detail/type_mat4x2.inl @@ -32,6 +32,13 @@ namespace glm { +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat4x2 tmat4x2::ZERO(static_cast(0)); + + template + const tmat4x2 tmat4x2::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat4x3.hpp b/glm/detail/type_mat4x3.hpp index 74b8364b..7a870a86 100644 --- a/glm/detail/type_mat4x3.hpp +++ b/glm/detail/type_mat4x3.hpp @@ -57,6 +57,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + private: col_type value[4]; diff --git a/glm/detail/type_mat4x3.inl b/glm/detail/type_mat4x3.inl index e7368619..da76cdcc 100644 --- a/glm/detail/type_mat4x3.inl +++ b/glm/detail/type_mat4x3.inl @@ -32,6 +32,13 @@ namespace glm { +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat4x3 tmat4x3::ZERO(static_cast(0)); + + template + const tmat4x3 tmat4x3::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/glm/detail/type_mat4x4.hpp b/glm/detail/type_mat4x4.hpp index e00b3ac3..fa585e5b 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -56,6 +56,11 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS +# ifdef GLM_STATIC_CONST_MEMBERS + static const type ZERO; + static const type IDENTITY; +# endif + template friend tvec4 operator/(tmat4x4 const & m, tvec4 const & v); template diff --git a/glm/detail/type_mat4x4.inl b/glm/detail/type_mat4x4.inl index c075122b..1d463836 100644 --- a/glm/detail/type_mat4x4.inl +++ b/glm/detail/type_mat4x4.inl @@ -92,6 +92,13 @@ namespace detail } }//namespace detail +# ifdef GLM_STATIC_CONST_MEMBERS + template + const tmat4x4 tmat4x4::ZERO(static_cast(0)); + + template + const tmat4x4 tmat4x4::IDENTITY(static_cast(1)); +# endif // -- Constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/test/core/core_type_mat2x2.cpp b/test/core/core_type_mat2x2.cpp index a682640b..9e36e54d 100644 --- a/test/core/core_type_mat2x2.cpp +++ b/test/core/core_type_mat2x2.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -86,6 +87,15 @@ int test_inverse() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat2x2(1) == glm::mat2x2::IDENTITY ? 0 : 1; + Error += glm::mat2x2(0) == glm::mat2x2::ZERO ? 0 : 1; + + return Error; +} + int test_ctr() { int Error(0); @@ -173,6 +183,7 @@ int main() #endif Error += cast::test(); + Error += test_static_const(); Error += test_ctr(); Error += test_operators(); Error += test_inverse(); diff --git a/test/core/core_type_mat2x3.cpp b/test/core/core_type_mat2x3.cpp index 59b06be0..34e2d9a8 100644 --- a/test/core/core_type_mat2x3.cpp +++ b/test/core/core_type_mat2x3.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -102,6 +103,16 @@ int test_ctr() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat2x3(1) == glm::mat2x3::IDENTITY ? 0 : 1; + Error += glm::mat2x3(0) == glm::mat2x3::ZERO ? 0 : 1; + + return Error; +} + + namespace cast { template @@ -147,6 +158,7 @@ int main() #endif Error += cast::test(); + Error += test_static_const(); Error += test_ctr(); Error += test_operators(); diff --git a/test/core/core_type_mat2x4.cpp b/test/core/core_type_mat2x4.cpp index f6f706cf..9ad9a47c 100644 --- a/test/core/core_type_mat2x4.cpp +++ b/test/core/core_type_mat2x4.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -98,6 +99,15 @@ int test_ctr() }; #endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +int test_static_const() { + int Error(0); + + Error += glm::mat2x4(1) == glm::mat2x4::IDENTITY ? 0 : 1; + Error += glm::mat2x4(0) == glm::mat2x4::ZERO ? 0 : 1; return Error; } @@ -147,6 +157,7 @@ int main() #endif Error += cast::test(); + Error += test_static_const(); Error += test_ctr(); Error += test_operators(); diff --git a/test/core/core_type_mat3x2.cpp b/test/core/core_type_mat3x2.cpp index b6611d23..e68c2638 100644 --- a/test/core/core_type_mat3x2.cpp +++ b/test/core/core_type_mat3x2.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -106,6 +107,16 @@ int test_ctr() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat3x2(1) == glm::mat3x2::IDENTITY ? 0 : 1; + Error += glm::mat3x2(0) == glm::mat3x2::ZERO ? 0 : 1; + + return Error; +} + + namespace cast { template @@ -152,6 +163,7 @@ int main() Error += cast::test(); Error += test_ctr(); + Error += test_static_const(); Error += test_operators(); return Error; diff --git a/test/core/core_type_mat3x3.cpp b/test/core/core_type_mat3x3.cpp index 89ec2be8..f9ece80f 100644 --- a/test/core/core_type_mat3x3.cpp +++ b/test/core/core_type_mat3x3.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -165,6 +166,15 @@ int test_ctr() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat3x3(1) == glm::mat3x3::IDENTITY ? 0 : 1; + Error += glm::mat3x3(0) == glm::mat3x3::ZERO ? 0 : 1; + + return Error; +} + namespace cast { template @@ -210,6 +220,7 @@ int main() #endif Error += cast::test(); + Error += test_static_const(); Error += test_ctr(); Error += test_mat3x3(); Error += test_operators(); diff --git a/test/core/core_type_mat3x4.cpp b/test/core/core_type_mat3x4.cpp index a76bb21e..bde2e89d 100644 --- a/test/core/core_type_mat3x4.cpp +++ b/test/core/core_type_mat3x4.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -106,6 +107,15 @@ int test_ctr() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat3x4(1) == glm::mat3x4::IDENTITY ? 0 : 1; + Error += glm::mat3x4(0) == glm::mat3x4::ZERO ? 0 : 1; + + return Error; +} + namespace cast { template @@ -151,6 +161,7 @@ int main() #endif Error += cast::test(); + Error += test_static_const(); Error += test_ctr(); Error += test_operators(); diff --git a/test/core/core_type_mat4x2.cpp b/test/core/core_type_mat4x2.cpp index 3b38e6d2..78cd9170 100644 --- a/test/core/core_type_mat4x2.cpp +++ b/test/core/core_type_mat4x2.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -110,6 +111,15 @@ int test_ctr() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat4x2(1) == glm::mat4x2::IDENTITY ? 0 : 1; + Error += glm::mat4x2(0) == glm::mat4x2::ZERO ? 0 : 1; + + return Error; +} + namespace cast { template @@ -155,6 +165,7 @@ int main() #endif Error += cast::test(); + Error += test_static_const(); Error += test_ctr(); Error += test_operators(); diff --git a/test/core/core_type_mat4x3.cpp b/test/core/core_type_mat4x3.cpp index 8a7e0542..677fcf03 100644 --- a/test/core/core_type_mat4x3.cpp +++ b/test/core/core_type_mat4x3.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #include #include #include @@ -110,6 +111,15 @@ int test_ctr() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat4x3(1) == glm::mat4x3::IDENTITY ? 0 : 1; + Error += glm::mat4x3(0) == glm::mat4x3::ZERO ? 0 : 1; + + return Error; +} + namespace cast { template @@ -155,6 +165,7 @@ int main() #endif Error += cast::test(); + Error += test_static_const(); Error += test_ctr(); Error += test_operators(); diff --git a/test/core/core_type_mat4x4.cpp b/test/core/core_type_mat4x4.cpp index 6b7b36e3..f3fa5aaf 100644 --- a/test/core/core_type_mat4x4.cpp +++ b/test/core/core_type_mat4x4.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_STATIC_CONST_MEMBERS #define GLM_SIMD #include #include @@ -283,6 +284,15 @@ int perf_mul() return Error; } +int test_static_const() { + int Error(0); + + Error += glm::mat4x4(1) == glm::mat4x4::IDENTITY ? 0 : 1; + Error += glm::mat4x4(0) == glm::mat4x4::ZERO ? 0 : 1; + + return Error; +} + namespace cast { template @@ -339,6 +349,7 @@ int main() Error += cast::test(); Error += test_ctr(); + Error += test_static_const(); Error += test_inverse_dmat4x4(); Error += test_inverse_mat4x4(); Error += test_operators();