3 #include <catch2/catch_test_macros.hpp>
4 #include <nlohmann/json.hpp>
5 #include <paraviewo/VTUWriter.hpp>
15 const std::filesystem::path
data_dir = WMTK_DATA_DIR;
19 const Eigen::Ref<Eigen::MatrixXd> p,
20 const Eigen::Ref<Eigen::MatrixXd> v)
22 REQUIRE(p.cols() == v.cols());
23 REQUIRE(p.rows() <= v.rows());
25 std::vector<Eigen::VectorXd> vv;
27 for (Eigen::Index i = 0; i < v.rows(); ++i) {
28 vv.emplace_back(v.row(i));
31 auto v_less = [](
const Eigen::Ref<Eigen::VectorXd> a,
const Eigen::Ref<Eigen::VectorXd> b) {
32 for (Eigen::Index i = 0; i < a.rows() - 1; ++i) {
37 return a[a.rows() - 1] < b[b.rows() - 1];
40 std::sort(vv.begin(), vv.end(), v_less);
41 for (Eigen::Index i = 0; i < p.rows(); ++i) {
42 const Eigen::VectorXd r = p.row(i);
43 CHECK(std::find(vv.begin(), vv.end(), r) != vv.end());
80 TEST_CASE(
"delaunay_2d_five_points",
"[components][delaunay]")
84 points.row(0) << -1, -1;
85 points.row(1) << -1, 1;
86 points.row(2) << 1, -1;
87 points.row(3) << 1, 1;
88 points.row(4) << 0, 0;
91 Eigen::MatrixXi
faces;
96 paraviewo::VTUWriter writer;
97 writer.write_mesh(
"delaunay_2d_five_points.vtu",
vertices,
faces);
101 TEST_CASE(
"delaunay_2d_random",
"[components][delaunay]")
103 std::uniform_real_distribution<double> distribution(-1, 1);
104 std::default_random_engine random_engine;
108 for (
size_t i = 0; i < 100; ++i) {
109 const double x = distribution(random_engine);
110 const double y = distribution(random_engine);
111 points.row(i) << x, y;
115 Eigen::MatrixXi
faces;
120 paraviewo::VTUWriter writer;
121 writer.write_mesh(
"delaunay_2d_random.vtu",
vertices,
faces);
125 TEST_CASE(
"delaunay_3d_nine_points",
"[components][delaunay]")
129 points.row(0) << -1, -1, -1;
130 points.row(1) << 1, -1, -1;
131 points.row(2) << -1, 1, -1;
132 points.row(3) << -1, -1, 1;
133 points.row(4) << 1, 1, -1;
134 points.row(5) << -1, 1, 1;
135 points.row(6) << 1, -1, 1;
136 points.row(7) << 1, 1, 1;
137 points.row(8) << 0, 0, 0;
140 Eigen::MatrixXi
faces;
145 paraviewo::VTUWriter writer;
146 writer.write_mesh(
"delaunay_3d_nine_points.vtu",
vertices,
faces);
150 TEST_CASE(
"delaunay_3d_random",
"[components][delaunay]")
152 std::uniform_real_distribution<double> distribution(-1, 1);
153 std::default_random_engine random_engine;
157 for (
size_t i = 0; i < 100; ++i) {
158 const double x = distribution(random_engine);
159 const double y = distribution(random_engine);
160 const double z = distribution(random_engine);
161 points.row(i) << x, y, z;
165 Eigen::MatrixXi
faces;
170 paraviewo::VTUWriter writer;
171 writer.write_mesh(
"delaunay_3d_random.vtu",
vertices,
faces);
177 Eigen::MatrixXd points;
186 points.row(0) << 0, 1, 2, 3;
192 TEST_CASE(
"delaunay_empty_points",
"[components][delaunay]")
194 Eigen::MatrixXd points;
196 Eigen::MatrixXi
faces;
200 CHECK(
faces.rows() == 0);
std::tuple< Eigen::MatrixXd, Eigen::MatrixXi > delaunay_3d(Eigen::Ref< const RowVectors3d > points)
std::tuple< Eigen::MatrixXd, Eigen::MatrixXi > delaunay_geogram(Eigen::Ref< const Eigen::MatrixXd > points)
std::tuple< Eigen::MatrixXd, Eigen::MatrixXi > delaunay_2d(Eigen::Ref< const RowVectors2d > points)
std::vector< Tuple > vertices(const Mesh &m, const Simplex &simplex)
SimplexCollection faces(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Returns all faces of a simplex.
RowVectors< double, 2 > RowVectors2d
RowVectors< double, 3 > RowVectors3d
const std::filesystem::path data_dir
TEST_CASE("delaunay_2d_five_points", "[components][delaunay]")
void check_p_is_contained_in_v(const Eigen::Ref< Eigen::MatrixXd > p, const Eigen::Ref< Eigen::MatrixXd > v)