12#include <doctest/doctest.h>
19using namespace manifolds;
21static inline auto constexpr RADIUS_2 = 2.0 * std::numbers::inv_sqrt3_v<double>;
23SCENARIO(
"Point operations" * doctest::test_suite(
"vertex"))
25 using Point = Point_t<3>;
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.")
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); }
39SCENARIO(
"Vertex operations" * doctest::test_suite(
"vertex"))
41 using Causal_vertices = Causal_vertices_t<3>;
43 using Point = Point_t<3>;
44 GIVEN(
"A foliated Delaunay triangulation.")
46 Causal_vertices causal_vertices;
47 WHEN(
"A vertex is inserted.")
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.")
54 auto vertex = manifold.get_vertices_span();
55 REQUIRE(manifold.is_vertex(vertex.front()));
58 THEN(
"The Delaunay triangulation is valid.")
60 REQUIRE(manifold.is_valid());
63 THEN(
"There is 1 vertex.") { REQUIRE_EQ(manifold.N0(), 1); }
65 THEN(
"There are no edges.") { REQUIRE_EQ(manifold.N1(), 0); }
67 THEN(
"A 1 vertex manifold has dimension 0.")
69 REQUIRE_EQ(manifold.dimensionality(), 0);
72 THEN(
"The vertex is valid.")
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());
80 AND_WHEN(
"Two vertices are inserted.")
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);
86 THEN(
"The vertices are in the manifold.")
88 auto vertex = manifold.get_vertices_span();
89 REQUIRE(manifold.is_vertex(vertex.front()));
90 REQUIRE(manifold.is_vertex(vertex.back()));
93 THEN(
"The Delaunay triangulation is valid.")
95 REQUIRE(manifold.is_valid());
98 THEN(
"There are 2 vertices.") { REQUIRE_EQ(manifold.N0(), 2); }
100 THEN(
"There is 1 edge.") { REQUIRE_EQ(manifold.N1(), 1); }
102 THEN(
"There are no faces.") { REQUIRE_EQ(manifold.N2(), 0); }
104 THEN(
"A 2 vertex manifold has dimension 1.")
106 REQUIRE_EQ(manifold.dimensionality(), 1);
109 THEN(
"The vertices are valid.")
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());
117 AND_WHEN(
"Three vertices are inserted.")
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);
124 THEN(
"The vertices are in the manifold.")
126 auto vertices = manifold.get_vertices_span();
127 auto require = [&manifold](
auto& vertex) {
128 REQUIRE(manifold.is_vertex(vertex));
130 std::ranges::for_each(vertices, require);
133 THEN(
"The Delaunay triangulation is valid.")
135 REQUIRE(manifold.is_valid());
138 THEN(
"There are 3 vertices.") { REQUIRE_EQ(manifold.N0(), 3); }
140 THEN(
"There are 3 edges.") { REQUIRE_EQ(manifold.N1(), 3); }
142 THEN(
"There is 1 face.") { REQUIRE_EQ(manifold.N2(), 1); }
144 THEN(
"There are no simplices.") { REQUIRE_EQ(manifold.N3(), 0); }
146 THEN(
"A 3 vertex manifold has dimension 2.")
148 REQUIRE_EQ(manifold.dimensionality(), 2);
151 THEN(
"The vertices are valid.")
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());
159 AND_WHEN(
"Four vertices are inserted.")
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);
167 THEN(
"The vertices are in the manifold.")
169 auto vertices = manifold.get_vertices_span();
170 auto require = [&manifold](
auto& vertex) {
171 REQUIRE(manifold.is_vertex(vertex));
173 std::ranges::for_each(vertices, require);
176 THEN(
"The Delaunay triangulation is valid.")
178 REQUIRE(manifold.is_valid());
181 THEN(
"There are 4 vertices.") { REQUIRE_EQ(manifold.N0(), 4); }
183 THEN(
"There are 6 edges.") { REQUIRE_EQ(manifold.N1(), 6); }
185 THEN(
"There are 4 faces.") { REQUIRE_EQ(manifold.N2(), 4); }
187 THEN(
"There is a simplex.") { REQUIRE_EQ(manifold.N3(), 1); }
189 THEN(
"A 4 vertex manifold has dimension 3.")
191 REQUIRE_EQ(manifold.dimensionality(), 3);
194 THEN(
"The vertices are valid.")
197 "When 4 causal vertices are inserted, there is a simplex:\n");
198 manifold.print_cells();
199 CHECK(manifold.get_triangulation().check_all_vertices());
203 AND_WHEN(
"Five vertices are inserted.")
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);
212 THEN(
"The vertices are in the manifold.")
214 auto vertices = manifold.get_vertices_span();
215 auto require = [&manifold](
auto& vertex_candidate) {
216 REQUIRE(manifold.is_vertex(vertex_candidate));
218 std::ranges::for_each(vertices, require);
221 THEN(
"The Delaunay triangulation is valid.")
223 REQUIRE(manifold.is_valid());
226 THEN(
"There are 5 vertices.") { REQUIRE_EQ(manifold.N0(), 5); }
228 THEN(
"There are 9 edges.") { REQUIRE_EQ(manifold.N1(), 9); }
230 THEN(
"There are 7 faces.") { REQUIRE_EQ(manifold.N2(), 7); }
232 THEN(
"There are 2 simplexes.") { REQUIRE_EQ(manifold.N3(), 2); }
234 THEN(
"A 5 vertex manifold still has dimension 3.")
236 REQUIRE_EQ(manifold.dimensionality(), 3);
239 THEN(
"The vertices are valid.")
242 "When 5 causal vertices are inserted, there are 2 simplices:\n");
243 manifold.print_cells();
244 CHECK(manifold.get_triangulation().check_all_vertices());
Data structures for manifolds.
SCENARIO("Perform bistellar flip on Delaunay triangulation" *doctest::test_suite("bistellar"))