From 25bd7014b0041c872df4ca9a279cdb7933af83c3 Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Fri, 2 Oct 2015 18:34:17 -0400 Subject: [PATCH] Add static constants for vec3 - Tests, too --- glm/detail/type_vec3.hpp | 9 +++++++++ glm/detail/type_vec3.inl | 24 ++++++++++++++++++++++++ test/core/core_type_vec3.cpp | 16 ++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 98dd74f8..5e497459 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -58,6 +58,15 @@ namespace glm static GLM_RELAXED_CONSTEXPR precision prec = P; # endif//GLM_META_PROG_HELPERS + static const type ZERO; + static const type X; + static const type Y; + static const type Z; + static const type XY; + static const type XZ; + static const type YZ; + static const type XYZ; + // -- Data -- # if GLM_HAS_ANONYMOUS_UNION diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index 1e5081d4..51fbf23c 100644 --- a/glm/detail/type_vec3.inl +++ b/glm/detail/type_vec3.inl @@ -32,6 +32,30 @@ namespace glm { +template +const tvec3 tvec3::ZERO = tvec3(static_cast(0), static_cast(0), static_cast(0)); + +template +const tvec3 tvec3::X = tvec3(static_cast(1), static_cast(0), static_cast(0)); + +template +const tvec3 tvec3::Y = tvec3(static_cast(0), static_cast(1), static_cast(0)); + +template +const tvec3 tvec3::Z = tvec3(static_cast(0), static_cast(0), static_cast(1)); + +template +const tvec3 tvec3::XY = tvec3(static_cast(1), static_cast(1), static_cast(0)); + +template +const tvec3 tvec3::XZ = tvec3(static_cast(1), static_cast(0), static_cast(1)); + +template +const tvec3 tvec3::YZ = tvec3(static_cast(0), static_cast(1), static_cast(1)); + +template +const tvec3 tvec3::XYZ = tvec3(static_cast(1), static_cast(1), static_cast(1)); + // -- Implicit basic constructors -- # if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index 727e90d7..46e3f2d7 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -493,6 +493,21 @@ int test_operator_increment() return Error; } +int test_vec3_static_const() { + int Error(0); + + Error += (glm::ivec3(0, 0, 0) == glm::ivec3::ZERO) ? 0 : 1; + Error += (glm::vec3(1, 0, 0) == glm::vec3::X) ? 0 : 1; + Error += (glm::bvec3(false, true, false) == glm::bvec3::Y) ? 0 : 1; + Error += (glm::bvec3(false, false, true) == glm::bvec3::Z) ? 0 : 1; + Error += (glm::dvec3(1, 1, 0) == glm::dvec3::XY) ? 0 : 1; + Error += (glm::vec3(1, 0, 1) == glm::vec3::XZ) ? 0 : 1; + Error += (glm::uvec3(0u, 1u, 1u) == glm::uvec3::YZ) ? 0 : 1; + Error += (glm::dvec3(1, 1, 1) == glm::dvec3::XYZ) ? 0 : 1; + + return Error; +} + int main() { int Error = 0; @@ -505,6 +520,7 @@ int main() assert(glm::vec3::components == 3); # endif + Error += test_vec3_static_const(); Error += test_vec3_ctor(); Error += test_vec3_operators(); Error += test_vec3_size();