g-truc / glm

OpenGL Mathematics (GLM)
https://glm.g-truc.net
Other
9.1k stars 2.12k forks source link

epsilon not declared in color_space.inl #1233

Closed chrismile closed 7 months ago

chrismile commented 7 months ago

When including color_space.hpp, I get the following errors:

In file included from ../src/../glm/include/glm/gtx/color_space.hpp:70,
                 from ../src/Main.cpp:5:
../src/../glm/include/glm/gtx/color_space.inl: In function ‘glm::vec<3, T, Q> glm::rgbColor(const glm::vec<3, T, Q>&)’:
../src/../glm/include/glm/gtx/color_space.inl:13:52: error: ‘epsilon’ was not declared in this scope
   13 |                 if(equal(hsv.y, static_cast<T>(0), epsilon<T>()))
      |                                                    ^~~~~~~
../src/../glm/include/glm/gtx/color_space.inl:13:61: error: expected primary-expression before ‘>’ token
   13 |                 if(equal(hsv.y, static_cast<T>(0), epsilon<T>()))
      |                                                             ^
../src/../glm/include/glm/gtx/color_space.inl:13:63: error: expected primary-expression before ‘)’ token
   13 |                 if(equal(hsv.y, static_cast<T>(0), epsilon<T>()))
      |                                                               ^
../src/../glm/include/glm/gtx/color_space.inl: In function ‘glm::vec<3, T, Q> glm::hsvColor(const glm::vec<3, T, Q>&)’:
../src/../glm/include/glm/gtx/color_space.inl:74:51: error: ‘epsilon’ was not declared in this scope
   74 |                 if(!equal(Max, static_cast<T>(0), epsilon<T>()))
      |                                                   ^~~~~~~
../src/../glm/include/glm/gtx/color_space.inl:74:60: error: expected primary-expression before ‘>’ token
   74 |                 if(!equal(Max, static_cast<T>(0), epsilon<T>()))
      |                                                            ^
../src/../glm/include/glm/gtx/color_space.inl:74:62: error: expected primary-expression before ‘)’ token
   74 |                 if(!equal(Max, static_cast<T>(0), epsilon<T>()))
      |                                                              ^
../src/../glm/include/glm/gtx/color_space.inl:79:60: error: expected primary-expression before ‘>’ token
   79 |                         if(equal(rgbColor.r, Max, epsilon<T>()))
      |                                                            ^
../src/../glm/include/glm/gtx/color_space.inl:79:62: error: expected primary-expression before ‘)’ token
   79 |                         if(equal(rgbColor.r, Max, epsilon<T>()))
      |                                                              ^
../src/../glm/include/glm/gtx/color_space.inl:82:65: error: expected primary-expression before ‘>’ token
   82 |                         else if(equal(rgbColor.g, Max, epsilon<T>()))
      |                                                                 ^
../src/../glm/include/glm/gtx/color_space.inl:82:67: error: expected primary-expression before ‘)’ token
   82 |                         else if(equal(rgbColor.g, Max, epsilon<T>()))
      |                                                                   ^

There's probably an include missing to glm/gtc/epsilon.hpp.

EDIT: Even including glm/gtc/epsilon.hpp beforehand seems to be insufficient. Is epsilon in a different namespace?

chrismile commented 7 months ago

This bug seems to have been introduced by https://github.com/g-truc/glm/commit/f86092a658ad19bdc3e5a121d18785a582c9a56f.

gottfriedleibniz commented 7 months ago

In most cases ext/scalar_constants.hpp is indirectly included. For instance, gtx/matrix_decompose.hpp -> gtc/quaternion.hpp -> gtc/constants.hpp -> ext/scalar_constants.hpp. Unfortunately that is not true with gtx/color_space.hpp's case and the closest example would be to follow gtx/matrix_interpolation.inl.

Those epsilon changes were to compensate -Weverything enabling -Wfloat-equal. In this case it may have been better to abstract this a little e.g., detail::equal or detail::approx(?). This would be inline with C++-14's introduction of std::equal_to which prevents Wfloat-equal (and the likes) from firing.