BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arr_point_location/Arr_batched_point_location_traits_2.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Tel-Aviv University (Israel).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_batched_point_location_traits_2.h $
00015 // $Id: Arr_batched_point_location_traits_2.h 50366 2009-07-05 12:56:48Z efif $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 //                 Ron Wein        <wein@post.tau.ac.il>
00020 //                 Efi Fogel       <efif@post.tau.ac.il>
00021 
00022 #ifndef CGAL_ARR_BATCHED_POINT_LOCATION_TRAITS_2_H
00023 #define CGAL_ARR_BATCHED_POINT_LOCATION_TRAITS_2_H
00024 
00029 #include <CGAL/Arr_tags.h>
00030 
00031 CGAL_BEGIN_NAMESPACE
00032 
00036 template <typename Arrangement_>
00037 class Arr_batched_point_location_traits_2
00038 {
00039 public:
00040 
00041   typedef Arrangement_                                  Arrangement_2;
00042   typedef typename Arrangement_2::Geometry_traits_2     Base_traits_2;
00043 
00044   typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle;
00045   typedef typename Arrangement_2::Vertex_const_handle   Vertex_const_handle;
00046 
00047   typedef typename Base_traits_2::X_monotone_curve_2   Base_x_monotone_curve_2;
00048   typedef typename Base_traits_2::Point_2              Base_point_2;
00049 
00050   typedef typename Base_traits_2::Construct_min_vertex_2
00051                                                     Base_construct_min_vertex_2;
00052   typedef typename Base_traits_2::Construct_max_vertex_2
00053                                                     Base_construct_max_vertex_2;
00054   typedef typename Base_traits_2::Compare_x_2       Base_compare_x_2;
00055   typedef typename Base_traits_2::Compare_xy_2      Base_compare_xy_2;
00056   typedef typename Base_traits_2::Compare_y_at_x_2  Base_compare_y_at_x_2;
00057   typedef typename Base_traits_2::Compare_y_at_x_right_2 
00058                                                     Base_compare_y_at_x_right_2;
00059   typedef typename Base_traits_2::Equal_2           Base_equal_2;
00060   typedef typename Base_traits_2::Is_vertical_2     Base_is_vertical_2;
00061 
00062   typedef typename CGALi::Arr_complete_left_side_tag< Base_traits_2 >::Tag 
00063                                                     Arr_left_side_tag;
00064   typedef typename CGALi::Arr_complete_bottom_side_tag< Base_traits_2 >::Tag
00065                                                     Arr_bottom_side_tag;
00066   typedef typename CGALi::Arr_complete_top_side_tag< Base_traits_2 >::Tag
00067                                                    Arr_top_side_tag;
00068   typedef typename CGALi::Arr_complete_right_side_tag< Base_traits_2 >::Tag
00069                                                     Arr_right_side_tag;
00070   
00071   /* Overlay is implemented as sweep-line visitor. The sweep-line algorithm
00072    * never uses Compare_y_at_x_left_2, and it never performs merging of curves.
00073    * Thus, AreMergeable_2 and Merge_2 are not needed either.
00074    */
00075   typedef Tag_false                                 Has_left_category;
00076   typedef Tag_false                                 Has_merge_category;
00077 
00078 protected:
00079 
00080   const Base_traits_2*    m_base_traits;
00081  
00082 public:
00083 
00085   Arr_batched_point_location_traits_2 (const Base_traits_2& tr) :
00086     m_base_traits (&tr)
00087   {}
00088 
00092   class Ex_x_monotone_curve_2 
00093   {
00094   public:
00095 
00096     typedef Base_x_monotone_curve_2    Base;
00097 
00098   protected:
00099     
00100     Base_x_monotone_curve_2 m_base_xcv;  // The base x-monotone curve.
00101     Halfedge_const_handle   m_he;        // The corresponding arrangement edge.
00102 
00103   public:
00104 
00105     Ex_x_monotone_curve_2 ():
00106       m_base_xcv(),
00107       m_he()
00108     {}
00109 
00110     Ex_x_monotone_curve_2 (const Base& xcv):
00111       m_base_xcv(xcv),
00112       m_he()
00113     {}
00114 
00115     Ex_x_monotone_curve_2 (const Base& xcv, Halfedge_const_handle he) :
00116       m_base_xcv(xcv),
00117       m_he(he)
00118     {
00119       CGAL_precondition (he->direction() == ARR_RIGHT_TO_LEFT);
00120     }
00121 
00122     Halfedge_const_handle halfedge_handle() const
00123     {
00124       return (m_he);
00125     }
00126 
00127     const Base& base () const
00128     {
00129       return (m_base_xcv);
00130     }
00131 
00132     Base& base ()
00133     {
00134       return (m_base_xcv);
00135     }
00136 
00137     operator const Base&() const
00138     {
00139       return (m_base_xcv);
00140     }
00141 
00142     operator Base&()
00143     {
00144       return (m_base_xcv);
00145     }
00146    
00147   };
00148 
00152   class Ex_point_2 
00153   {
00154   public:
00155 
00156     typedef  Base_point_2            Base;
00157 
00158   protected:
00159 
00160     Base                   m_base_pt; // The base point.
00161     Vertex_const_handle    m_v;       // The corresponding arrangement vertex.
00162 
00163   public:
00164 
00165     Ex_point_2 ():
00166       m_base_pt(),
00167       m_v()
00168     {}
00169 
00170     Ex_point_2 (const Base& pt):
00171       m_base_pt (pt),
00172       m_v()
00173     {}
00174 
00175     Ex_point_2 (const Base& pt, Vertex_const_handle v):
00176       m_base_pt (pt),
00177       m_v (v)
00178     {}
00179 
00180     const Base& base() const
00181     {
00182       return (m_base_pt);
00183     }
00184 
00185     Base& base()
00186     {
00187       return (m_base_pt);
00188     }
00189 
00190     operator const Base&() const
00191     {
00192       return (m_base_pt);
00193     }
00194 
00195     operator Base&()
00196     {
00197       return (m_base_pt);
00198     }
00199 
00200     Vertex_const_handle vertex_handle() const
00201     {
00202       return m_v;
00203     } 
00204   };
00205 
00206   typedef Ex_x_monotone_curve_2                     X_monotone_curve_2; 
00207   typedef Ex_point_2                                Point_2; 
00208 
00209 #ifdef CGAL_SL_VERBOSE
00210   // For debugging purposes:
00211   friend std::ostream& operator<< (std::ostream& os,
00212                                    const X_monotone_curve_2& xcv)
00213   {
00214     os << xcv.base();
00215     return (os);
00216   }
00217 
00218   // For debugging purposes:
00219   friend std::ostream& operator<< (std::ostream& os,
00220                                    const Point_2& pt)
00221   {
00222     os << pt.base();
00223     return (os);
00224   }
00225 #endif
00226 
00228   class Construct_min_vertex_2 {
00229   protected:
00231     Base_construct_min_vertex_2 m_base_min_v;
00232 
00238     Construct_min_vertex_2 (const Base_construct_min_vertex_2& base):
00239         m_base_min_v(base)
00240     {}
00241 
00243     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00244 
00245   public:
00251     Point_2 operator() (const X_monotone_curve_2 & xcv) 
00252     {
00253       // Note that the halfedge associated with the curve is always directed
00254       // from right to left, so its target is the leftmost vertex.
00255       Vertex_const_handle vh = xcv.halfedge_handle()->target();
00256       return (Point_2 (m_base_min_v (xcv.base()), vh));
00257     }
00258   };
00259 
00261   Construct_min_vertex_2 construct_min_vertex_2_object () const
00262   {
00263     return 
00264       Construct_min_vertex_2 (m_base_traits->construct_min_vertex_2_object());
00265   }
00266 
00268   class Construct_max_vertex_2 {
00269   protected:
00271     Base_construct_max_vertex_2 m_base_max_v;
00272 
00278     Construct_max_vertex_2 (const Base_construct_max_vertex_2& base):
00279       m_base_max_v(base)
00280     {}
00281 
00283     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00284 
00285   public:
00291     Point_2 operator() (const X_monotone_curve_2 & xcv) 
00292     {
00293       // Note that the halfedge associated with the curve is always directed
00294       // from right to left, so its source is the rightmost vertex.
00295       Vertex_const_handle vh = xcv.halfedge_handle()->source();
00296       return (Point_2 (m_base_max_v (xcv.base()), vh));
00297     }
00298   };
00299 
00301   Construct_max_vertex_2 construct_max_vertex_2_object () const
00302   {
00303     return
00304       Construct_max_vertex_2 (m_base_traits->construct_max_vertex_2_object());
00305   }
00306 
00308   class Compare_xy_2 {
00309   protected:
00311     Base_compare_xy_2    m_base_cmp_xy;
00312 
00313     Vertex_const_handle  invalid_v;
00314 
00320     Compare_xy_2(const Base_compare_xy_2& base) :
00321       m_base_cmp_xy(base),
00322       invalid_v()
00323     {}
00324 
00326     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00327 
00328   public:
00334     Comparison_result operator() (const Point_2& p1, const Point_2& p2) const
00335     {
00336       if (p1.vertex_handle() == p2.vertex_handle() &&
00337           p1.vertex_handle() != invalid_v)
00338         return (EQUAL);
00339 
00340       return (m_base_cmp_xy (p1.base(), p2.base()));
00341     }
00342   };
00343 
00345   Compare_xy_2 compare_xy_2_object () const
00346   {
00347     return Compare_xy_2(m_base_traits->compare_xy_2_object());
00348   }
00349 
00353   class Compare_y_at_x_2 {
00354   protected:
00356     Base_compare_y_at_x_2 m_base_cmp_y_at_x;
00357 
00363     Compare_y_at_x_2(const Base_compare_y_at_x_2& base) :
00364       m_base_cmp_y_at_x(base)
00365     {}
00366 
00368     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00369 
00370   public:
00371     Comparison_result operator() (const Point_2& p,
00372                                   const X_monotone_curve_2& xcv) const
00373     {
00374       return (m_base_cmp_y_at_x (p.base(), xcv.base()));
00375     }
00376   };
00377 
00379   Compare_y_at_x_2 compare_y_at_x_2_object () const
00380   {
00381     return (Compare_y_at_x_2 (m_base_traits->compare_y_at_x_2_object()));
00382   }
00383 
00387   class Compare_y_at_x_right_2 {
00388   protected:
00390     Base_compare_y_at_x_right_2 m_base_cmp_y_at_x_right;
00391 
00397     Compare_y_at_x_right_2(const Base_compare_y_at_x_right_2& base) :
00398       m_base_cmp_y_at_x_right(base)
00399     {}
00400 
00402     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00403 
00404   public:
00405     Comparison_result operator() (const X_monotone_curve_2& xcv1,
00406                                   const X_monotone_curve_2& xcv2,
00407                                   const Point_2& p) const
00408     {
00409       return (m_base_cmp_y_at_x_right(xcv1.base(), xcv2.base(), p.base()));
00410     }
00411   };
00412 
00414   Compare_y_at_x_right_2 compare_y_at_x_right_2_object () const
00415   {
00416     return (Compare_y_at_x_right_2
00417             (m_base_traits->compare_y_at_x_right_2_object()));
00418   }
00419 
00423   class Equal_2 {
00424   protected:
00426     Base_equal_2           m_base_eq;
00427 
00428     Vertex_const_handle    invalid_v;
00429     Halfedge_const_handle  invalid_he;
00430 
00436     Equal_2(const Base_equal_2& base) :
00437       m_base_eq(base),
00438       invalid_v(),
00439       invalid_he()
00440     {}
00441 
00443     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00444 
00445   public:  
00447     bool operator() (const X_monotone_curve_2& xcv1,
00448                      const X_monotone_curve_2& xcv2) const
00449     {
00450       if (xcv1.halfedge_handle() == xcv2.halfedge_handle() &&
00451           xcv1.halfedge_handle() != invalid_he)
00452         return (true);
00453 
00454       return (m_base_eq(xcv1.base(), xcv2.base()));
00455     }
00456 
00458     bool operator() (const Point_2& p1, const Point_2& p2) const
00459     {
00460       if (p1.vertex_handle() == p2.vertex_handle() &&
00461           p1.vertex_handle() != invalid_v)
00462         return (true);
00463 
00464       return (m_base_eq(p1.base(), p2.base()));
00465     }
00466   };
00467 
00469   Equal_2 equal_2_object () const
00470   {
00471     return (Equal_2 (m_base_traits->equal_2_object()));
00472   }
00473 
00475   class Compare_x_2 {
00476   protected:
00478     Base_compare_x_2 m_base_cmp_x;
00479 
00485     Compare_x_2(const Base_compare_x_2& base) : m_base_cmp_x(base) {}
00486 
00488     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00489 
00490   public:
00491     Comparison_result operator() (const Point_2& p1, const Point_2& p2) const
00492     {
00493       return (m_base_cmp_x(p1.base(), p2.base()));
00494     }
00495   };
00496 
00498   Compare_x_2 compare_x_2_object () const
00499   {
00500     return (Compare_x_2 (m_base_traits->compare_x_2_object()));
00501   }
00502 
00504   class Is_vertical_2 {
00505   protected:
00507     Base_is_vertical_2 m_base_is_vert;
00508 
00514     Is_vertical_2(const Base_is_vertical_2& base) : m_base_is_vert(base) {}
00515 
00517     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00518 
00519   public:
00520     bool operator() (const X_monotone_curve_2& xcv) const
00521     {
00522       return (m_base_is_vert(xcv.base()));
00523     }
00524   };
00525 
00527   Is_vertical_2 is_vertical_2_object() const
00528   {
00529     return (Is_vertical_2(m_base_traits->is_vertical_2_object()));
00530   }
00531 
00532 
00533   // left-right
00534 
00538   class Parameter_space_in_x_2 {
00539   protected:
00541     const Base_traits_2      *m_base;
00542 
00548     Parameter_space_in_x_2 (const Base_traits_2 *tr) : m_base (tr) {}
00549 
00551     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00552     
00553   public:
00554     Arr_parameter_space operator() (const X_monotone_curve_2& xcv,
00555                                     Arr_curve_end ce) const
00556     {
00557       return m_base->parameter_space_in_x_2_object() (xcv.base(), ce);
00558     }
00559 
00560     Arr_parameter_space operator() (const Point_2 & p) const
00561     {
00562       return m_base->parameter_space_in_x_2_object() (p.base());
00563     }
00564 
00565     Arr_parameter_space operator() (const X_monotone_curve_2 & xcv) const
00566     {
00567       return m_base->parameter_space_in_x_2_object() (xcv.base());
00568     }
00569   };
00570 
00572   Parameter_space_in_x_2 parameter_space_in_x_2_object () const
00573   {
00574     return Parameter_space_in_x_2 (m_base_traits);
00575   }
00576 
00580   class Compare_y_near_boundary_2 {
00581   protected:
00583     const Base_traits_2 * m_base;
00584 
00592     Compare_y_near_boundary_2(const Base_traits_2 * tr) : m_base(tr) {}
00593 
00595     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00596 
00597   public:
00598     Comparison_result operator()(const X_monotone_curve_2 & xcv1,
00599                                  const X_monotone_curve_2 & xcv2, 
00600                                  Arr_curve_end ce) const
00601     {
00602       // If the traits class does not support open curves, we just
00603       // return EQUAL, as this comparison will not be invoked anyway.
00604       return m_base->compare_y_near_boundary_2_object()(xcv1.base(),
00605                                                         xcv2.base(), ce);
00606     }
00607   };
00608 
00610   Compare_y_near_boundary_2 compare_y_near_boundary_2_object () const
00611   {
00612     return Compare_y_near_boundary_2(m_base_traits);
00613   }
00614 
00618   class Compare_y_on_boundary_2 {
00619   protected:
00621     const Base_traits_2 * m_base;
00622 
00630     Compare_y_on_boundary_2(const Base_traits_2 * tr) : m_base(tr) {}
00631 
00633     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00634 
00635   public:
00636     Comparison_result operator()(const Point_2 & p1, const Point_2 & p2) const
00637     {
00638       return m_base->compare_x_on_boundary_2_object()(p1.base(), p2.base());
00639     }
00640   };
00641 
00643   Compare_y_on_boundary_2 compare_y_on_boundary_2_object () const
00644   {
00645     return Compare_y_on_boundary_2(m_base_traits);
00646   }
00647 
00648   // TODO Is_on_x_identification_2
00649 
00650   // bottom-top
00651 
00655   class Parameter_space_in_y_2 {
00656   protected:
00658     const Base_traits_2      *m_base;
00659 
00665     Parameter_space_in_y_2(const Base_traits_2 *tr) : m_base (tr) {}
00666 
00668     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00669     
00670   public:
00671     Arr_parameter_space operator() (const X_monotone_curve_2& xcv,
00672                                     Arr_curve_end ce) const
00673     {
00674       return m_base->parameter_space_in_y_2_object() (xcv.base(), ce);
00675     }
00676 
00677     Arr_parameter_space operator() (const Point_2 & p) const
00678     {
00679       return m_base->parameter_space_in_y_2_object()(p.base());
00680     }
00681     
00682     Arr_parameter_space operator() (const X_monotone_curve_2 & xcv) const
00683     {
00684       return m_base->parameter_space_in_y_2_object()(xcv.base());
00685     }
00686 
00687   };
00688 
00690   Parameter_space_in_y_2 parameter_space_in_y_2_object () const
00691   {
00692     return Parameter_space_in_y_2 (m_base_traits);
00693   }
00694 
00698   class Compare_x_near_boundary_2 {
00699   protected:
00701     const Base_traits_2 * m_base;
00702 
00710     Compare_x_near_boundary_2(const Base_traits_2 * tr) : m_base(tr) {}
00711     
00713     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00714     
00715   public:
00716     Comparison_result operator() (const Point_2& p,
00717                                   const X_monotone_curve_2 & xcv,
00718                                   Arr_curve_end ce) const
00719     {
00720       return m_base->compare_x_near_boundary_2_object()(p.base(),
00721                                                         xcv.base(), ce);
00722     }
00723 
00724     Comparison_result operator()(const X_monotone_curve_2 & xcv1,
00725                                  Arr_curve_end ce1,
00726                                  const X_monotone_curve_2 & xcv2,
00727                                  Arr_curve_end ce2) const
00728     {
00729       return m_base->compare_x_near_boundary_2_object()(xcv1.base(), ce1,
00730                                                         xcv2.base(), ce2);
00731     }
00732   };
00733 
00735   Compare_x_near_boundary_2 compare_x_near_boundary_2_object () const
00736   {
00737     return Compare_x_near_boundary_2(m_base_traits);
00738   }
00739 
00743   class Compare_x_on_boundary_2 {
00744   protected:
00746     const Base_traits_2 * m_base;
00747 
00755     Compare_x_on_boundary_2(const Base_traits_2 * tr) : m_base(tr) {}
00756 
00758     friend class Arr_batched_point_location_traits_2<Arrangement_2>;
00759 
00760   public:
00761     Comparison_result operator()(const Point_2 & p1, const Point_2 & p2) const
00762     {
00763       return m_base->compare_x_on_boundary_2_object()(p1.base(), p2.base());
00764     }
00765   };
00766 
00768   Compare_x_on_boundary_2 compare_x_on_boundary_2_object () const
00769   {
00770     return Compare_x_on_boundary_2(m_base_traits);
00771   }
00772   
00773   // TODO Is_on_y_identification_2
00774 
00775 };
00776 
00777 CGAL_END_NAMESPACE
00778 
00779 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines