Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_adjacency_predicates.cpp

raw
1 #include "gtest/gtest.h"
2
3 #include "stk_middle_mesh/predicates/adjacency_predicates.hpp"
4
5 namespace stk {
6 namespace middle_mesh {
7 namespace impl {
8
9 TEST(AdjacencyPredicates, any_edge_intersect)
10 {
11 auto mesh = mesh::make_empty_mesh();
12 auto v1 = mesh->create_vertex(0, 0);
13 auto v2 = mesh->create_vertex(2, 0);
14 auto v3 = mesh->create_vertex(2, 2);
15 auto v4 = mesh->create_vertex(0, 2);
16 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
17 mesh::MeshEntityPtr edges1[mesh::MAX_DOWN];
18 mesh::get_downward(el, 1, edges1);
19
20 auto v5 = mesh->create_vertex(1, 1);
21 auto v6 = mesh->create_vertex(1.5, 0.5);
22 auto v7 = mesh->create_vertex(3, 1);
23 auto v8 = mesh->create_vertex(1, 3);
24 auto e1 = mesh->create_edge(v5, v6);
25 auto e2 = mesh->create_edge(v6, v7);
26 mesh->create_edge(v7, v8);
27 auto e4 = mesh->create_edge(v5, v8);
28 mesh->create_quad_from_verts(v5, v6, v7, v8);
29
30 predicates::impl::AdjacencyPredicates preds(mesh);
31
32 EXPECT_EQ(preds.any_edge_intersect(el, e2), edges1[1]);
33 EXPECT_EQ(preds.any_edge_intersect(el, e4), edges1[2]);
34 EXPECT_EQ(preds.any_edge_intersect(el, e1), nullptr);
35 }
36
37 TEST(AdjacencyPredicates, any_edges_intersect)
38 {
39 auto mesh = mesh::make_empty_mesh();
40 auto v1 = mesh->create_vertex(0, 0);
41 auto v2 = mesh->create_vertex(2, 0);
42 auto v3 = mesh->create_vertex(2, 2);
43 auto v4 = mesh->create_vertex(0, 2);
44 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
45
46 auto v5 = mesh->create_vertex(5, 0);
47 auto v6 = mesh->create_vertex(7, 0);
48 auto v7 = mesh->create_vertex(7, 2);
49 auto v8 = mesh->create_vertex(5, 2);
50 auto el1 = mesh->create_quad_from_verts(v5, v6, v7, v8);
51
52 // this it tricky: any_edges_intersect *any* edge of el2 that intersect with
53 // el1, no guarantee which one it is
54 auto v9 = mesh->create_vertex(1, 1);
55 auto v10 = mesh->create_vertex(1.5, 1);
56 auto v11 = mesh->create_vertex(1.5, 3);
57 auto v12 = mesh->create_vertex(1, 3);
58 auto el2 = mesh->create_quad_from_verts(v9, v10, v11, v12);
59 mesh::MeshEntityPtr edges2[mesh::MAX_DOWN];
60 mesh::get_downward(el2, 1, edges2);
61 predicates::impl::AdjacencyPredicates preds(mesh);
62
63 EXPECT_EQ(preds.any_edges_intersect(el, el1), nullptr);
64 auto edgeIntersect = preds.any_edges_intersect(el, el2);
65 EXPECT_TRUE(edgeIntersect == edges2[1] || edgeIntersect == edges2[3]);
66 }
67
68 TEST(AdjacencyPredicates, any_vertices_contained)
69 {
70 auto mesh = mesh::make_empty_mesh();
71 auto v1 = mesh->create_vertex(0, 0);
72 auto v2 = mesh->create_vertex(2, 0);
73 auto v3 = mesh->create_vertex(2, 2);
74 auto v4 = mesh->create_vertex(0, 2);
75 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
76
77 auto v5 = mesh->create_vertex(5, 0);
78 auto v6 = mesh->create_vertex(7, 0);
79 auto v7 = mesh->create_vertex(7, 2);
80 auto v8 = mesh->create_vertex(5, 2);
81 auto el1 = mesh->create_quad_from_verts(v5, v6, v7, v8);
82
83 // this it tricky: any_edges_intersect *any* edge of el2 that intersect with
84 // el1, no guarantee which one it is
85 auto v9 = mesh->create_vertex(1, 1);
86 auto v10 = mesh->create_vertex(3, 1);
87 auto v11 = mesh->create_vertex(3, 3);
88 auto v12 = mesh->create_vertex(1, 3);
89 auto el2 = mesh->create_quad_from_verts(v9, v10, v11, v12);
90 mesh::MeshEntityPtr edges2[mesh::MAX_DOWN];
91 mesh::get_downward(el2, 1, edges2);
92 predicates::impl::AdjacencyPredicates preds(mesh);
93
94 EXPECT_EQ(preds.any_vertices_contained(el, el1), nullptr);
95 EXPECT_EQ(preds.any_vertices_contained(el, el2), v9);
96 }
97
98 TEST(AdjacencyPredicates, is_point_contained)
99 {
100 auto mesh = mesh::make_empty_mesh();
101 auto v1 = mesh->create_vertex(0, 0);
102 auto v2 = mesh->create_vertex(2, 0);
103 auto v3 = mesh->create_vertex(2, 2);
104 auto v4 = mesh->create_vertex(0, 2);
105 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
106 predicates::impl::AdjacencyPredicates preds(mesh);
107
108 auto v5 = utils::Point(1, 1);
109 auto v6 = utils::Point(0, 1);
110 auto v7 = utils::Point(0, 0);
111 auto v8 = utils::Point(1, 3);
112
113 EXPECT_TRUE(preds.is_point_contained(el, v5));
114 EXPECT_TRUE(preds.is_point_contained(el, v6));
115 EXPECT_TRUE(preds.is_point_contained(el, v7));
116 EXPECT_FALSE(preds.is_point_contained(el, v8));
117 }
118
119 } // namespace impl
120 } // namespace middle_mesh
121 } // namespace stk