Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
remove duplicate vertices before triangulation
Browse files Browse the repository at this point in the history
  • Loading branch information
dwastberg committed May 22, 2024
1 parent dc0ed20 commit c4c4483
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/cpp/include/Triangulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/cpp/include/model/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c4c4483

Please sign in to comment.