diff --git a/glm/gtc/round.inl b/glm/gtc/round.inl index 255dec66..94fdd54b 100644 --- a/glm/gtc/round.inl +++ b/glm/gtc/round.inl @@ -104,10 +104,7 @@ namespace detail GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple) { if(Source > genType(0)) - { - genType Tmp = Source - genType(1); - return Tmp + (Multiple - std::fmod(Tmp, Multiple)); - } + return Source + (Multiple - std::fmod(Source, Multiple)); else return Source + std::fmod(-Source, Multiple); } @@ -152,10 +149,7 @@ namespace detail if(Source >= genType(0)) return Source - std::fmod(Source, Multiple); else - { - genType Tmp = Source + genType(1); - return Tmp - std::fmod(Tmp, Multiple) - Multiple; - } + return Source - std::fmod(Source, Multiple) - Multiple; } }; diff --git a/glm/gtx/component_wise.hpp b/glm/gtx/component_wise.hpp index acc2adc6..4f90c4ff 100644 --- a/glm/gtx/component_wise.hpp +++ b/glm/gtx/component_wise.hpp @@ -60,7 +60,10 @@ namespace glm template class vecType> GLM_FUNC_DECL vecType compNormalize(vecType const & v); - template class vecType> + /// Convert a normalized float vector to an integer vector. + /// If the parameter value type is already a floating precision type, the value is passed through. + /// @see gtx_component_wise + template class vecType> GLM_FUNC_DECL vecType compScale(vecType const & v); /// Add all vector components together. diff --git a/glm/gtx/component_wise.inl b/glm/gtx/component_wise.inl index b091c9e1..4c380b7a 100644 --- a/glm/gtx/component_wise.inl +++ b/glm/gtx/component_wise.inl @@ -113,7 +113,7 @@ namespace detail template class vecType> GLM_FUNC_QUALIFIER vecType compScale(vecType const & v) { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'compNormalize' accepts only floating-point types for 'floatType' template parameter"); + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'compScale' accepts only floating-point types for 'floatType' template parameter"); return detail::compute_compScale::is_integer, std::numeric_limits::is_signed>::call(v); } diff --git a/readme.md b/readme.md index 40faa2de..5c9ba555 100644 --- a/readme.md +++ b/readme.md @@ -53,7 +53,10 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.7.2](https://github.com/g-truc/glm/releases/latest) - 2015-XX-XX ##### Improvements: -- Added compNormalize function to GTX_component_wise +- Added compNormalize and compScale functions to GTX_component_wise + +##### Fixes: +- Fixed GTC_round floorMultiple/ceilMultiple #412 #### [GLM 0.9.7.1](https://github.com/g-truc/glm/releases/tag/0.9.7.1) - 2015-09-07 ##### Improvements: diff --git a/test/gtc/gtc_round.cpp b/test/gtc/gtc_round.cpp index 1162d00f..aa6cf1a1 100644 --- a/test/gtc/gtc_round.cpp +++ b/test/gtc/gtc_round.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -293,6 +294,86 @@ namespace ceilPowerOfTwo } }//namespace ceilPowerOfTwo +namespace floorMultiple +{ + template + struct type + { + genType Source; + genType Multiple; + genType Return; + genType Epsilon; + }; + + int test_float() + { + type const Data[] = + { + {3.4, 0.3, 3.3, 0.0001}, + {-1.4, 0.3, -1.5, 0.0001}, + }; + + int Error(0); + + for(std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) + { + glm::float64 Result = glm::floorMultiple(Data[i].Source, Data[i].Multiple); + Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1; + } + + return Error; + } + + int test() + { + int Error(0); + + Error += test_float(); + + return Error; + } +}//namespace floorMultiple + +namespace ceilMultiple +{ + template + struct type + { + genType Source; + genType Multiple; + genType Return; + genType Epsilon; + }; + + int test_float() + { + type const Data[] = + { + {3.4, 0.3, 3.6, 0.0001}, + {-1.4, 0.3, -1.2, 0.0001}, + }; + + int Error(0); + + for(std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) + { + glm::float64 Result = glm::ceilMultiple(Data[i].Source, Data[i].Multiple); + Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1; + } + + return Error; + } + + int test() + { + int Error(0); + + Error += test_float(); + + return Error; + } +}//namespace ceilMultiple + int main() { int Error(0); @@ -304,5 +385,8 @@ int main() Error += ceilPowerOfTwo::perf(); # endif//NDEBUG + Error += floorMultiple::test(); + Error += ceilMultiple::test(); + return Error; }