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_predicatesH2.h $ 00019 // $Id: distance_predicatesH2.h 28567 2006-02-16 14:30:13Z lsaboret $ 00020 // 00021 // 00022 // Author(s) : Stefan Schirra 00023 00024 00025 #ifndef CGAL_DISTANCE_PREDICATESH2_H 00026 #define CGAL_DISTANCE_PREDICATESH2_H 00027 00028 #include <CGAL/determinant.h> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00032 template < class R> 00033 CGAL_KERNEL_MEDIUM_INLINE 00034 bool 00035 has_larger_distance_to_point(const PointH2<R>& p, 00036 const PointH2<R>& q, 00037 const PointH2<R>& r) 00038 { 00039 typedef typename R::RT RT; 00040 00041 const RT phx = p.hx(); 00042 const RT phy = p.hy(); 00043 const RT phw = p.hw(); 00044 const RT qhx = q.hx(); 00045 const RT qhy = q.hy(); 00046 const RT qhw = q.hw(); 00047 const RT rhx = r.hx(); 00048 const RT rhy = r.hy(); 00049 const RT rhw = r.hw(); 00050 const RT RT0 = RT(0); 00051 const RT RT2 = RT(2); 00052 00053 RT dosd = // difference of squared distances 00054 00055 // phx * phx * qhw * qhw * rhw * rhw 00056 // -RT(2) * phx * qhx * phw * qhw * rhw * rhw 00057 // + qhx * qhx * phw * phw * rhw * rhw 00058 // 00059 // + phy * phy * qhw * qhw * rhw * rhw 00060 // -RT(2) * phy * qhy * phw * qhw * rhw * rhw 00061 // + qhy * qhy * phw * phw * rhw * rhw 00062 // 00063 // - ( phx * phx * qhw * qhw * rhw * rhw 00064 // -RT(2) * phx * rhx * phw * qhw * qhw * rhw 00065 // + rhx * rhx * phw * phw * qhw * qhw 00066 // 00067 // + phy * phy * qhw * qhw * rhw * rhw 00068 // -RT(2) * phy * rhy * phw * qhw * qhw * rhw 00069 // + rhy * rhy * phw * phw * qhw * qhw 00070 00071 rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy ) 00072 - RT2 * qhw * ( phx*qhx + phy*qhy ) 00073 ) 00074 - qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy ) 00075 - RT2 * rhw * ( phx*rhx + phy*rhy ) 00076 ); 00077 00078 00079 return ( dosd > RT0 ); 00080 } 00081 00082 template < class R> 00083 CGAL_KERNEL_INLINE 00084 Comparison_result 00085 compare_signed_distance_to_line(const LineH2<R>& l, 00086 const PointH2<R>& p, 00087 const PointH2<R>& q) 00088 { 00089 typedef typename R::RT RT; 00090 00091 const RT la = l.a(); 00092 const RT lb = l.b(); 00093 const RT phx= p.hx(); 00094 const RT phy= p.hy(); 00095 const RT phw= p.hw(); 00096 const RT qhx= q.hx(); 00097 const RT qhy= q.hy(); 00098 const RT qhw= q.hw(); 00099 const RT RT0 = RT(0); 00100 00101 RT scaled_dist_p_minus_scaled_dist_q = 00102 la*( phx*qhw - qhx*phw ) 00103 + lb*( phy*qhw - qhy*phw ); 00104 00105 00106 00107 if ( scaled_dist_p_minus_scaled_dist_q < RT0 ) 00108 { 00109 return SMALLER; 00110 } 00111 else 00112 { 00113 return ( RT0 < scaled_dist_p_minus_scaled_dist_q ) ? 00114 LARGER : EQUAL; 00115 } 00116 } 00117 00118 00119 template < class R> 00120 CGAL_KERNEL_INLINE 00121 bool 00122 has_larger_signed_distance_to_line(const LineH2<R>& l, 00123 const PointH2<R>& p, 00124 const PointH2<R>& q) 00125 { 00126 typedef typename R::RT RT; 00127 00128 const RT la = l.a(); 00129 const RT lb = l.b(); 00130 const RT phx= p.hx(); 00131 const RT phy= p.hy(); 00132 const RT phw= p.hw(); 00133 const RT qhx= q.hx(); 00134 const RT qhy= q.hy(); 00135 const RT qhw= q.hw(); 00136 const RT RT0 = RT(0); 00137 00138 RT scaled_dist_p_minus_scaled_dist_q = 00139 la*( phx*qhw - qhx*phw ) 00140 + lb*( phy*qhw - qhy*phw ); 00141 00142 00143 00144 return ( scaled_dist_p_minus_scaled_dist_q > RT0 ); 00145 } 00146 00147 00148 template < class R> 00149 CGAL_KERNEL_INLINE 00150 bool 00151 has_smaller_signed_distance_to_line(const LineH2<R>& l, 00152 const PointH2<R>& p, 00153 const PointH2<R>& q) 00154 { 00155 typedef typename R::RT RT; 00156 00157 const RT la = l.a(); 00158 const RT lb = l.b(); 00159 const RT phx= p.hx(); 00160 const RT phy= p.hy(); 00161 const RT phw= p.hw(); 00162 const RT qhx= q.hx(); 00163 const RT qhy= q.hy(); 00164 const RT qhw= q.hw(); 00165 const RT RT0 = RT(0); 00166 00167 RT scaled_dist_p_minus_scaled_dist_q = 00168 la*( phx*qhw - qhx*phw ) 00169 + lb*( phy*qhw - qhy*phw ); 00170 00171 return ( scaled_dist_p_minus_scaled_dist_q < RT0 ); 00172 } 00173 00174 00175 template < class R> 00176 CGAL_KERNEL_MEDIUM_INLINE 00177 Comparison_result 00178 compare_signed_distance_to_line(const PointH2<R>& p, 00179 const PointH2<R>& q, 00180 const PointH2<R>& r, 00181 const PointH2<R>& s) 00182 { 00183 typedef typename R::RT RT; 00184 00185 const RT phx= p.hx(); 00186 const RT phy= p.hy(); 00187 const RT phw= p.hw(); 00188 const RT qhx= q.hx(); 00189 const RT qhy= q.hy(); 00190 const RT qhw= q.hw(); 00191 const RT rhx= r.hx(); 00192 const RT rhy= r.hy(); 00193 const RT rhw= r.hw(); 00194 const RT shx= s.hx(); 00195 const RT shy= s.hy(); 00196 const RT shw= s.hw(); 00197 const RT RT0 = RT(0); 00198 00199 RT scaled_dist_r_minus_scaled_dist_s = 00200 ( rhx*shw - shx*rhw ) * (phy*qhw - qhy*phw) 00201 - ( rhy*shw - shy*rhw ) * (phx*qhw - qhx*phw); 00202 00203 00204 if ( scaled_dist_r_minus_scaled_dist_s < RT0 ) 00205 { 00206 return SMALLER; 00207 } 00208 else 00209 { 00210 return (scaled_dist_r_minus_scaled_dist_s > RT0 ) ? 00211 LARGER : EQUAL; 00212 } 00213 } 00214 00215 00216 template < class R> 00217 CGAL_KERNEL_MEDIUM_INLINE 00218 bool 00219 has_smaller_signed_distance_to_line(const PointH2<R>& p, 00220 const PointH2<R>& q, 00221 const PointH2<R>& r, 00222 const PointH2<R>& s) 00223 { 00224 typedef typename R::RT RT; 00225 00226 const RT phx= p.hx(); 00227 const RT phy= p.hy(); 00228 const RT phw= p.hw(); 00229 const RT qhx= q.hx(); 00230 const RT qhy= q.hy(); 00231 const RT qhw= q.hw(); 00232 const RT rhx= r.hx(); 00233 const RT rhy= r.hy(); 00234 const RT rhw= r.hw(); 00235 const RT shx= s.hx(); 00236 const RT shy= s.hy(); 00237 const RT shw= s.hw(); 00238 const RT RT0 = RT(0); 00239 00240 RT scaled_dist_r_minus_scaled_dist_s = 00241 ( rhx*shw - shx*rhw ) * (phy*qhw - qhy*phw) 00242 - ( rhy*shw - shy*rhw ) * (phx*qhw - qhx*phw); 00243 00244 return ( scaled_dist_r_minus_scaled_dist_s < RT0 ); 00245 } 00246 00247 00248 00249 template < class R> 00250 CGAL_KERNEL_MEDIUM_INLINE 00251 bool 00252 has_larger_signed_distance_to_line(const PointH2<R>& p, 00253 const PointH2<R>& q, 00254 const PointH2<R>& r, 00255 const PointH2<R>& s) 00256 { 00257 typedef typename R::RT RT; 00258 00259 const RT phx= p.hx(); 00260 const RT phy= p.hy(); 00261 const RT phw= p.hw(); 00262 const RT qhx= q.hx(); 00263 const RT qhy= q.hy(); 00264 const RT qhw= q.hw(); 00265 const RT rhx= r.hx(); 00266 const RT rhy= r.hy(); 00267 const RT rhw= r.hw(); 00268 const RT shx= s.hx(); 00269 const RT shy= s.hy(); 00270 const RT shw= s.hw(); 00271 const RT RT0 = RT(0); 00272 00273 RT scaled_dist_r_minus_scaled_dist_s = 00274 ( rhx*shw - shx*rhw ) * (phy*qhw - qhy*phw) 00275 - ( rhy*shw - shy*rhw ) * (phx*qhw - qhx*phw); 00276 00277 00278 return ( scaled_dist_r_minus_scaled_dist_s > RT0 ); 00279 } 00280 00281 CGAL_END_NAMESPACE 00282 00283 #endif //CGAL_DISTANCE_PREDICATESH2_H