BWAPI
|
00001 // Copyright (c) 1999 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/Homogeneous_kernel/include/CGAL/Homogeneous/distance_predicatesH3.h $ 00019 // $Id: distance_predicatesH3.h 29102 2006-03-06 23:51:27Z spion $ 00020 // 00021 // 00022 // Author(s) : Stefan Schirra 00023 00024 00025 #ifndef CGAL_DISTANCE_PREDICATESH3_H 00026 #define CGAL_DISTANCE_PREDICATESH3_H 00027 00028 CGAL_BEGIN_NAMESPACE 00029 00030 template <class R> 00031 Comparison_result 00032 compare_distance_to_point(const PointH3<R>& , 00033 const PointH3<R>& , 00034 const PointH3<R>& ); 00035 00036 template <class R> 00037 bool 00038 has_larger_distance_to_point(const PointH3<R>& , 00039 const PointH3<R>& , 00040 const PointH3<R>& ); 00041 00042 template <class R> 00043 bool 00044 has_smaller_distance_to_point(const PointH3<R>& , 00045 const PointH3<R>& , 00046 const PointH3<R>& ); 00047 00048 template <class R> 00049 Comparison_result 00050 compare_signed_distance_to_plane(const PlaneH3<R>& , 00051 const PointH3<R>& , 00052 const PointH3<R>& ); 00053 00054 template <class R> 00055 bool 00056 has_larger_signed_distance_to_plane(const PlaneH3<R>& , 00057 const PointH3<R>& , 00058 const PointH3<R>& ); 00059 00060 template <class R> 00061 bool 00062 has_smaller_signed_distance_to_plane(const PlaneH3<R>&, 00063 const PointH3<R>& , 00064 const PointH3<R>& ); 00065 00066 template <class R> 00067 Comparison_result 00068 compare_signed_distance_to_plane(const PointH3<R>& , 00069 const PointH3<R>& , 00070 const PointH3<R>& , 00071 const PointH3<R>& , 00072 const PointH3<R>& ); 00073 00074 template <class R> 00075 bool 00076 has_larger_signed_distance_to_plane(const PointH3<R>& , 00077 const PointH3<R>& , 00078 const PointH3<R>& , 00079 const PointH3<R>& , 00080 const PointH3<R>& ); 00081 00082 template <class R> 00083 bool 00084 has_smaller_signed_distance_to_plane(const PointH3<R>& , 00085 const PointH3<R>& , 00086 const PointH3<R>& , 00087 const PointH3<R>& , 00088 const PointH3<R>& ); 00089 00090 template <class R> 00091 CGAL_KERNEL_MEDIUM_INLINE 00092 Comparison_result 00093 compare_distance_to_point(const PointH3<R>& p, 00094 const PointH3<R>& q, 00095 const PointH3<R>& r) 00096 { 00097 typedef typename R::RT RT; 00098 00099 const RT phx = p.hx(); 00100 const RT phy = p.hy(); 00101 const RT phz = p.hz(); 00102 const RT phw = p.hw(); 00103 const RT qhx = q.hx(); 00104 const RT qhy = q.hy(); 00105 const RT qhz = q.hz(); 00106 const RT qhw = q.hw(); 00107 const RT rhx = r.hx(); 00108 const RT rhy = r.hy(); 00109 const RT rhz = r.hz(); 00110 const RT rhw = r.hw(); 00111 const RT RT0 = RT(0); 00112 const RT RT2 = RT(2); 00113 00114 RT dosd = // difference of squared distances 00115 00116 rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz ) 00117 - RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz ) 00118 ) 00119 - qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz ) 00120 - RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz ) 00121 ); 00122 00123 if ( RT0 < dosd ) 00124 { return LARGER; } 00125 else 00126 { return (dosd < RT0) ? SMALLER : EQUAL; } 00127 } 00128 00129 template < class R> 00130 CGAL_KERNEL_MEDIUM_INLINE 00131 bool 00132 has_larger_distance_to_point(const PointH3<R>& p, 00133 const PointH3<R>& q, 00134 const PointH3<R>& r) 00135 { 00136 typedef typename R::RT RT; 00137 00138 const RT phx = p.hx(); 00139 const RT phy = p.hy(); 00140 const RT phz = p.hz(); 00141 const RT phw = p.hw(); 00142 const RT qhx = q.hx(); 00143 const RT qhy = q.hy(); 00144 const RT qhz = q.hz(); 00145 const RT qhw = q.hw(); 00146 const RT rhx = r.hx(); 00147 const RT rhy = r.hy(); 00148 const RT rhz = r.hz(); 00149 const RT rhw = r.hw(); 00150 const RT RT0 = RT(0); 00151 const RT RT2 = RT(2); 00152 00153 RT dosd = // difference of squared distances 00154 00155 rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz ) 00156 - RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz ) 00157 ) 00158 - qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz ) 00159 - RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz ) 00160 ); 00161 00162 return ( RT0 < dosd ); 00163 } 00164 00165 template < class R> 00166 CGAL_KERNEL_MEDIUM_INLINE 00167 bool 00168 has_smaller_distance_to_point(const PointH3<R>& p, 00169 const PointH3<R>& q, 00170 const PointH3<R>& r) 00171 { 00172 typedef typename R::RT RT; 00173 00174 const RT phx = p.hx(); 00175 const RT phy = p.hy(); 00176 const RT phz = p.hz(); 00177 const RT phw = p.hw(); 00178 const RT qhx = q.hx(); 00179 const RT qhy = q.hy(); 00180 const RT qhz = q.hz(); 00181 const RT qhw = q.hw(); 00182 const RT rhx = r.hx(); 00183 const RT rhy = r.hy(); 00184 const RT rhz = r.hz(); 00185 const RT rhw = r.hw(); 00186 const RT RT0 = RT(0); 00187 const RT RT2 = RT(2); 00188 00189 RT dosd = // difference of squared distances 00190 00191 rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz ) 00192 - RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz ) 00193 ) 00194 - qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz ) 00195 - RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz ) 00196 ); 00197 00198 return ( dosd < RT0 ); 00199 } 00200 00201 template < class R> 00202 CGAL_KERNEL_INLINE 00203 Comparison_result 00204 compare_signed_distance_to_plane(const PlaneH3<R>& pl, 00205 const PointH3<R>& p, 00206 const PointH3<R>& q) 00207 { 00208 typedef typename R::RT RT; 00209 00210 const RT pla = pl.a(); 00211 const RT plb = pl.b(); 00212 const RT plc = pl.c(); 00213 const RT phx = p.hx(); 00214 const RT phy = p.hy(); 00215 const RT phz = p.hz(); 00216 const RT phw = p.hw(); 00217 const RT qhx = q.hx(); 00218 const RT qhy = q.hy(); 00219 const RT qhz = q.hz(); 00220 const RT qhw = q.hw(); 00221 const RT RT0 = RT(0); 00222 00223 RT scaled_dist_p_minus_scaled_dist_q = 00224 pla*( phx*qhw - qhx*phw ) 00225 + plb*( phy*qhw - qhy*phw ) 00226 + plc*( phz*qhw - qhz*phw ); 00227 00228 00229 00230 if ( scaled_dist_p_minus_scaled_dist_q < RT0 ) 00231 { return SMALLER; } 00232 else 00233 { return (RT0 < scaled_dist_p_minus_scaled_dist_q ) ? LARGER : EQUAL;} 00234 } 00235 00236 template <class R> 00237 bool 00238 has_larger_signed_distance_to_plane(const PlaneH3<R>& pl, 00239 const PointH3<R>& p, 00240 const PointH3<R>& q ) 00241 { 00242 typedef typename R::RT RT; 00243 00244 const RT pla = pl.a(); 00245 const RT plb = pl.b(); 00246 const RT plc = pl.c(); 00247 const RT phx = p.hx(); 00248 const RT phy = p.hy(); 00249 const RT phz = p.hz(); 00250 const RT phw = p.hw(); 00251 const RT qhx = q.hx(); 00252 const RT qhy = q.hy(); 00253 const RT qhz = q.hz(); 00254 const RT qhw = q.hw(); 00255 const RT RT0 = RT(0); 00256 00257 RT scaled_dist_p_minus_scaled_dist_q = 00258 pla*( phx*qhw - qhx*phw ) 00259 + plb*( phy*qhw - qhy*phw ) 00260 + plc*( phz*qhw - qhz*phw ); 00261 00262 00263 return ( RT0 < scaled_dist_p_minus_scaled_dist_q ); 00264 } 00265 00266 template <class R> 00267 bool 00268 has_smaller_signed_distance_to_plane(const PlaneH3<R>& pl, 00269 const PointH3<R>& p, 00270 const PointH3<R>& q ) 00271 { 00272 typedef typename R::RT RT; 00273 00274 const RT pla = pl.a(); 00275 const RT plb = pl.b(); 00276 const RT plc = pl.c(); 00277 const RT phx = p.hx(); 00278 const RT phy = p.hy(); 00279 const RT phz = p.hz(); 00280 const RT phw = p.hw(); 00281 const RT qhx = q.hx(); 00282 const RT qhy = q.hy(); 00283 const RT qhz = q.hz(); 00284 const RT qhw = q.hw(); 00285 const RT RT0 = RT(0); 00286 00287 RT scaled_dist_p_minus_scaled_dist_q = 00288 pla*( phx*qhw - qhx*phw ) 00289 + plb*( phy*qhw - qhy*phw ) 00290 + plc*( phz*qhw - qhz*phw ); 00291 00292 00293 return ( scaled_dist_p_minus_scaled_dist_q < RT0 ); 00294 } 00295 00296 template <class R> 00297 inline 00298 Comparison_result 00299 compare_signed_distance_to_plane(const PointH3<R>& p, 00300 const PointH3<R>& q, 00301 const PointH3<R>& r, 00302 const PointH3<R>& s, 00303 const PointH3<R>& t) 00304 { 00305 CGAL_kernel_precondition( !collinear(p,q,r) ); 00306 PlaneH3<R> P(p,q,r); 00307 return cmp_signed_dist_to_plane( P, s, t); 00308 } 00309 00310 template <class R> 00311 inline 00312 bool 00313 has_larger_signed_distance_to_plane(const PointH3<R>& p, 00314 const PointH3<R>& q, 00315 const PointH3<R>& r, 00316 const PointH3<R>& s, 00317 const PointH3<R>& t) 00318 { return cmp_signed_dist_to_plane(p,q,r,s,t) == LARGER; } 00319 00320 00321 template <class R> 00322 inline 00323 bool 00324 has_smaller_signed_distance_to_plane(const PointH3<R>& p, 00325 const PointH3<R>& q, 00326 const PointH3<R>& r, 00327 const PointH3<R>& s, 00328 const PointH3<R>& t) 00329 { return cmp_signed_dist_to_plane(p,q,r,s,t) == SMALLER; } 00330 00331 CGAL_END_NAMESPACE 00332 00333 #endif //CGAL_DISTANCE_PREDICATESH3_H