diff --git a/Partition_2/examples/Partition_2/y_monotone_partition_indices_2.cpp b/Partition_2/examples/Partition_2/y_monotone_partition_indices_2.cpp index 2036f194b8d..ec72d837230 100644 --- a/Partition_2/examples/Partition_2/y_monotone_partition_indices_2.cpp +++ b/Partition_2/examples/Partition_2/y_monotone_partition_indices_2.cpp @@ -43,7 +43,7 @@ int main( ) Polygon_list partition_polys; - CGAL::y_monotone_partition_2(polygon.vertices_begin(), + CGAL::optimal_convex_partition_2(polygon.vertices_begin(), polygon.vertices_end(), std::back_inserter(partition_polys), traits); diff --git a/Partition_2/include/CGAL/Partition_2/Rotation_tree_node_2.h b/Partition_2/include/CGAL/Partition_2/Rotation_tree_node_2.h index a4c538465b1..ec84dfeefcb 100644 --- a/Partition_2/include/CGAL/Partition_2/Rotation_tree_node_2.h +++ b/Partition_2/include/CGAL/Partition_2/Rotation_tree_node_2.h @@ -45,8 +45,9 @@ namespace CGAL { template class Rotation_tree_2; template -class Rotation_tree_node_2 : public Traits::Point_2 +class Rotation_tree_node_2 { + typename Traits::Point_2 point; public: typedef typename Traits::Point_2 Base_point; @@ -56,7 +57,7 @@ public: typedef std::pair Node_ref; - Rotation_tree_node_2(Base_point p) : Base_point(p) + Rotation_tree_node_2(Base_point p) : point(p) { _parent.second = false; _left_sibling.second = false; @@ -64,6 +65,9 @@ public: _rightmost_child.second = false; } + operator Base_point() const + { return point;} + bool has_left_sibling() const { return _left_sibling.second; } diff --git a/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2.h b/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2.h index 571161d71b2..9c079980975 100644 --- a/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2.h +++ b/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2.h @@ -96,11 +96,11 @@ private: Collinear_are_ordered_along_line_2; typedef typename Traits::Are_strictly_ordered_along_line_2 Are_strictly_ordered_along_line_2; - typedef typename Traits::Construct_segment_2 - Construct_segment_2; - typedef typename Traits::Construct_ray_2 Construct_ray_2; - typedef typename Traits::Intersect_2 Intersect_2; - typedef typename Traits::Assign_2 Assign_2; + // typedef typename Traits::Construct_segment_2 + // Construct_segment_2; + // typedef typename Traits::Construct_ray_2 Construct_ray_2; + // typedef typename Traits::Intersect_2 Intersect_2; + // typedef typename Traits::Assign_2 Assign_2; typedef CGAL::Segment_less_yx_2 Segment_less_yx_2; typedef Rotation_tree_2 Tree; @@ -140,10 +140,10 @@ public: are_strictly_ordered_along_line_2( traits.are_strictly_ordered_along_line_2_object()), less_xy_2(traits.less_xy_2_object()), - construct_segment_2(traits.construct_segment_2_object()), - construct_ray_2(traits.construct_ray_2_object()), - intersect_2(traits.intersect_2_object()), - assign_2(traits.assign_2_object()), + // construct_segment_2(traits.construct_segment_2_object()), + //construct_ray_2(traits.construct_ray_2_object()), + //intersect_2(traits.intersect_2_object()), + //assign_2(traits.assign_2_object()), edges(Point_pair_compare(traits)) { build(first, beyond, traits); @@ -156,8 +156,8 @@ public: Polygon polygon(first,beyond); Tree tree(polygon.begin(), polygon.end(),traits); - Vertex_map vertex_map; - initialize_vertex_map(polygon, vertex_map,traits); + Vertex_map vertex_map(less_xy_2); + initialize_vertex_map(polygon, vertex_map, traits); // NOTE: use the std::list as the basis here because otherwise the basis // is a deque, which is buggy under MSVC++ @@ -421,10 +421,10 @@ private: Collinear_are_ordered_along_line_2 collinear_ordered_2; Are_strictly_ordered_along_line_2 are_strictly_ordered_along_line_2; Less_xy_2 less_xy_2; - Construct_segment_2 construct_segment_2; - Construct_ray_2 construct_ray_2; - Intersect_2 intersect_2; - Assign_2 assign_2; + // Construct_segment_2 construct_segment_2; + // Construct_ray_2 construct_ray_2; + //Intersect_2 intersect_2; + // Assign_2 assign_2; Edge_set edges; }; diff --git a/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2_impl.h b/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2_impl.h index 6e3df64f4aa..fd38b55d1c1 100644 --- a/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2_impl.h +++ b/Partition_2/include/CGAL/Partition_2/Vertex_visibility_graph_2_impl.h @@ -522,6 +522,8 @@ void Vertex_visibility_graph_2::update_visibility( // don't need to do this for the previous visibility point since // if it were closer to p than q when looking from p to q, q would // not be visible. + + #if 0 Segment_2 next_seg = construct_segment_2(*(*p_it).second.second, *next_v_p); Ray_2 ray = construct_ray_2((*p_it).first, (*q_it).first); @@ -535,18 +537,7 @@ void Vertex_visibility_graph_2::update_visibility( if (collinear_ordered_2((*p_it).first, (*q_it).first, i_point)) { (*p_it).second.second = (*q_it).second.first; -#ifdef CGAL_VISIBILITY_GRAPH_DEBUG - std::cout << "p sees something in direction of q, but q is closer;" - << " p sees q" << std::endl; -#endif } -#ifdef CGAL_VISIBILITY_GRAPH_DEBUG - else - { - std::cout << "p sees something in direction of q that's closer " - << "than q; p doesn't see q" << std::endl; - } -#endif } else if (assign_2(i_seg, next_result)) { @@ -554,27 +545,57 @@ void Vertex_visibility_graph_2::update_visibility( collinear_ordered_2((*p_it).first,(*q_it).first,i_seg.target())) { (*p_it).second.second = (*q_it).second.first; -#ifdef CGAL_VISIBILITY_GRAPH_DEBUG - std::cout << "p sees something in direction of q, but q is closer;" - << " p sees q" << std::endl; -#endif } -#ifdef CGAL_VISIBILITY_GRAPH_DEBUG - else - { - std::cout << "p sees something in direction of q that's closer " - << " than q; p doesn't see q" << std::endl; - } -#endif + } else { (*p_it).second.second = (*q_it).second.first; -#ifdef CGAL_VISIBILITY_GRAPH_DEBUG - std::cout << "p doesn't see something in direction of q; p sees q" - << std::endl; -#endif } +#else + // Segment ab and Ray pq + Point_2 a = *(*p_it).second.second; + Point_2 b = *next_v_p; + Point_2 p = (*p_it).first; + Point_2 q = (*q_it).first; + Orientation pqa = orientation_2(p,q,a); + Orientation pqb = orientation_2(p,q,b); + Orientation abp = orientation_2(a,b,p); + Orientation abq = orientation_2(a,b,q); + bool change = false; + if((pqa == COLLINEAR)&& (pqb == COLLINEAR)){ + // the segment lies on the supporting line of the ray + if(collinear_ordered_2(p,q,a) && collinear_ordered_2(p,q,b)){ + change = true; + } + } else if (pqa == COLLINEAR){ + if (collinear_ordered_2(p,q,a)){ // forget about b as it is not collinear + change = true; + } + } else if (pqb == COLLINEAR){ + if (collinear_ordered_2(p,q,b)){ // forget about a + change = true; + } + }else if(pqa == pqb){ + // no intersection as the segment is completely to the left or to the right of the ray + }else if((abp == COLLINEAR) || (abq == COLLINEAR) ){ + // do nothing because when a ray point lies on the segment collinear_ordered_2 will be false + } else if (abp != abq){ + // do nothing as i between p and q + } else if(pqb == RIGHT_TURN){ + if(abp == RIGHT_TURN){ + change = true; + } + } else { + CGAL_assertion(pqa == RIGHT_TURN); + if(abp == LEFT_TURN){ + change = true; + } + } + if(change){ + (*p_it).second.second = (*q_it).second.first; + } +#endif } else // p sees what q sees { diff --git a/Partition_2/include/CGAL/Partition_traits_adapter_2.h b/Partition_2/include/CGAL/Partition_traits_adapter_2.h index bbd9ec883e6..2c1100d499a 100644 --- a/Partition_2/include/CGAL/Partition_traits_adapter_2.h +++ b/Partition_2/include/CGAL/Partition_traits_adapter_2.h @@ -117,7 +117,7 @@ public: typename K::Collinear_are_ordered_along_line_2::result_type operator()(Arg_type p, Arg_type q, Arg_type r) const { - return fct(get(ppmap,p), get(ppmap,q), r.first); + return fct(get(ppmap,p), get(ppmap,q), get(ppmap,r)); } }; @@ -140,7 +140,7 @@ public: // needed by visibility graph and thus by optimal convex typedef typename Kernel::Ray_2 Ray_2; - typedef Pmap_collinear_are_ordered_along_line_2 Collinear_are_ordered_along_line_2; + typedef Pmap_collinear_are_ordered_along_line_2 Collinear_are_ordered_along_line_2; typedef Pmap_fct Are_strictly_ordered_along_line_2; typedef typename Kernel::Intersect_2 Intersect_2; @@ -204,11 +204,11 @@ public: Collinear_are_ordered_along_line_2 collinear_are_ordered_along_line_2_object() const - { return Collinear_are_ordered_along_line_2(); } + { return Collinear_are_ordered_along_line_2(ppmap,static_cast(this)->collinear_are_ordered_along_line_2_object()); } Are_strictly_ordered_along_line_2 are_strictly_ordered_along_line_2_object() const - { return Are_strictly_ordered_along_line_2(); } + { return Are_strictly_ordered_along_line_2(ppmap,static_cast(this)->are_strictly_ordered_along_line_2_object()); } Is_horizontal_2