BWAPI
|
00001 // Copyright (c) 1998 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Distance_2/include/CGAL/squared_distance_utils.h $ 00019 // $Id: squared_distance_utils.h 42823 2008-04-09 20:57:58Z spion $ 00020 // 00021 // 00022 // Author(s) : Geert-Jan Giezeman 00023 00024 00025 #ifndef CGAL_SQUARED_DISTANCE_UTILS_H 00026 #define CGAL_SQUARED_DISTANCE_UTILS_H 00027 00028 #include <CGAL/determinant.h> 00029 #include <CGAL/wmult.h> 00030 00031 CGAL_BEGIN_NAMESPACE 00032 00033 namespace CGALi { 00034 00035 template <class K> 00036 bool is_null(const typename K::Vector_2 &v, const K&) 00037 { 00038 typedef typename K::RT RT; 00039 return v.hx()==RT(0) && v.hy()==RT(0); 00040 } 00041 00042 00043 template <class K> 00044 typename K::RT 00045 wdot(const typename K::Vector_2 &u, 00046 const typename K::Vector_2 &v, 00047 const K&) 00048 { 00049 return (u.hx()*v.hx() + u.hy()*v.hy()); 00050 } 00051 00052 00053 00054 template <class K> 00055 typename K::RT wdot_tag(const typename K::Point_2 &p, 00056 const typename K::Point_2 &q, 00057 const typename K::Point_2 &r, 00058 const K&, 00059 const Cartesian_tag&) 00060 { 00061 return (p.x() - q.x()) * (r.x() - q.x()) 00062 + (p.y() - q.y()) * (r.y() - q.y()); 00063 } 00064 00065 00066 template <class K> 00067 typename K::RT wdot_tag(const typename K::Point_2 &p, 00068 const typename K::Point_2 &q, 00069 const typename K::Point_2 &r, 00070 const K&, 00071 const Homogeneous_tag&) 00072 { 00073 return (p.hx() * q.hw() - q.hx() * p.hw()) 00074 * (r.hx() * q.hw() - q.hx() * r.hw()) 00075 + (p.hy() * q.hw() - q.hy() * p.hw()) 00076 * (r.hy() * q.hw() - q.hy() * r.hw()); 00077 } 00078 00079 00080 template <class K> 00081 typename K::RT wdot(const typename K::Point_2 &p, 00082 const typename K::Point_2 &q, 00083 const typename K::Point_2 &r, 00084 const K& k) 00085 { 00086 typedef typename K::Kernel_tag Tag; 00087 Tag tag; 00088 return wdot_tag(p, q, r, k, tag); 00089 } 00090 00091 00092 00093 template <class K> 00094 typename K::RT 00095 wcross(const typename K::Vector_2 &u, 00096 const typename K::Vector_2 &v, 00097 const K&) 00098 { 00099 return (typename K::RT)(u.hx()*v.hy() - u.hy()*v.hx()); 00100 } 00101 00102 00103 00104 template <class K> 00105 inline 00106 typename K::RT 00107 wcross_tag(const typename K::Point_2 &p, 00108 const typename K::Point_2 &q, 00109 const typename K::Point_2 &r, 00110 const K&, 00111 const Homogeneous_tag&) 00112 { 00113 return CGAL::determinant( 00114 p.hx(), q.hx(), r.hx(), 00115 p.hy(), q.hy(), r.hy(), 00116 p.hw(), q.hw(), r.hw()); 00117 } 00118 00119 00120 00121 template <class K> 00122 inline 00123 typename K::FT 00124 wcross_tag(const typename K::Point_2 &p, 00125 const typename K::Point_2 &q, 00126 const typename K::Point_2 &r, 00127 const K&, 00128 const Cartesian_tag&) 00129 { 00130 return (q.x()-p.x())*(r.y()-q.y()) - (q.y()-p.y())*(r.x()-q.x()); 00131 } 00132 00133 00134 template <class K> 00135 typename K::RT wcross(const typename K::Point_2 &p, 00136 const typename K::Point_2 &q, 00137 const typename K::Point_2 &r, 00138 const K& k) 00139 { 00140 typedef typename K::Kernel_tag Tag; 00141 Tag tag; 00142 return wcross_tag(p, q, r, k, tag); 00143 00144 } 00145 00146 00147 00148 template <class K> 00149 inline bool is_acute_angle(const typename K::Vector_2 &u, 00150 const typename K::Vector_2 &v, 00151 const K& k) 00152 { 00153 typedef typename K::RT RT; 00154 return RT(wdot(u, v, k)) > RT(0) ; 00155 } 00156 00157 template <class K> 00158 inline bool is_straight_angle(const typename K::Vector_2 &u, 00159 const typename K::Vector_2 &v, 00160 const K& k) 00161 { 00162 typedef typename K::RT RT; 00163 return RT(wdot(u, v, k)) == RT(0) ; 00164 } 00165 00166 template <class K> 00167 inline bool is_obtuse_angle(const typename K::Vector_2 &u, 00168 const typename K::Vector_2 &v, 00169 const K& k) 00170 { 00171 typedef typename K::RT RT; 00172 return RT(wdot(u, v, k)) < RT(0) ; 00173 } 00174 00175 template <class K> 00176 inline bool is_acute_angle(const typename K::Point_2 &p, 00177 const typename K::Point_2 &q, 00178 const typename K::Point_2 &r, 00179 const K& k) 00180 { 00181 typedef typename K::RT RT; 00182 return RT(wdot(p, q, r, k)) > RT(0) ; 00183 } 00184 00185 template <class K> 00186 inline bool is_straight_angle(const typename K::Point_2 &p, 00187 const typename K::Point_2 &q, 00188 const typename K::Point_2 &r, 00189 const K& k) 00190 { 00191 typedef typename K::RT RT; 00192 return RT(wdot(p, q, r, k)) == RT(0) ; 00193 } 00194 00195 template <class K> 00196 inline bool is_obtuse_angle(const typename K::Point_2 &p, 00197 const typename K::Point_2 &q, 00198 const typename K::Point_2 &r, 00199 const K& k) 00200 { 00201 typedef typename K::RT RT; 00202 return RT(wdot(p, q, r, k)) < RT(0) ; 00203 } 00204 00205 template <class K> 00206 inline bool counterclockwise(const typename K::Vector_2 &u, 00207 const typename K::Vector_2 &v, 00208 const K& k) 00209 { 00210 typedef typename K::RT RT; 00211 return RT(wcross(u,v, k)) > RT(0); 00212 } 00213 00214 template <class K> 00215 inline bool left_turn(const typename K::Vector_2 &u, 00216 const typename K::Vector_2 &v, 00217 const K& k) 00218 { 00219 typedef typename K::RT RT; 00220 return RT(wcross(u,v, k)) > RT(0); 00221 } 00222 00223 template <class K> 00224 inline bool clockwise(const typename K::Vector_2 &u, 00225 const typename K::Vector_2 &v, 00226 const K& k) 00227 { 00228 typedef typename K::RT RT; 00229 return RT(wcross(u,v, k)) < RT(0); 00230 } 00231 00232 template <class K> 00233 inline bool right_turn(const typename K::Vector_2 &u, 00234 const typename K::Vector_2 &v, 00235 const K& k) 00236 { 00237 typedef typename K::RT RT; 00238 return RT(wcross(u,v, k)) < RT(0); 00239 } 00240 00241 template <class K> 00242 inline bool collinear(const typename K::Vector_2 &u, 00243 const typename K::Vector_2 &v, 00244 const K& k) 00245 { 00246 typedef typename K::RT RT; 00247 return RT(wcross(u,v, k)) == RT(0); 00248 } 00249 00250 /* 00251 the ordertype, right_turn, left_turn and collinear routines for points are 00252 defined elsewhere. 00253 */ 00254 template <class K> 00255 inline 00256 bool 00257 same_direction_tag(const typename K::Vector_2 &u, 00258 const typename K::Vector_2 &v, 00259 const K&, 00260 const Cartesian_tag&) 00261 { 00262 typedef typename K::FT FT; 00263 const FT& ux = u.x(); 00264 const FT& uy = u.y(); 00265 if (CGAL_NTS abs(ux) > CGAL_NTS abs(uy)) { 00266 return CGAL_NTS sign(ux) == CGAL_NTS sign(v.x()); 00267 } else { 00268 return CGAL_NTS sign(uy) == CGAL_NTS sign(v.y()); 00269 } 00270 } 00271 00272 00273 template <class K> 00274 inline 00275 bool 00276 same_direction_tag(const typename K::Vector_2 &u, 00277 const typename K::Vector_2 &v, 00278 const K&, 00279 const Homogeneous_tag&) 00280 { 00281 typedef typename K::RT RT; 00282 const RT& uhx = u.hx(); 00283 const RT& uhy = u.hy(); 00284 if (CGAL_NTS abs(uhx) > CGAL_NTS abs(uhy)) { 00285 return CGAL_NTS sign(uhx) == CGAL_NTS sign(v.hx()); 00286 } else { 00287 return CGAL_NTS sign(uhy) == CGAL_NTS sign(v.hy()); 00288 } 00289 } 00290 00291 00292 template <class K> 00293 inline 00294 bool 00295 same_direction(const typename K::Vector_2 &u, 00296 const typename K::Vector_2 &v, 00297 const K& k) 00298 { 00299 typedef typename K::Kernel_tag Tag; 00300 Tag tag; 00301 return same_direction_tag(u,v, k, tag); 00302 } 00303 00304 00305 } // namespace CGALi 00306 00307 CGAL_END_NAMESPACE 00308 00309 #endif // CGAL_SQUARED_DISTANCE_UTILS_H