BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Boolean_set_operations_2/Gps_traits_adaptor.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/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_traits_adaptor.h $
00015 // $Id: Gps_traits_adaptor.h 50373 2009-07-05 14:44:48Z efif $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 
00020 #ifndef CGAL_GPS_TRAITS_ADAPTOR_H
00021 #define CGAL_GPS_TRAITS_ADAPTOR_H
00022 
00023 CGAL_BEGIN_NAMESPACE
00024 
00025 template <class Traits_>
00026 class Gps_traits_adaptor : public Traits_
00027 {
00028   typedef Traits_                     Base;
00029   typedef Gps_traits_adaptor<Base>    Self;
00030 
00031 public:
00032   typedef typename Base::X_monotone_curve_2      X_monotone_curve_2;
00033   typedef typename Base::Point_2                 Point_2;
00034   typedef typename Base::Compare_xy_2            Compare_xy_2;
00035   typedef typename Base::Compare_y_at_x_right_2  Compare_y_at_x_right_2;
00036   typedef typename Base::Compare_endpoints_xy_2  Compare_endpoints_xy_2;
00037   typedef typename Base::Construct_min_vertex_2  Construct_min_vertex_2;
00038   typedef typename Base::Construct_max_vertex_2  Construct_max_vertex_2;
00039 
00041   Gps_traits_adaptor () : Base()
00042   {}
00043 
00045   Gps_traits_adaptor (const Base& traits) : Base (traits)
00046   {}
00047 
00048   class Construct_vertex_2 
00049   {
00050   public:
00051     Point_2 operator()(const X_monotone_curve_2& cv, int i) const
00052     {
00053       Base tr;
00054       Compare_endpoints_xy_2 cmp_endpoints = 
00055         tr.compare_endpoints_xy_2_object();
00056       Construct_min_vertex_2 ctr_min_v = tr.construct_min_vertex_2_object();
00057       Construct_max_vertex_2 ctr_max_v = tr.construct_max_vertex_2_object();
00058       i %= 2;
00059       if (i==0)
00060       {
00061         // return the source
00062         if(cmp_endpoints(cv) == SMALLER)
00063           return (ctr_min_v(cv));
00064         
00065         return (ctr_max_v(cv));
00066       }
00067 
00068       // else i==1 (return the target)
00069       if(cmp_endpoints(cv) == SMALLER)
00070         return (ctr_max_v(cv));
00071       
00072       return (ctr_min_v(cv));
00073     }
00074   };
00075 
00076   Construct_vertex_2 construct_vertex_2_object() const
00077   {
00078     return Construct_vertex_2();
00079   }
00080 
00081   class Orientation_2
00082   {
00083   public:
00084     template <class CurveInputIteraor>
00085     Orientation operator()(CurveInputIteraor begin,
00086                            CurveInputIteraor end) const
00087     {
00088       Self tr;
00089       Compare_xy_2 cmp_xy = tr.compare_xy_2_object();
00090       Compare_y_at_x_right_2 cmp_y_at_x_right = 
00091         tr.compare_y_at_x_right_2_object();
00092       Construct_vertex_2 ctr_v = tr.construct_vertex_2_object();
00093 
00094       CurveInputIteraor from_left_most = begin;
00095       CurveInputIteraor into_left_most = end;
00096 
00097       Point_2 left_most_v = ctr_v(*from_left_most, 0);
00098       
00099       --into_left_most;
00100 
00101       CurveInputIteraor ci = from_left_most;
00102 
00103       for(++ci ; ci != end; ++ci)
00104       {
00105         Comparison_result res_xy = cmp_xy( ctr_v(*ci, 0), left_most_v);
00106         if(res_xy == LARGER)
00107           continue;
00108         if(res_xy == SMALLER)
00109         {
00110           left_most_v =  ctr_v(*ci, 0);
00111           from_left_most = into_left_most = ci;
00112           --into_left_most;
00113         }
00114         else
00115         {
00116           // res_xy == EQUAL
00117           CurveInputIteraor tmp_from_left_most = ci;
00118           CurveInputIteraor tmp_into_left_most = ci;
00119           --tmp_into_left_most;
00120 
00121           Comparison_result res_from = cmp_y_at_x_right(*from_left_most,
00122                                                         *tmp_from_left_most,
00123                                                         left_most_v);
00124 
00125           Comparison_result res_to = cmp_y_at_x_right(*into_left_most, 
00126                                                       *tmp_into_left_most,
00127                                                       left_most_v);
00128           
00129           CGAL_assertion(res_from != EQUAL && res_to != EQUAL);
00130           if(res_from == LARGER && res_to == SMALLER)
00131           {
00132             if(cmp_y_at_x_right(*tmp_from_left_most,
00133                                 *into_left_most,
00134                                 left_most_v) == LARGER)
00135             {
00136               from_left_most = tmp_from_left_most;
00137               into_left_most = tmp_into_left_most;
00138             }
00139           }
00140           else
00141             if(res_from == SMALLER && res_to == LARGER)
00142             {
00143               if(cmp_y_at_x_right(*tmp_into_left_most,
00144                                   *from_left_most,
00145                                   left_most_v) == LARGER)
00146               {
00147                 from_left_most = tmp_from_left_most;
00148                 into_left_most = tmp_into_left_most;
00149               }
00150             }
00151         }
00152       }// end for
00153       Comparison_result res = cmp_y_at_x_right(*into_left_most, 
00154                                               *from_left_most,
00155                                               left_most_v);
00156       CGAL_assertion(res != EQUAL);
00157       if(res == SMALLER)
00158         return (CLOCKWISE);
00159       return (COUNTERCLOCKWISE);
00160     }
00161   };
00162 
00163   Orientation_2 orientation_2_object() const
00164   {
00165     return Orientation_2();
00166   }
00167 };
00168 
00169 CGAL_END_NAMESPACE
00170 
00171 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines