Browse Source

Bug fix: avoid having query point colinear with the closest edge.

Former-commit-id: 49ea319600e89422f0495013eccd88e0982e770e
Qingnan Zhou 9 years ago
parent
commit
70478c8d2d
1 changed files with 11 additions and 6 deletions
  1. 11 6
      include/igl/copyleft/cgal/closest_facet.cpp

+ 11 - 6
include/igl/copyleft/cgal/closest_facet.cpp

@@ -308,14 +308,19 @@ IGL_INLINE void igl::copyleft::cgal::closest_facet(
             for (size_t j=i+1; j<num_adj_vertices; j++) {
                 Plane_3 separator(closest_point, adj_points[i], adj_points[j]);
                 if (separator.is_degenerate()) {
-                    throw std::runtime_error(
-                            "Input mesh contains degenerated faces");
+                    continue;
                 }
                 if (is_on_exterior(separator)) {
-                    d = vi;
-                    assert(!CGAL::collinear(
-                                query_point, adj_points[i], closest_point));
-                    break;
+                    if (!CGAL::collinear(
+                                query_point, adj_points[i], closest_point)) {
+                        d = vi;
+                        break;
+                    } else {
+                        d = adj_vertices[j];
+                        assert(!CGAL::collinear(
+                                    query_point, adj_points[j], closest_point));
+                        break;
+                    }
                 }
             }
         }