-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEdge.h
69 lines (64 loc) · 3.42 KB
/
Edge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef EDGE_H
#define EDGE_H
#include <QOpenGLFunctions>
struct Edge
{
//-----------------------------------------------------------------------------------------------------
/// @brief Default constructor.
//-----------------------------------------------------------------------------------------------------
Edge() = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default copy constructor.
//-----------------------------------------------------------------------------------------------------
Edge(const Edge&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default copy assignment operator.
//-----------------------------------------------------------------------------------------------------
Edge& operator=(const Edge&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default move constructor.
//-----------------------------------------------------------------------------------------------------
Edge(Edge&&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default move assignment operator.
//-----------------------------------------------------------------------------------------------------
Edge& operator=(Edge&&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default destructor.
//-----------------------------------------------------------------------------------------------------
~Edge() = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Constructor that takes two vertex indices.
/// @param _a is a vertex index representing one of the vertices that contributes to this edge.
/// @param _b is a vertex index representing one of the vertices that contributes to this edge.
//-----------------------------------------------------------------------------------------------------
Edge(const GLushort _a, const GLushort _b) :
p(std::min(_a, _b), std::max(_a, _b))
{}
//-----------------------------------------------------------------------------------------------------
/// @brief Used for hashing.
//-----------------------------------------------------------------------------------------------------
friend bool operator==(const Edge &_a, const Edge &_b)
{
return _a.p == _b.p;
}
//-----------------------------------------------------------------------------------------------------
/// @brief Internally stores a pair, which is sorted on construction.
//-----------------------------------------------------------------------------------------------------
std::pair<GLushort, GLushort> p;
};
//-----------------------------------------------------------------------------------------------------
/// @brief Define the hash struct for this Edge so we can create unordered_set's using it.
//-----------------------------------------------------------------------------------------------------
namespace std
{
template <>
struct hash<Edge>
{
size_t operator()(const Edge &_key) const
{
return std::hash<size_t>()(std::hash<GLushort>()(_key.p.first)) ^ std::hash<GLushort>()(_key.p.second);
}
};
}
#endif // EDGE_H