|
BWAPI
|
00001 // Copyright (c) 1998,2003 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/Kernel_23/include/CGAL/Kernel/Wutils.h $ 00019 // $Id: Wutils.h 42811 2008-04-09 13:35:34Z spion $ 00020 // 00021 // 00022 // Author(s) : Geert-Jan Giezeman, Sylvain Pion 00023 00024 #ifndef CGAL_KERNEL_WUTILS_H 00025 #define CGAL_KERNEL_WUTILS_H 00026 00027 #include <CGAL/representation_tags.h> 00028 #include <CGAL/determinant.h> 00029 #include <CGAL/Point_2.h> 00030 #include <CGAL/Point_3.h> 00031 00032 // Functions wmult() and wcross(). 00033 00034 CGAL_BEGIN_NAMESPACE 00035 00036 namespace CGALi { 00037 00038 template < typename Rep_Tag > struct wmult_tag; 00039 00040 template <> 00041 struct wmult_tag<Cartesian_tag> 00042 { 00043 template < typename RT > 00044 const RT & operator()(const RT &a, const RT &) const 00045 { return a; } 00046 00047 template < typename RT > 00048 const RT & operator()(const RT &a, const RT &, const RT &) const 00049 { return a; } 00050 00051 template < typename RT > 00052 const RT & operator()(const RT &a, const RT &, const RT &, const RT &) const 00053 { return a; } 00054 00055 template < typename RT > 00056 const RT & operator()(const RT &a, const RT &, const RT &, const RT &, 00057 const RT &) const 00058 { return a; } 00059 }; 00060 00061 template <> 00062 struct wmult_tag<Homogeneous_tag> 00063 { 00064 template < typename RT > 00065 RT operator()(const RT &a, const RT &w) const 00066 { return a*w; } 00067 00068 template < typename RT > 00069 RT operator()(const RT &a, const RT &w1, const RT &w2) const 00070 { return a*w1*w2; } 00071 00072 template < typename RT > 00073 RT operator()(const RT &a, const RT &w1, const RT &w2, const RT &w3) const 00074 { return a*w1*w2*w3; } 00075 00076 template < typename RT > 00077 RT operator()(const RT &a, const RT &w1, const RT &w2, const RT &w3, 00078 const RT &w4) const 00079 { return a*w1*w2*w3*w4; } 00080 }; 00081 00082 template < typename K > 00083 struct wmult_functor 00084 : public wmult_tag<typename K::Rep_tag> {}; 00085 00086 00087 template < typename Rep_Tag > struct wmult_hw_tag; 00088 00089 template <> 00090 struct wmult_hw_tag<Cartesian_tag> 00091 { 00092 template < typename RT, typename T > 00093 const RT & operator()(const RT &a, const T &) const 00094 { return a; } 00095 00096 template < typename RT, typename T > 00097 const RT & operator()(const RT &a, const RT &, const T &) const 00098 { return a; } 00099 00100 template < typename RT, typename T > 00101 const RT & operator()(const RT &a, const RT &, const RT &, const T &) const 00102 { return a; } 00103 00104 template < typename RT, typename T > 00105 const RT & operator()(const RT &a, const RT &, const RT &, const RT &, 00106 const T &) const 00107 { return a; } 00108 }; 00109 00110 template <> 00111 struct wmult_hw_tag<Homogeneous_tag> 00112 { 00113 template < typename RT, typename T > 00114 RT operator()(const RT &a, const T &t) const 00115 { return a*t.hw(); } 00116 00117 template < typename RT, typename T > 00118 RT operator()(const RT &a, const RT &w1, const T &t) const 00119 { return a*w1*t.hw(); } 00120 00121 template < typename RT, typename T > 00122 RT operator()(const RT &a, const RT &w1, const RT &w2, const T &t) const 00123 { return a*w1*w2*t.hw(); } 00124 00125 template < typename RT, typename T > 00126 RT operator()(const RT &a, const RT &w1, const RT &w2, const RT &w3, 00127 const T &t) const 00128 { return a*w1*w2*w3*t.hw(); } 00129 }; 00130 00131 00132 template < typename K > 00133 struct wmult_hw_functor 00134 : public wmult_hw_tag<typename K::Rep_tag> {}; 00135 00136 00137 template < typename Rep_Tag > struct wcross_tag_2; 00138 00139 template <> 00140 struct wcross_tag_2<Cartesian_tag> 00141 { 00142 template < typename Point_2 > 00143 typename Point_2::R::RT operator()(const Point_2 &p, 00144 const Point_2 &q, 00145 const Point_2 &r) const 00146 { 00147 return (q.x()-p.x())*(r.y()-q.y()) - (q.y()-p.y())*(r.x()-q.x()); 00148 } 00149 }; 00150 00151 template <> 00152 struct wcross_tag_2<Homogeneous_tag> 00153 { 00154 template < typename Point_2 > 00155 typename Point_2::R::RT operator()(const Point_2 &p, 00156 const Point_2 &q, 00157 const Point_2 &r) const 00158 { 00159 return determinant(p.hx(), q.hx(), r.hx(), 00160 p.hy(), q.hy(), r.hy(), 00161 p.hw(), q.hw(), r.hw()); 00162 } 00163 }; 00164 00165 template < typename K > 00166 struct wcross_functor_2 00167 : public wcross_tag_2<typename K::Rep_tag> {}; 00168 00169 00170 template < typename Rep_Tag > struct wcross_tag_3; 00171 00172 template <> 00173 struct wcross_tag_3<Cartesian_tag> 00174 { 00175 template < typename Point_3 > 00176 typename Point_3::R::Vector_3 operator()(const Point_3 &p, 00177 const Point_3 &q, 00178 const Point_3 &r) const 00179 { 00180 typedef typename Point_3::R::FT FT; 00181 typedef typename Point_3::R::Vector_3 Vector_3; 00182 FT x = (q.y()-p.y())*(r.z()-q.z()) - (q.z()-p.z())*(r.y()-q.y()); 00183 FT y = (q.z()-p.z())*(r.x()-q.x()) - (q.x()-p.x())*(r.z()-q.z()); 00184 FT z = (q.x()-p.x())*(r.y()-q.y()) - (q.y()-p.y())*(r.x()-q.x()); 00185 return Vector_3(x, y, z); 00186 } 00187 }; 00188 00189 template <> 00190 struct wcross_tag_3<Homogeneous_tag> 00191 { 00192 template < typename Point_3 > 00193 typename Point_3::R::Vector_3 operator()(const Point_3 &p, 00194 const Point_3 &q, 00195 const Point_3 &r) const 00196 { 00197 typedef typename Point_3::R::RT RT; 00198 typedef typename Point_3::R::Vector_3 Vector_3; 00199 RT x = p.hy() * (q.hz()*r.hw() - q.hw()*r.hz() ) 00200 + p.hz() * (q.hw()*r.hy() - q.hy()*r.hw() ) 00201 + p.hw() * (q.hy()*r.hz() - q.hz()*r.hy() ); 00202 RT y = p.hz() * (q.hx()*r.hw() - q.hw()*r.hx() ) 00203 + p.hx() * (q.hw()*r.hz() - q.hz()*r.hw() ) 00204 + p.hw() * (q.hz()*r.hx() - q.hx()*r.hz() ); 00205 RT z = p.hx() * (q.hy()*r.hw() - q.hw()*r.hy() ) 00206 + p.hy() * (q.hw()*r.hx() - q.hx()*r.hw() ) 00207 + p.hw() * (q.hx()*r.hy() - q.hy()*r.hx() ); 00208 return Vector_3(x, y, z); 00209 } 00210 }; 00211 00212 template < typename K > 00213 struct wcross_functor_3 00214 : public wcross_tag_3<typename K::Rep_tag> {}; 00215 00216 } // end namespace CGALi 00217 00218 00219 // wmult_hw() is like wmult(), except it calls .hw() on its last argument. 00220 // This way, we can completely avoid creating FT(1) for Cartesian. 00221 00222 template < typename K, typename T > 00223 inline 00224 typename K::RT 00225 wmult_hw(K*, const typename K::RT &a, 00226 const T &t) 00227 { 00228 return CGALi::wmult_hw_functor<K>()(a, t); 00229 } 00230 00231 template < typename K, typename T > 00232 inline 00233 typename K::RT 00234 wmult_hw(K*, const typename K::RT &a, 00235 const typename K::RT &w1, 00236 const T &t) 00237 { 00238 return CGALi::wmult_hw_functor<K>()(a, w1, t); 00239 } 00240 00241 template < typename K, typename T > 00242 inline 00243 typename K::RT 00244 wmult_hw(K*, const typename K::RT &a, 00245 const typename K::RT &w1, 00246 const typename K::RT &w2, 00247 const T &t) 00248 { 00249 return CGALi::wmult_hw_functor<K>()(a, w1, w2, t); 00250 } 00251 00252 template < typename K, typename T > 00253 inline 00254 typename K::RT 00255 wmult_hw(K*, const typename K::RT &a, 00256 const typename K::RT &w1, 00257 const typename K::RT &w2, 00258 const typename K::RT &w3, 00259 const T &t) 00260 { 00261 return CGALi::wmult_hw_functor<K>()(a, w1, w2, w3, t); 00262 } 00263 00264 00265 template < typename K > 00266 inline 00267 typename K::RT 00268 wmult(K*, const typename K::RT &a, 00269 const typename K::RT &w) 00270 { 00271 return CGALi::wmult_functor<K>()(a, w); 00272 } 00273 00274 template < typename K > 00275 inline 00276 typename K::RT 00277 wmult(K*, const typename K::RT &a, 00278 const typename K::RT &w1, 00279 const typename K::RT &w2) 00280 { 00281 return CGALi::wmult_functor<K>()(a, w1, w2); 00282 } 00283 00284 template < typename K > 00285 inline 00286 typename K::RT 00287 wmult(K*, const typename K::RT &a, 00288 const typename K::RT &w1, 00289 const typename K::RT &w2, 00290 const typename K::RT &w3) 00291 { 00292 return CGALi::wmult_functor<K>()(a, w1, w2, w3); 00293 } 00294 00295 template < typename K > 00296 inline 00297 typename K::RT 00298 wmult(K*, const typename K::RT &a, 00299 const typename K::RT &w1, 00300 const typename K::RT &w2, 00301 const typename K::RT &w3, 00302 const typename K::RT &w4) 00303 { 00304 return CGALi::wmult_functor<K>()(a, w1, w2, w3, w4); 00305 } 00306 00307 template < typename K > 00308 inline 00309 typename K::RT 00310 wcross(K*, const Point_2<K> &p, 00311 const Point_2<K> &q, 00312 const Point_2<K> &r) 00313 { 00314 return CGALi::wcross_functor_2<K>()(p, q, r); 00315 } 00316 00317 template < typename K > 00318 inline 00319 typename K::Vector_3 00320 wcross(const Point_3<K> &p, 00321 const Point_3<K> &q, 00322 const Point_3<K> &r) 00323 { 00324 return CGALi::wcross_functor_3<K>()(p, q, r); 00325 } 00326 00327 CGAL_END_NAMESPACE 00328 00329 #endif // CGAL_KERNEL_WUTILS_H
1.7.6.1