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/Kernel_23/include/CGAL/Vector_3.h $ 00019 // $Id: Vector_3.h 49257 2009-05-09 16:08:19Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Stefan Schirra 00023 00024 #ifndef CGAL_VECTOR_3_H 00025 #define CGAL_VECTOR_3_H 00026 00027 #include <CGAL/Origin.h> 00028 #include <CGAL/Kernel/mpl.h> 00029 #include <CGAL/representation_tags.h> 00030 #include <boost/static_assert.hpp> 00031 #include <boost/type_traits.hpp> 00032 #include <CGAL/Kernel/Return_base_tag.h> 00033 #include <CGAL/Dimension.h> 00034 00035 CGAL_BEGIN_NAMESPACE 00036 00037 template <class R_> 00038 class Vector_3 : public R_::Kernel_base::Vector_3 00039 { 00040 typedef typename R_::RT RT; 00041 typedef typename R_::FT FT; 00042 typedef typename R_::Segment_3 Segment_3; 00043 typedef typename R_::Ray_3 Ray_3; 00044 typedef typename R_::Line_3 Line_3; 00045 typedef typename R_::Point_3 Point_3; 00046 typedef typename R_::Direction_3 Direction_3; 00047 typedef typename R_::Aff_transformation_3 Aff_transformation_3; 00048 00049 typedef Vector_3 Self; 00050 BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Vector_3>::value)); 00051 00052 public: 00053 00054 typedef Dimension_tag<3> Ambient_dimension; 00055 typedef Dimension_tag<0> Feature_dimension; 00056 00057 typedef typename R_::Cartesian_const_iterator_3 Cartesian_const_iterator; 00058 typedef typename R_::Kernel_base::Vector_3 Rep; 00059 00060 const Rep& rep() const 00061 { 00062 return *this; 00063 } 00064 00065 Rep& rep() 00066 { 00067 return *this; 00068 } 00069 00070 typedef R_ R; 00071 00072 Vector_3() {} 00073 00074 Vector_3(const Rep& v) 00075 : Rep(v) {} 00076 00077 Vector_3(const Point_3& a, const Point_3& b) 00078 : Rep(typename R::Construct_vector_3()(Return_base_tag(), a, b)) {} 00079 00080 explicit Vector_3(const Segment_3& s) 00081 : Rep(typename R::Construct_vector_3()(Return_base_tag(), s)) {} 00082 00083 explicit Vector_3(const Ray_3& r) 00084 : Rep(typename R::Construct_vector_3()(Return_base_tag(), r)) {} 00085 00086 explicit Vector_3(const Line_3& l) 00087 : Rep(typename R::Construct_vector_3()(Return_base_tag(), l)) {} 00088 00089 Vector_3(const Null_vector& v) 00090 : Rep(typename R::Construct_vector_3()(Return_base_tag(), v)) {} 00091 00092 template < typename T1, typename T2, typename T3 > 00093 Vector_3(const T1 &x, const T2 &y, const T3 &z) 00094 : Rep(typename R::Construct_vector_3()(Return_base_tag(), x, y, z)) {} 00095 00096 Vector_3(const RT& x, const RT& y, const RT& z, const RT& w) 00097 : Rep(typename R::Construct_vector_3()(Return_base_tag(), x, y, z, w)) {} 00098 00099 Direction_3 direction() const 00100 { 00101 return R().construct_direction_3_object()(*this); 00102 } 00103 00104 Vector_3 transform(const Aff_transformation_3 &t) const 00105 { 00106 return t.transform(*this); 00107 } 00108 00109 Vector_3 operator-() const 00110 { 00111 return R().construct_opposite_vector_3_object()(*this); 00112 } 00113 00114 Vector_3 operator-(const Vector_3& v) const 00115 { 00116 return R().construct_difference_of_vectors_3_object()(*this,v); 00117 } 00118 00119 Vector_3 operator+(const Vector_3& v) const 00120 { 00121 return R().construct_sum_of_vectors_3_object()(*this,v); 00122 } 00123 00124 Vector_3 operator/(const RT& c) const 00125 { 00126 return R().construct_divided_vector_3_object()(*this,c); 00127 } 00128 00129 Vector_3 operator/(const typename First_if_different<FT,RT>::Type & c) const 00130 { 00131 return R().construct_divided_vector_3_object()(*this,c); 00132 } 00133 00134 typename Qualified_result_of<typename R::Compute_x_3, Vector_3>::type 00135 x() const 00136 { 00137 return R().compute_x_3_object()(*this); 00138 } 00139 00140 typename Qualified_result_of<typename R::Compute_y_3, Vector_3>::type 00141 y() const 00142 { 00143 return R().compute_y_3_object()(*this); 00144 } 00145 00146 typename Qualified_result_of<typename R::Compute_z_3, Vector_3>::type 00147 z() const 00148 { 00149 return R().compute_z_3_object()(*this); 00150 } 00151 00152 typename Qualified_result_of<typename R::Compute_hx_3, Vector_3>::type 00153 hx() const 00154 { 00155 return R().compute_hx_3_object()(*this); 00156 } 00157 00158 typename Qualified_result_of<typename R::Compute_hy_3, Vector_3>::type 00159 hy() const 00160 { 00161 return R().compute_hy_3_object()(*this); 00162 } 00163 00164 typename Qualified_result_of<typename R::Compute_hz_3, Vector_3>::type 00165 hz() const 00166 { 00167 return R().compute_hz_3_object()(*this); 00168 } 00169 00170 typename Qualified_result_of<typename R::Compute_hw_3, Vector_3>::type 00171 hw() const 00172 { 00173 return R().compute_hw_3_object()(*this); 00174 } 00175 00176 typename Qualified_result_of<typename R::Compute_x_3, Vector_3>::type 00177 cartesian(int i) const 00178 { 00179 CGAL_kernel_precondition( (i == 0) || (i == 1) || (i == 2) ); 00180 if (i==0) return x(); 00181 if (i==1) return y(); 00182 return z(); 00183 } 00184 00185 typename Qualified_result_of<typename R::Compute_hw_3, Vector_3>::type 00186 homogeneous(int i) const 00187 { 00188 CGAL_kernel_precondition( (i >= 0) || (i <= 3) ); 00189 if (i==0) return hx(); 00190 if (i==1) return hy(); 00191 if (i==2) return hz(); 00192 return hw(); 00193 } 00194 00195 int dimension() const 00196 { 00197 return 3; 00198 } 00199 00200 typename Qualified_result_of<typename R::Compute_x_3, Vector_3>::type 00201 operator[](int i) const 00202 { 00203 return cartesian(i); 00204 } 00205 00206 Cartesian_const_iterator cartesian_begin() const 00207 { 00208 return typename R::Construct_cartesian_const_iterator_3()(*this); 00209 } 00210 00211 Cartesian_const_iterator cartesian_end() const 00212 { 00213 return typename R::Construct_cartesian_const_iterator_3()(*this,3); 00214 } 00215 00216 typename Qualified_result_of<typename R::Compute_squared_length_3, Vector_3>::type 00217 squared_length() const 00218 { 00219 return R().compute_squared_length_3_object()(*this); 00220 } 00221 00222 }; 00223 00224 00225 template <class R > 00226 std::ostream& 00227 insert(std::ostream& os, const Vector_3<R>& v, const Cartesian_tag&) 00228 { 00229 switch(os.iword(IO::mode)) { 00230 case IO::ASCII : 00231 return os << v.x() << ' ' << v.y() << ' ' << v.z(); 00232 case IO::BINARY : 00233 write(os, v.x()); 00234 write(os, v.y()); 00235 write(os, v.z()); 00236 return os; 00237 default: 00238 os << "VectorC3(" << v.x() << ", " << v.y() << ", " << v.z() << ")"; 00239 return os; 00240 } 00241 } 00242 00243 template <class R > 00244 std::ostream& 00245 insert(std::ostream& os, const Vector_3<R>& v, const Homogeneous_tag&) 00246 { 00247 switch(os.iword(IO::mode)) 00248 { 00249 case IO::ASCII : 00250 return os << v.hx() << ' ' << v.hy() << ' ' << v.hz() << ' ' << v.hw(); 00251 case IO::BINARY : 00252 write(os, v.hx()); 00253 write(os, v.hy()); 00254 write(os, v.hz()); 00255 write(os, v.hw()); 00256 return os; 00257 default: 00258 return os << "VectorH3(" << v.hx() << ", " 00259 << v.hy() << ", " 00260 << v.hz() << ", " 00261 << v.hw() << ')'; 00262 } 00263 } 00264 00265 template < class R > 00266 std::ostream& 00267 operator<<(std::ostream& os, const Vector_3<R>& v) 00268 { 00269 return insert(os, v, typename R::Kernel_tag() ); 00270 } 00271 00272 00273 template <class R > 00274 std::istream& 00275 extract(std::istream& is, Vector_3<R>& v, const Cartesian_tag&) 00276 { 00277 typename R::FT x, y, z; 00278 switch(is.iword(IO::mode)) { 00279 case IO::ASCII : 00280 is >> x >> y >> z; 00281 break; 00282 case IO::BINARY : 00283 read(is, x); 00284 read(is, y); 00285 read(is, z); 00286 break; 00287 default: 00288 std::cerr << "" << std::endl; 00289 std::cerr << "Stream must be in ascii or binary mode" << std::endl; 00290 break; 00291 } 00292 if (is) 00293 v = Vector_3<R>(x, y, z); 00294 return is; 00295 } 00296 00297 template <class R > 00298 std::istream& 00299 extract(std::istream& is, Vector_3<R>& v, const Homogeneous_tag&) 00300 { 00301 typename R::RT hx, hy, hz, hw; 00302 switch(is.iword(IO::mode)) 00303 { 00304 case IO::ASCII : 00305 is >> hx >> hy >> hz >> hw; 00306 break; 00307 case IO::BINARY : 00308 read(is, hx); 00309 read(is, hy); 00310 read(is, hz); 00311 read(is, hw); 00312 break; 00313 default: 00314 std::cerr << "" << std::endl; 00315 std::cerr << "Stream must be in ascii or binary mode" << std::endl; 00316 break; 00317 } 00318 if (is) 00319 v = Vector_3<R>(hx, hy, hz, hw); 00320 return is; 00321 } 00322 00323 template < class R > 00324 std::istream& 00325 operator>>(std::istream& is, Vector_3<R>& v) 00326 { 00327 return extract(is, v, typename R::Kernel_tag() ); 00328 } 00329 00330 CGAL_END_NAMESPACE 00331 00332 #endif // CGAL_VECTOR_3_H