BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Circular_kernel_3/internal_functions_on_circular_arc_point_3.h
Go to the documentation of this file.
00001 // Copyright (c) 2008  INRIA Sophia-Antipolis (France).
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/Circular_kernel_3/include/CGAL/Circular_kernel_3/internal_functions_on_circular_arc_point_3.h $
00015 // $Id: internal_functions_on_circular_arc_point_3.h 50731 2009-07-21 09:08:07Z sloriot $
00016 //
00017 // Author(s) : Monique Teillaud, Sylvain Pion, Pedro Machado, 
00018 //             Sebastien Loriot, Julien Hazebrouck, Damien Leroy
00019 
00020 // Partially supported by the IST Programme of the EU as a 
00021 // STREP (FET Open) Project under Contract No  IST-006413 
00022 // (ACS -- Algorithms for Complex Shapes)
00023 
00024 #ifndef CGAL_SPHERICAL_KERNEL_PREDICATES_ON_CIRCULAR_ARC_POINT_3_H
00025 #define CGAL_SPHERICAL_KERNEL_PREDICATES_ON_CIRCULAR_ARC_POINT_3_H
00026 
00027 namespace CGAL {
00028   namespace SphericalFunctors {
00029 
00030     template< class SK>
00031     bool
00032       equal( const typename SK::Circular_arc_point_3 &p1,
00033              const typename SK::Circular_arc_point_3 &p2)
00034     {
00035       return p1.rep() == p2.rep();
00036     }
00037         
00038 
00039   //compute the half_quadrant relative to the cylindrical coordinate system defined by sphere of pt
00040   template<class SK>
00041   float half_quadrant(const typename SK::Root_of_2& Rx,
00042                       const typename SK::Root_of_2& Ry)
00043   {
00044     int x=CGAL_NTS sign(Rx);
00045     int y=CGAL_NTS sign(Ry);
00046     if (y>0){
00047       if (x>0)  switch (CGAL_NTS sign(Rx-Ry)){case -1: return 2; case 0: return 1.5; case 1: return 1; }; 
00048       if (x<0) switch (CGAL::opposite(CGAL_NTS sign(Rx+Ry))){case -1: return 3; case 0: return 3.5; case 1: return 4; };
00049       return 2.5;//OPTI : we have more information here by x_y
00050     }
00051     else{
00052       if (y<0){
00053         if (x>0) switch (CGAL_NTS sign(Rx+Ry)){case -1: return 7; case 0: return 7.5; case 1: return 8; };
00054         if (x<0) switch (CGAL::opposite(CGAL_NTS sign(Rx-Ry))){case -1: return 6; case 0: return 5.5; case 1: return 5; };
00055         return 6.5;//OPTI : we have more information here by x_y
00056       }
00057       else{
00058         if (x>0)  return 0.5;
00059         if (x<0) return 4.5;
00060         return 0;
00061       }
00062     }
00063   }    
00064     
00065 
00066   template<class SK>
00067   inline
00068   float half_quadrant(const typename SK::Circular_arc_point_3& pt,
00069                       const typename SK::Sphere_3& sphere)
00070   {
00071     typename SK::Root_of_2 Rx=pt.x()-sphere.center().x();
00072     typename SK::Root_of_2 Ry=pt.y()-sphere.center().y();
00073     return half_quadrant<SK>(Rx,Ry);
00074   }
00075   
00076   template<class SK>
00077   bool is_hquadrant_a_tangent(float hq){
00078     if (hq >7 || hq<2 || (hq>3 && hq<6))
00079       return true;
00080     return false;
00081   }
00082   
00083   template <class SK>
00084   CGAL::Comparison_result compare_theta_of_pts(const typename SK::Circular_arc_point_3& pt1,
00085                                                const typename SK::Circular_arc_point_3& pt2,
00086                                                const typename SK::Sphere_3& sphere)
00087   {
00088     CGAL_kernel_precondition( (pt1.x()!=sphere.center().x() || pt1.y()!=sphere.center().x()) && 
00089                               (pt2.x()!=sphere.center().x() || pt2.y()!=sphere.center().x()) );
00090     float hq1=half_quadrant<SK>(pt1,sphere);
00091     float hq2=half_quadrant<SK>(pt2,sphere);
00092     CGAL::Sign res=CGAL_NTS sign(hq1-hq2);
00093     if (res == CGAL::EQUAL){//same quadrant 
00094       if (floor(hq1)!=hq1)//for hquadrant boundary
00095         res=CGAL::EQUAL;
00096       else{
00097         //compare tan or cot, same expression due to constant sign within a hquadrant
00098         //and different monotonicity type of tan and cot
00099         if ( is_hquadrant_a_tangent<SK>(hq1) )
00100           res= CGAL_NTS compare( (pt1.y() - sphere.center().y()) / (pt1.x() - sphere.center().x()) ,
00101                               (pt2.y() - sphere.center().y()) / (pt2.x() - sphere.center().x()) ); 
00102         else
00103           res= CGAL_NTS compare( (pt2.x() - sphere.center().x()) / (pt2.y() - sphere.center().y()) ,
00104                               (pt1.x() - sphere.center().x()) / (pt1.y() - sphere.center().y()) );          
00105       }
00106     }
00107     return res;
00108   }
00109 
00110   template <class SK>
00111   CGAL::Comparison_result compare_theta_pt_vector(const typename SK::Circular_arc_point_3& pt,
00112                                                   const typename SK::Vector_3& v,
00113                                                   const typename SK::Sphere_3& sphere)
00114   {
00115     CGAL_kernel_precondition( (pt.x()!=sphere.center().x() || pt.y()!=sphere.center().x()) && 
00116                               (v.x()!=0 || v.y()!=0) &&  v.z()==0);
00117     float hq1=half_quadrant<SK>(pt,sphere);
00118     float hq2=half_quadrant<SK>(v.x(),v.y());
00119     CGAL::Sign res=CGAL_NTS sign(hq1-hq2);
00120     if (res == CGAL::EQUAL){//same quadrant 
00121       if (floor(hq1)!=hq1)//for hquadrant boundary
00122         res=CGAL::EQUAL;
00123       else{
00124         //compare tan or cot, same expression due to constant sign within a hquadrant
00125         //and different monotonicity type of tan and cot
00126         res= CGAL_NTS compare( v.x() * (pt.y() - sphere.center().y()) ,
00127                             v.y() * (pt.x() - sphere.center().x())  ); 
00128       }
00129     }
00130     return res;
00131   }
00132 
00133   template <class SK>
00134   CGAL::Comparison_result compare_theta_vectors(const typename SK::Vector_3& m1,
00135                                                 const typename SK::Vector_3& m2
00136                                                )
00137   {
00138     CGAL_kernel_precondition( (m1.x()!=0 || m1.y()!=0) &&  m1.z()==0 &&  
00139                              (m2.x()!=0 || m2.y()!=0) &&  m2.z()==0 );
00140     float hq1=half_quadrant<SK>(m1.x(),m1.y());
00141     float hq2=half_quadrant<SK>(m2.x(),m2.y());
00142     CGAL::Sign res=CGAL_NTS sign(hq1-hq2);
00143     if (res == CGAL::EQUAL){//same quadrant 
00144       if (floor(hq1)!=hq1)//for hquadrant boundary
00145         res=CGAL::EQUAL;
00146       else{
00147         //compare tan or cot, same expression due to constant sign within a hquadrant
00148         //and different monotonicity type of tan and cot
00149         res= CGAL_NTS compare( m2.x() * m1.y() ,
00150                             m2.y() * m1.x() ); 
00151       }
00152     }
00153     return res;
00154   }
00155   
00156   template <class SK>
00157   CGAL::Comparison_result compare_theta_z(const typename SK::Circular_arc_point_3& pt1,
00158                                           const typename SK::Circular_arc_point_3& pt2,
00159                                           const typename SK::Sphere_3& sphere,
00160                                           bool decreasing_z=false)
00161   {
00162     CGAL::Comparison_result res=compare_theta_of_pts<SK>(pt1,pt2,sphere);
00163     if (res==CGAL::EQUAL)
00164       res = (decreasing_z?(CGAL::opposite(SK().compare_z_3_object()(pt1,pt2))):(SK().compare_z_3_object()(pt1,pt2)));
00165     return res;
00166   }  
00167     
00168   }//SphericalFunctors
00169 }//CGAL
00170 
00171 #endif //CGAL_SPHERICAL_KERNEL_PREDICATES_ON_CIRCULAR_ARC_POINT_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines