diff --git a/src/cpp/include/Triangulate.h b/src/cpp/include/Triangulate.h index 0f67056..ba80d45 100644 --- a/src/cpp/include/Triangulate.h +++ b/src/cpp/include/Triangulate.h @@ -14,6 +14,10 @@ #include "Eigen/Eigen" #include "Eigen/Geometry" + +#include "Logging.h" +#include "Timer.h" + #include "model/Mesh.h" #include "model/Surface.h" #include "model/Vector.h" @@ -159,6 +163,21 @@ static void call_triangle(Mesh &mesh, // Create input data structure for Triangle struct triangulateio in = create_triangle_io(); + // Check for duplicate points + size_t duplicate_vertices = 0; + for (auto polygon: sub_domains) + { + auto first = polygon.front(); + auto last = polygon.back(); + if (first.close_to(last)) + { + polygon.pop_back(); + duplicate_vertices++; + } + + } + info("Removed " + str(duplicate_vertices) + " duplicate vertices"); + // Set number of points size_t num_points = boundary.size(); for (auto const &innerPolygon : sub_domains) diff --git a/src/cpp/include/model/Vector.h b/src/cpp/include/model/Vector.h index dbb923e..644a2e0 100644 --- a/src/cpp/include/model/Vector.h +++ b/src/cpp/include/model/Vector.h @@ -123,6 +123,11 @@ class Vector2D : public Printable void normalize() { (*this) /= magnitude(); } + bool close_to(const Vector2D &p, double tol = 1e-6) const + { + return (std::abs(x - p.x) < tol && std::abs(y - p.y) < tol); + } + /// Pretty-print std::string __str__() const override { @@ -240,6 +245,11 @@ class Vector3D : public Printable return (x == p.x && y == p.y && z == p.z); } + bool close_to(const Vector3D &p, double tol = 1e-6) const + { + return (std::abs(x - p.x) < tol && std::abs(y - p.y) < tol && std::abs(z - p.z) < tol); + } + double dot(const Vector3D &p) const { return x * p.x + y * p.y + z * p.z; } Vector3D cross(const Vector3D &p) const