From 081012221e6c017c82641001704c4be0ffa9131e Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 15 Sep 2021 19:30:19 +0800 Subject: [PATCH] update src --- delaunay.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ demo.cpp | 12 +++++++++++ 2 files changed, 73 insertions(+) diff --git a/delaunay.h b/delaunay.h index a6513b4..2b2e0e5 100644 --- a/delaunay.h +++ b/delaunay.h @@ -239,4 +239,65 @@ void triangulation(std::vector &in_verts, std::vector &out_ return; } +/** + * @brief Check for duplicated vertex + * + * @param[in] in_verts Input vertexes + * + * @return If there is duplicated vertex + */ +bool duplicated_vertex(const std::vector &in_verts) +{ + if (in_verts.empty()) return false; + + for (int i = 0; i < in_verts.size()-1; ++i) + { + for (int j = i+1; j < in_verts.size(); ++j) + { + if (in_verts[i] == in_verts[j]) + { + return true; + } + } + } + return false; +} + +/** + * @brief Check to see if the triangulation is fully delaunay + * + * @param[in] in_tris Input triangles + * @param[in] in_verts Input vertexes + * + * @return If the triangulation is fully delaunay + */ +bool fully_delaunay(const std::vector &in_tris, const std::vector &in_verts) +{ + if (in_tris.empty()) return true; + + int count; + double dist; + for (int i = 0; i < in_tris.size(); ++i) + { + count = 0; + for (int j = 0; j < in_verts.size(); ++j) + { + dist = (in_tris[i].cx - in_verts[j].x) * (in_tris[i].cx - in_verts[j].x) + + (in_tris[i].cy - in_verts[j].y) * (in_tris[i].cy - in_verts[j].y); + + if ((dist - in_tris[i].cr) <= ZERO) + { + count++; + } + } + + if (count > 3) + { + return false; + } + } + + return true; +} + #endif // _BW_2D_DELAUNAY_H \ No newline at end of file diff --git a/demo.cpp b/demo.cpp index 638a901..e142f77 100644 --- a/demo.cpp +++ b/demo.cpp @@ -26,9 +26,21 @@ int main(int argc, char const *argv[]) points[19].set(3.5, 1.8, 19); points[20].set(3.6, 3.1, 20); + if (duplicated_vertex(points)) + { + std::cerr << "Duplicated vertice detected.\n"; + return 0; + } + std::vector elements; triangulation(points, elements); + if (fully_delaunay(elements, points)) + { + std::clog << "The triangulation is fully delaunay.\n"; + } + else std::clog << "The triangulation is not fully delaunay\n"; + std::cout << "OFF\n"; std::cout << points.size() << " " << elements.size() << " 0\n";