BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Segment_Delaunay_graph_2/Orientation_C2.h
Go to the documentation of this file.
00001 // Copyright (c) 2003,2004,2005,2006  INRIA Sophia-Antipolis (France) and
00002 // Notre Dame University (U.S.A.).  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/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Orientation_C2.h $
00015 // $Id: Orientation_C2.h 44317 2008-07-22 12:29:01Z spion $
00016 // 
00017 //
00018 // Author(s)     : Menelaos Karavelas <mkaravel@cse.nd.edu>
00019 
00020 
00021 
00022 #ifndef CGAL_SEGMENT_DELAUNAY_GRAPH_2_ORIENTATION_C2_H
00023 #define CGAL_SEGMENT_DELAUNAY_GRAPH_2_ORIENTATION_C2_H
00024 
00025 #include <CGAL/Segment_Delaunay_graph_2/Basic_predicates_C2.h>
00026 #include <CGAL/Segment_Delaunay_graph_2/Are_same_points_C2.h>
00027 #include <CGAL/Segment_Delaunay_graph_2/Are_same_segments_C2.h>
00028 
00029 CGAL_BEGIN_NAMESPACE
00030 
00031 CGAL_SEGMENT_DELAUNAY_GRAPH_2_BEGIN_NAMESPACE
00032 
00033 //-----------------------------------------------------------------------------
00034 
00035 
00036 
00037 template<class K>
00038 class Orientation_C2
00039   : private Basic_predicates_C2<K>
00040 {
00041 private:
00042   typedef Basic_predicates_C2<K>              Base;
00043   
00044 public:
00045   typedef typename Base::Orientation          Orientation;
00046 
00047 private:
00048   typedef typename Base::Point_2              Point_2;
00049   typedef typename Base::Segment_2            Segment_2;
00050   typedef typename Base::Site_2               Site_2;
00051   typedef typename Base::FT                   FT;
00052   typedef typename Base::RT                   RT;
00053 
00054   typedef typename Base::Comparison_result    Comparison_result;
00055   typedef typename Base::Oriented_side        Oriented_side;
00056   typedef typename Base::Sign                 Sign;
00057 
00058   typedef typename K::Kernel::Orientation_2   Orientation_2;
00059   typedef Are_same_points_C2<K>               Are_same_points_2;
00060   typedef Are_same_segments_C2<K>             Are_same_segments_2;
00061 
00062   typedef typename K::Intersections_tag       ITag;
00063 
00064   Are_same_points_2    same_points;
00065   Are_same_segments_2  same_segments;
00066 
00067   bool have_common_support(const Site_2& p, const Site_2& q) const
00068   {
00069     CGAL_precondition( !p.is_input() && !q.is_input() );
00070 
00071     return
00072       same_segments(p.supporting_site(0), q.supporting_site(0)) ||
00073       same_segments(p.supporting_site(0), q.supporting_site(1)) ||
00074       same_segments(p.supporting_site(1), q.supporting_site(0)) ||
00075       same_segments(p.supporting_site(1), q.supporting_site(1));
00076   }
00077 
00078   bool have_common_support(const Site_2& p, const Site_2& q,
00079                            Site_2& support) const
00080   {
00081     CGAL_precondition( !p.is_input() && !q.is_input() );
00082 
00083     if ( same_segments(p.supporting_site(0),
00084                        q.supporting_site(0)) ||
00085          same_segments(p.supporting_site(0),
00086                        q.supporting_site(1)) ) {
00087       support = p.supporting_site(0);
00088       return true;
00089     } else if ( same_segments(p.supporting_site(1),
00090                               q.supporting_site(0)) ||
00091                 same_segments(p.supporting_site(1),
00092                               q.supporting_site(1)) ) {
00093       support =  p.supporting_site(1);
00094       return true;
00095     }
00096     return false;
00097   }
00098 
00099   bool is_endpoint(const Site_2& p, const Site_2& s) const
00100   {
00101     return same_points(s.source_site(), p) ||
00102       same_points(s.target_site(), p);
00103   }
00104 
00105   //-------------------------------------------------------------
00106 
00107   Orientation predicate(const Site_2& p, const Site_2& q,
00108                         const Site_2& r, const Tag_false&) const
00109   {
00110     return Orientation_2()(p.point(), q.point(), r.point());
00111   }
00112 
00113   Orientation predicate(const Site_2& p, const Site_2& q,
00114                         const Site_2& r, const Tag_true&) const
00115   {
00116 #if 1
00117     // do geometric filtering
00118     bool pe = p.is_input();
00119     bool qe = q.is_input();
00120     bool re = r.is_input();
00121     Site_2 support;
00122     if ( !pe && !qe && !re ) {
00123       if ( have_common_support(p, q, support) &&
00124            have_common_support(support, r) ) {
00125         return COLLINEAR;
00126       }
00127     } else if ( !pe && !qe ) {
00128       if ( have_common_support(p, q, support) &&
00129            is_endpoint(r, support) ) {
00130         return COLLINEAR;
00131       }
00132     } else if ( !pe && !re ) {
00133       if ( have_common_support(p, r, support) &&
00134            is_endpoint(q, support) ) {
00135         return COLLINEAR;
00136       }
00137     } else if ( !qe && !re ) {
00138       if ( have_common_support(q, r, support) &&
00139            is_endpoint(p, support) ) {
00140         return COLLINEAR;
00141       }
00142     } else if ( !pe ) {
00143       Site_2 s0 = p.supporting_site(0);
00144       Site_2 s1 = p.supporting_site(1);
00145       if ( (is_endpoint(q, s0) && is_endpoint(r, s0)) ||
00146            (is_endpoint(q, s1) && is_endpoint(r, s1)) ) {
00147         return COLLINEAR;
00148       }
00149     } else if ( !qe ) {
00150       Site_2 s0 = q.supporting_site(0);
00151       Site_2 s1 = q.supporting_site(1);
00152       if ( (is_endpoint(p, s0) && is_endpoint(r, s0)) ||
00153            (is_endpoint(p, s1) && is_endpoint(r, s1)) ) {
00154         return COLLINEAR;
00155       }
00156     } else if ( !re ) {
00157       Site_2 s0 = r.supporting_site(0);
00158       Site_2 s1 = r.supporting_site(1);
00159       if ( (is_endpoint(q, s0) && is_endpoint(p, s0)) ||
00160            (is_endpoint(q, s1) && is_endpoint(p, s1)) ) {
00161         return COLLINEAR;
00162       }
00163     }
00164 #endif
00165 
00166     return predicate(p, q, r, Tag_false());
00167   }
00168 
00169 public:
00170   typedef Orientation                  result_type;
00171   typedef Site_2                       argument_type;
00172 
00173   Orientation operator()(const Site_2& p, const Site_2& q,
00174                          const Site_2& r) const
00175   {
00176     CGAL_precondition( p.is_point() && q.is_point() && r.is_point() );
00177 
00178     return predicate(p, q, r, ITag());
00179   }
00180 };
00181 
00182 
00183 //-----------------------------------------------------------------------------
00184 
00185 CGAL_SEGMENT_DELAUNAY_GRAPH_2_END_NAMESPACE
00186 
00187 CGAL_END_NAMESPACE
00188 
00189 #endif // CGAL_SEGMENT_DELAUNAY_GRAPH_2_ORIENTATION_C2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines