GLM + STL: operator == missing

I am trying to use GLM vector classes in STL containers. It's okay if I'm not trying to use <algorithm>. Most algorithms rely on an operator ==that is not implemented for GLM classes.

Does anyone know an easy way around this? Without (re) implementing STL algorithms: (

GLM is a great math library that implements GLSL functions in C ++

Update

I just found out that glm actually implements comparison operators in the extension ( here ). But how do I use them in stl?

Update 2

This question has been replaced by the following: how to use the glm == operator in stl algorithms?

+3
source share
3 answers

Many STL algorithms take a functor to compare objects (of course, you need to be especially careful when comparing two vectors containing floating point values ​​for equality).

Example:

To sort a std::list<glm::vec3>(for you, regardless of whether there will be any practical sense in sorting vectors), you can use

std::sort(myVec3List.begin(), myVec3List.end(), MyVec3ComparisonFunc)

with

bool MyVec3ComparisonFunc(const glm::vec3 &vecA, const glm::vec3 &vecB)
{
 return vecA[0]<vecB[0] 
        && vecA[1]<vecB[1] 
        && vecA[2]<vecB[2];
}

So, fortunately, there is no need to change GLM or even reinvent the wheel.

+5
source

You should be able to implement the == operator as a standalone function:

// (Actually more Greg S code than mine.....)

bool operator==(const glm::vec3 &vecA, const glm::vec3 &vecB) 
{ 
   const double epsilion = 0.0001;  // choose something apprpriate.

   return    fabs(vecA[0] -vecB[0]) < epsilion   
          && fabs(vecA[1] -vecB[1]) < epsilion   
          && fabs(vecA[2] -vecB[2]) < epsilion;
} 
+3
source

S .

  • , STL, ,
  • == <, STL, .

, , . operator< glm::vec3, , "" , , - , "" , . , . 3D-, .

, , , . , , , "". , . x, , y z. , (, a.x == b.x, y. , z)

, "" , , , .

. : , .

, , - epsilon, , . epsilon, operator==, .

, operator== - epsilon, epsilons.

, . . , .

+2

Source: https://habr.com/ru/post/1760044/


All Articles