CDT++
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Vertex_test.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Causal Dynamical Triangulations in C++ using CGAL
3
4 Copyright © 2017 Adam Getchell
5 ******************************************************************************/
6
11
12#include <doctest/doctest.h>
13
14#include <algorithm>
15#include <numbers>
16
17#include "Manifold.hpp"
18
19using namespace manifolds;
20
21static inline auto constexpr RADIUS_2 = 2.0 * std::numbers::inv_sqrt3_v<double>;
22
23SCENARIO("Point operations" * doctest::test_suite("vertex"))
24{
25 using Point = Point_t<3>;
26 GIVEN("Some points.")
27 {
28 auto const point_1 = Point(0, 0, 0);
29 auto const point_2 = Point(0, 0.0, 0.0);
30 auto const point_3 = Point(1, 1, 1);
31 WHEN("They are compared.")
32 {
33 THEN("Similar points are equal.") { REQUIRE_EQ(point_1, point_2); }
34 THEN("Dissimilar points are not equal.") { REQUIRE_NE(point_1, point_3); }
35 }
36 }
37}
38
39SCENARIO("Vertex operations" * doctest::test_suite("vertex"))
40{
41 using Causal_vertices = Causal_vertices_t<3>;
42 using Manifold = Manifold_3;
43 using Point = Point_t<3>;
44 GIVEN("A foliated Delaunay triangulation.")
45 {
46 Causal_vertices causal_vertices;
47 WHEN("A vertex is inserted.")
48 {
49 causal_vertices.emplace_back(Point(0, 0, 0), 1);
50 Manifold const manifold(causal_vertices, 0, 1);
51 THEN("The vertex is in the manifold.")
52 {
53 // auto vertex = manifold.get_vertices();
54 auto vertex = manifold.get_vertices_span();
55 REQUIRE(manifold.is_vertex(vertex.front()));
56 }
57
58 THEN("The Delaunay triangulation is valid.")
59 {
60 REQUIRE(manifold.is_valid());
61 }
62
63 THEN("There is 1 vertex.") { REQUIRE_EQ(manifold.N0(), 1); }
64
65 THEN("There are no edges.") { REQUIRE_EQ(manifold.N1(), 0); }
66
67 THEN("A 1 vertex manifold has dimension 0.")
68 {
69 REQUIRE_EQ(manifold.dimensionality(), 0);
70 }
71
72 THEN("The vertex is valid.")
73 {
74 fmt::print("When a causal vertex is inserted, the vertices are:\n");
75 manifold.print_vertices();
76 CHECK(manifold.get_triangulation().check_all_vertices());
77 }
78 }
79
80 AND_WHEN("Two vertices are inserted.")
81 {
82 causal_vertices.emplace_back(Point(0, 0, 0), 1);
83 causal_vertices.emplace_back(Point(1, 0, 0), 2);
84 Manifold const manifold(causal_vertices, 0, 1);
85
86 THEN("The vertices are in the manifold.")
87 {
88 auto vertex = manifold.get_vertices_span();
89 REQUIRE(manifold.is_vertex(vertex.front()));
90 REQUIRE(manifold.is_vertex(vertex.back()));
91 }
92
93 THEN("The Delaunay triangulation is valid.")
94 {
95 REQUIRE(manifold.is_valid());
96 }
97
98 THEN("There are 2 vertices.") { REQUIRE_EQ(manifold.N0(), 2); }
99
100 THEN("There is 1 edge.") { REQUIRE_EQ(manifold.N1(), 1); }
101
102 THEN("There are no faces.") { REQUIRE_EQ(manifold.N2(), 0); }
103
104 THEN("A 2 vertex manifold has dimension 1.")
105 {
106 REQUIRE_EQ(manifold.dimensionality(), 1);
107 }
108
109 THEN("The vertices are valid.")
110 {
111 fmt::print("When 2 causal vertices are inserted, the vertices are:\n");
112 manifold.print_vertices();
113 CHECK(manifold.get_triangulation().check_all_vertices());
114 }
115 }
116
117 AND_WHEN("Three vertices are inserted.")
118 {
119 causal_vertices.emplace_back(Point(0, 0, 0), 1);
120 causal_vertices.emplace_back(Point(1, 0, 0), 2);
121 causal_vertices.emplace_back(Point(0, 1, 0), 2);
122 Manifold manifold(causal_vertices, 0, 1);
123
124 THEN("The vertices are in the manifold.")
125 {
126 auto vertices = manifold.get_vertices_span();
127 auto require = [&manifold](auto& vertex) {
128 REQUIRE(manifold.is_vertex(vertex));
129 };
130 std::ranges::for_each(vertices, require);
131 }
132
133 THEN("The Delaunay triangulation is valid.")
134 {
135 REQUIRE(manifold.is_valid());
136 }
137
138 THEN("There are 3 vertices.") { REQUIRE_EQ(manifold.N0(), 3); }
139
140 THEN("There are 3 edges.") { REQUIRE_EQ(manifold.N1(), 3); }
141
142 THEN("There is 1 face.") { REQUIRE_EQ(manifold.N2(), 1); }
143
144 THEN("There are no simplices.") { REQUIRE_EQ(manifold.N3(), 0); }
145
146 THEN("A 3 vertex manifold has dimension 2.")
147 {
148 REQUIRE_EQ(manifold.dimensionality(), 2);
149 }
150
151 THEN("The vertices are valid.")
152 {
153 fmt::print("When 3 causal vertices are inserted, the vertices are:\n");
154 manifold.print_vertices();
155 CHECK(manifold.get_triangulation().check_all_vertices());
156 }
157 }
158
159 AND_WHEN("Four vertices are inserted.")
160 {
161 causal_vertices.emplace_back(Point(0, 0, 0), 1);
162 causal_vertices.emplace_back(Point(1, 0, 0), 2);
163 causal_vertices.emplace_back(Point(0, 1, 0), 2);
164 causal_vertices.emplace_back(Point(0, 0, 1), 2);
165 Manifold manifold(causal_vertices, 0, 1);
166
167 THEN("The vertices are in the manifold.")
168 {
169 auto vertices = manifold.get_vertices_span();
170 auto require = [&manifold](auto& vertex) {
171 REQUIRE(manifold.is_vertex(vertex));
172 };
173 std::ranges::for_each(vertices, require);
174 }
175
176 THEN("The Delaunay triangulation is valid.")
177 {
178 REQUIRE(manifold.is_valid());
179 }
180
181 THEN("There are 4 vertices.") { REQUIRE_EQ(manifold.N0(), 4); }
182
183 THEN("There are 6 edges.") { REQUIRE_EQ(manifold.N1(), 6); }
184
185 THEN("There are 4 faces.") { REQUIRE_EQ(manifold.N2(), 4); }
186
187 THEN("There is a simplex.") { REQUIRE_EQ(manifold.N3(), 1); }
188
189 THEN("A 4 vertex manifold has dimension 3.")
190 {
191 REQUIRE_EQ(manifold.dimensionality(), 3);
192 }
193
194 THEN("The vertices are valid.")
195 {
196 fmt::print(
197 "When 4 causal vertices are inserted, there is a simplex:\n");
198 manifold.print_cells();
199 CHECK(manifold.get_triangulation().check_all_vertices());
200 }
201 }
202
203 AND_WHEN("Five vertices are inserted.")
204 {
205 causal_vertices.emplace_back(Point(0, 0, 0), 1);
206 causal_vertices.emplace_back(Point(1, 0, 0), 2);
207 causal_vertices.emplace_back(Point(0, 1, 0), 2);
208 causal_vertices.emplace_back(Point(0, 0, 1), 2);
209 causal_vertices.emplace_back(Point(RADIUS_2, RADIUS_2, RADIUS_2), 3);
210 Manifold manifold(causal_vertices, 0, 1);
211
212 THEN("The vertices are in the manifold.")
213 {
214 auto vertices = manifold.get_vertices_span();
215 auto require = [&manifold](auto& vertex_candidate) {
216 REQUIRE(manifold.is_vertex(vertex_candidate));
217 };
218 std::ranges::for_each(vertices, require);
219 }
220
221 THEN("The Delaunay triangulation is valid.")
222 {
223 REQUIRE(manifold.is_valid());
224 }
225
226 THEN("There are 5 vertices.") { REQUIRE_EQ(manifold.N0(), 5); }
227
228 THEN("There are 9 edges.") { REQUIRE_EQ(manifold.N1(), 9); }
229
230 THEN("There are 7 faces.") { REQUIRE_EQ(manifold.N2(), 7); }
231
232 THEN("There are 2 simplexes.") { REQUIRE_EQ(manifold.N3(), 2); }
233
234 THEN("A 5 vertex manifold still has dimension 3.")
235 {
236 REQUIRE_EQ(manifold.dimensionality(), 3);
237 }
238
239 THEN("The vertices are valid.")
240 {
241 fmt::print(
242 "When 5 causal vertices are inserted, there are 2 simplices:\n");
243 manifold.print_cells();
244 CHECK(manifold.get_triangulation().check_all_vertices());
245 }
246 }
247 }
248}
Data structures for manifolds.
SCENARIO("Perform bistellar flip on Delaunay triangulation" *doctest::test_suite("bistellar"))