Enmesh
Loading...
Searching...
No Matches
quad.h
1#ifndef QUAD_H
2#define QUAD_H
3
4#include <vector>
5#include <array>
6#include <iostream>
7#include <cmath>
8#include <unordered_set>
9#include <unordered_map>
10#include <fstream>
11#include <sstream>
12#include <string>
13#include <algorithm>
14
15
16#include "geometry/point.h"
17#include "geometry/edge.h"
18
19namespace Enmesh {
20
25struct Quad {
26
27 static constexpr size_t elementType = 3;
28 static constexpr size_t numVertices = 4;
29
30 std::array<size_t, 4> v;
31
32
38 bool containsEdge(size_t v1, size_t v2) const;
39
40
47 bool operator==(const Quad& other) const {
48 std::array<size_t, 4> sortedV1 = v;
49 std::array<size_t, 4> sortedV2 = other.v;
50 std::sort(sortedV1.begin(), sortedV1.end());
51 std::sort(sortedV2.begin(), sortedV2.end());
52 return sortedV1 == sortedV2;
53 }
54
55};
56
57
59struct QuadHash {
60 size_t operator()(const Quad& quad) const {
61 // Combine the hashes of the four vertex indices to create a unique hash for the quad
62 size_t h = std::hash<size_t>{}(quad.v[0]);
63 h ^= std::hash<size_t>{}(quad.v[1]) + 0x9e3779b9 + (h << 6) + (h >> 2); // Combine with the second vertex index
64 h ^= std::hash<size_t>{}(quad.v[2]) + 0x9e3779b9 + (h << 6) + (h >> 2); // Combine with the third vertex index
65 h ^= std::hash<size_t>{}(quad.v[3]) + 0x9e3779b9 + (h << 6) + (h >> 2); // Combine with the fourth vertex index
66 return h;
67 }
68};
69
70} // namespace Enmesh
71
72#endif
A hash function for quads.
Definition quad.h:59
A struct representing a quad in the mesh.
Definition quad.h:25
static constexpr size_t numVertices
Number of vertices in a quad.
Definition quad.h:28
static constexpr size_t elementType
Gmsh element type for quads.
Definition quad.h:27
bool containsEdge(size_t v1, size_t v2) const
Check if the circum circle of the quad contains a specific edge defined by two vertex indices.
Definition quad.cpp:5
std::array< size_t, 4 > v
Indices of the vertices that form the quad.
Definition quad.h:30
bool operator==(const Quad &other) const
Overload the == operator to compare two quads based on their vertex indices.
Definition quad.h:47