From d8e2cfaecd48a1994e82d8e7022ad6372e085eda Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 23 Mar 2010 14:59:11 +0000 Subject: [PATCH] Fix yet another bug of Mesh_2: if a vertex of the CDT has all its incident edges in a cluster of constrained edges, then the construction of the cluster was buggy. --- Mesh_2/include/CGAL/Mesh_2/Clusters.h | 71 +++++++++++++++------------ 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/Mesh_2/include/CGAL/Mesh_2/Clusters.h b/Mesh_2/include/CGAL/Mesh_2/Clusters.h index db08e7c7830..4764e8ebe7e 100644 --- a/Mesh_2/include/CGAL/Mesh_2/Clusters.h +++ b/Mesh_2/include/CGAL/Mesh_2/Clusters.h @@ -1,4 +1,5 @@ // Copyright (c) 2004-2005 INRIA Sophia-Antipolis (France). +// Copyright (c) 2010 GeometryFactory Sarl (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -15,7 +16,7 @@ // $Id$ // // -// Author(s) : Laurent RINEAU +// Author(s) : Laurent Rineau #ifndef CGAL_MESH_2_CLUSTERS_H #define CGAL_MESH_2_CLUSTERS_H @@ -191,7 +192,7 @@ private: * to the clusters of the vertex \c v. */ void construct_cluster(const Vertex_handle v, - Constrained_edge_circulator begin, + const Constrained_edge_circulator& begin, const Constrained_edge_circulator& end, Cluster c = Cluster()); @@ -448,7 +449,7 @@ create_clusters_of_vertex(const Vertex_handle v) template void Clusters:: construct_cluster(Vertex_handle v, - Constrained_edge_circulator begin, + const Constrained_edge_circulator& begin, const Constrained_edge_circulator& end, Cluster c) { @@ -468,11 +469,8 @@ construct_cluster(Vertex_handle v, c.smallest_angle.second = target(second); } - bool all_edges_in_cluster=false; // tell if all incident edges are - // in the cluster - if(begin==end) - all_edges_in_cluster=true; - + const bool all_edges_in_cluster = (begin == end); // tell if all incident edges + // are in the cluster const Point& vp = v->point(); FT greatest_cosine = @@ -480,31 +478,42 @@ construct_cluster(Vertex_handle v, v->point(), c.smallest_angle.second->point()); - Constrained_edge_circulator next(begin); - ++next; - do - { - c.vertices[target(begin)] = false; - Squared_length l = squared_distance(vp, - target(begin)->point()); - c.minimum_squared_length = - (std::min)(l,c.minimum_squared_length); + bool one_full_loop_is_needed = all_edges_in_cluster; - if(all_edges_in_cluster || begin!=end) - { - FT cosine = - squared_cosine_of_angle_times_4(target(begin)->point(), - v->point(), - target(next)->point()); - if(cosine>greatest_cosine) - { - greatest_cosine = cosine; - c.smallest_angle.first = target(begin); - c.smallest_angle.second = target(next); - } - } + bool stop = false; + Constrained_edge_circulator circ(begin); + Constrained_edge_circulator next(begin); + while(!stop) + { + c.vertices[target(circ)] = false; + Squared_length l = squared_distance(vp, + target(circ)->point()); + c.minimum_squared_length = + (std::min)(l,c.minimum_squared_length); + + if(circ!=end || one_full_loop_is_needed) + { + FT cosine = + squared_cosine_of_angle_times_4(target(circ)->point(), + v->point(), + target(next)->point()); + if(cosine>greatest_cosine) + { + greatest_cosine = cosine; + c.smallest_angle.first = target(circ); + c.smallest_angle.second = target(next); + } } - while(next++,begin++!=end); + + if(one_full_loop_is_needed) { + one_full_loop_is_needed = false; + } else { + stop = (circ == end); + } + ++circ; + ++next; + } + typedef typename Cluster_map::value_type Value_key_pair; cluster_map.insert(Value_key_pair(v,c)); }