Skip to content
Snippets Groups Projects
Commit 09139c8e authored by Stefen Guzik's avatar Stefen Guzik
Browse files

- stores sorted order of vertex addresses

- added Equal, Less, and Hash function objects for MEdge and MEdge*
parent b4de12ef
No related branches found
No related tags found
No related merge requests found
...@@ -20,24 +20,36 @@ ...@@ -20,24 +20,36 @@
// //
// Please report all bugs and problems to <gmsh@geuz.org>. // Please report all bugs and problems to <gmsh@geuz.org>.
#include <functional>
#include "MVertex.h" #include "MVertex.h"
#include "SVector3.h" #include "SVector3.h"
#include "Hash.h"
// A mesh edge. // A mesh edge.
class MEdge { class MEdge {
private: private:
MVertex *_v[2]; MVertex *_v[2];
char _si[2]; // sorted indices
public: public:
MEdge(MVertex *v0, MVertex *v1) MEdge(MVertex *v0, MVertex *v1)
{ {
_v[0] = v0; _v[1] = v1; _v[0] = v0; _v[1] = v1;
if(_v[1] < _v[0]) {
_si[0] = 1;
_si[1] = 0;
}
else {
_si[0] = 0;
_si[1] = 1;
}
} }
inline int getNumVertices() const { return 2; } inline int getNumVertices() const { return 2; }
inline MVertex *getVertex(int i) const { return _v[i]; } inline MVertex *getVertex(const int i) const { return _v[i]; }
inline MVertex *getMinVertex() const { return std::min(_v[0], _v[1]); } inline MVertex *getSortedVertex(const int i) const { return _v[int(_si[i])]; }
inline MVertex *getMaxVertex() const { return std::max(_v[0], _v[1]); } inline MVertex *getMinVertex() const { return _v[int(_si[0])]; }
SVector3 tangent() inline MVertex *getMaxVertex() const { return _v[int(_si[1])]; }
SVector3 tangent() const
{ {
SVector3 t(_v[1]->x() - _v[0]->x(), SVector3 t(_v[1]->x() - _v[0]->x(),
_v[1]->y() - _v[0]->y(), _v[1]->y() - _v[0]->y(),
...@@ -45,7 +57,7 @@ class MEdge { ...@@ -45,7 +57,7 @@ class MEdge {
t.normalize(); t.normalize();
return t; return t;
} }
SPoint3 barycenter() SPoint3 barycenter() const
{ {
return SPoint3(0.5 * (_v[0]->x() + _v[1]->x()), return SPoint3(0.5 * (_v[0]->x() + _v[1]->x()),
0.5 * (_v[0]->y() + _v[1]->y()), 0.5 * (_v[0]->y() + _v[1]->y()),
...@@ -53,4 +65,63 @@ class MEdge { ...@@ -53,4 +65,63 @@ class MEdge {
} }
}; };
//--The following function objects compare the addresses of the mesh vertices.
//--Equal, Less, and a Hash are defined.
struct Equal_Edge : public std::binary_function<MEdge, MEdge, bool> {
bool operator()(const MEdge &e1, const MEdge &e2) const
{
return (e1.getMinVertex() == e2.getMinVertex() &&
e1.getMaxVertex() == e2.getMaxVertex());
}
};
struct Equal_EdgePtr : public std::binary_function<MEdge*, MEdge*, bool> {
bool operator()(const MEdge *const e1, const MEdge *const e2) const
{
return (e1->getMinVertex() == e2->getMinVertex() &&
e1->getMaxVertex() == e2->getMaxVertex());
}
};
struct Less_Edge : public std::binary_function<MEdge, MEdge, bool> {
bool operator()(const MEdge &e1, const MEdge &e2) const
{
if(e1.getMinVertex() < e2.getMinVertex()) return true;
if(e1.getMinVertex() > e2.getMinVertex()) return false;
if(e1.getMaxVertex() < e2.getMaxVertex()) return true;
return false;
}
};
struct Less_EdgePtr : public std::binary_function<MEdge*, MEdge*, bool> {
bool operator()(const MEdge *const e1, const MEdge *const e2) const
{
if(e1->getMinVertex() < e2->getMinVertex()) return true;
if(e1->getMinVertex() > e2->getMinVertex()) return false;
if(e1->getMaxVertex() < e2->getMaxVertex()) return true;
return false;
}
};
struct Hash_Edge : public std::unary_function<MEdge, size_t> {
size_t operator()(const MEdge &e) const
{
const MVertex *v[2];
v[0] = e.getMinVertex();
v[1] = e.getMaxVertex();
return HashFNV1a<sizeof(MVertex*[2])>::eval(v);
}
};
struct Hash_EdgePtr : public std::unary_function<MEdge*, size_t> {
size_t operator()(const MEdge *const e) const
{
const MVertex *v[2];
v[0] = e->getMinVertex();
v[1] = e->getMaxVertex();
return HashFNV1a<sizeof(MVertex*[2])>::eval(v);
}
};
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment