BWAPI
|
00001 // Copyright (c) 2000 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/Cartesian_kernel/include/CGAL/Cartesian/Vector_3.h $ 00019 // $Id: Vector_3.h 49589 2009-05-26 07:54:52Z spion $ 00020 // 00021 // 00022 // Author : Andreas Fabri 00023 00024 #ifndef CGAL_CARTESIAN_VECTOR_3_H 00025 #define CGAL_CARTESIAN_VECTOR_3_H 00026 00027 #include <CGAL/Origin.h> 00028 #include <CGAL/array.h> 00029 #include <CGAL/constant.h> 00030 00031 CGAL_BEGIN_NAMESPACE 00032 00033 template < class R_ > 00034 class VectorC3 00035 { 00036 typedef typename R_::FT FT; 00037 typedef typename R_::Point_3 Point_3; 00038 typedef typename R_::Vector_3 Vector_3; 00039 typedef typename R_::Ray_3 Ray_3; 00040 typedef typename R_::Segment_3 Segment_3; 00041 typedef typename R_::Line_3 Line_3; 00042 typedef typename R_::Direction_3 Direction_3; 00043 00044 typedef cpp0x::array<FT, 3> Rep; 00045 typedef typename R_::template Handle<Rep>::type Base; 00046 00047 Base base; 00048 00049 public: 00050 00051 typedef typename Rep::const_iterator Cartesian_const_iterator; 00052 00053 typedef R_ R; 00054 00055 VectorC3() {} 00056 00057 VectorC3(const Null_vector &n) 00058 { *this = R().construct_vector_3_object()(n); } 00059 00060 VectorC3(const Point_3 &a, const Point_3 &b) 00061 { *this = R().construct_vector_3_object()(a, b); } 00062 00063 explicit VectorC3(const Segment_3 &s) 00064 { *this = R().construct_vector_3_object()(s); } 00065 00066 explicit VectorC3(const Ray_3 &r) 00067 { *this = R().construct_vector_3_object()(r); } 00068 00069 explicit VectorC3(const Line_3 &l) 00070 { *this = R().construct_vector_3_object()(l); } 00071 00072 VectorC3(const FT &x, const FT &y, const FT &z) 00073 : base(CGAL::make_array(x, y, z)) {} 00074 00075 VectorC3(const FT &x, const FT &y, const FT &z, const FT &w) 00076 : base( w != FT(1) ? CGAL::make_array(x/w, y/w, z/w) 00077 : CGAL::make_array(x, y, z) ) {} 00078 00079 const FT & x() const 00080 { 00081 return get(base)[0]; 00082 } 00083 const FT & y() const 00084 { 00085 return get(base)[1]; 00086 } 00087 const FT & z() const 00088 { 00089 return get(base)[2]; 00090 } 00091 00092 const FT & hx() const 00093 { 00094 return x(); 00095 } 00096 const FT & hy() const 00097 { 00098 return y(); 00099 } 00100 const FT & hz() const 00101 { 00102 return z(); 00103 } 00104 const FT & hw() const 00105 { 00106 return constant<FT, 1>(); 00107 } 00108 00109 Cartesian_const_iterator cartesian_begin() const 00110 { 00111 return get(base).begin(); 00112 } 00113 00114 Cartesian_const_iterator cartesian_end() const 00115 { 00116 return get(base).end(); 00117 } 00118 00119 const FT & cartesian(int i) const; 00120 const FT & operator[](int i) const; 00121 const FT & homogeneous(int i) const; 00122 00123 int dimension() const 00124 { 00125 return 3; 00126 } 00127 00128 Vector_3 operator+(const VectorC3 &w) const; 00129 Vector_3 operator-(const VectorC3 &w) const; 00130 Vector_3 operator-() const; 00131 Vector_3 operator/(const FT &c) const; 00132 FT squared_length() const; 00133 Direction_3 direction() const; 00134 }; 00135 00136 template < class R > 00137 inline 00138 bool 00139 operator==(const VectorC3<R> &v, const VectorC3<R> &w) 00140 { 00141 return w.x() == v.x() && w.y() == v.y() && w.z() == v.z(); 00142 } 00143 00144 template < class R > 00145 inline 00146 bool 00147 operator!=(const VectorC3<R> &v, const VectorC3<R> &w) 00148 { 00149 return !(v == w); 00150 } 00151 00152 template < class R > 00153 inline 00154 bool 00155 operator==(const VectorC3<R> &v, const Null_vector &) 00156 { 00157 return CGAL_NTS is_zero(v.x()) && CGAL_NTS is_zero(v.y()) && 00158 CGAL_NTS is_zero(v.z()); 00159 } 00160 00161 template < class R > 00162 inline 00163 bool 00164 operator==(const Null_vector &n, const VectorC3<R> &v) 00165 { 00166 return v == n; 00167 } 00168 00169 template < class R > 00170 inline 00171 bool 00172 operator!=(const VectorC3<R> &v, const Null_vector &n) 00173 { 00174 return !(v == n); 00175 } 00176 00177 template < class R > 00178 inline 00179 bool 00180 operator!=(const Null_vector &n, const VectorC3<R> &v) 00181 { 00182 return !(v == n); 00183 } 00184 00185 template < class R > 00186 inline 00187 const typename VectorC3<R>::FT & 00188 VectorC3<R>::cartesian(int i) const 00189 { 00190 CGAL_kernel_precondition( (i>=0) & (i<3) ); 00191 if (i==0) return x(); 00192 if (i==1) return y(); 00193 return z(); 00194 } 00195 00196 template < class R > 00197 inline 00198 const typename VectorC3<R>::FT & 00199 VectorC3<R>::operator[](int i) const 00200 { 00201 return cartesian(i); 00202 } 00203 00204 template < class R > 00205 const typename VectorC3<R>::FT & 00206 VectorC3<R>::homogeneous(int i) const 00207 { 00208 if (i==3) return hw(); 00209 return cartesian(i); 00210 } 00211 00212 template < class R > 00213 inline 00214 typename VectorC3<R>::Vector_3 00215 VectorC3<R>:: 00216 operator+(const VectorC3<R> &w) const 00217 { 00218 return VectorC3<R>(x() + w.x(), y() + w.y(), z() + w.z()); 00219 } 00220 00221 template < class R > 00222 inline 00223 typename VectorC3<R>::Vector_3 00224 VectorC3<R>::operator-(const VectorC3<R> &w) const 00225 { 00226 return VectorC3<R>(x() - w.x(), y() - w.y(), z() - w.z()); 00227 } 00228 00229 template < class R > 00230 inline 00231 typename VectorC3<R>::Vector_3 00232 VectorC3<R>::operator-() const 00233 { 00234 return R().construct_opposite_vector_3_object()(*this); 00235 } 00236 00237 template < class R > 00238 inline 00239 typename VectorC3<R>::FT 00240 VectorC3<R>::squared_length() const 00241 { 00242 return CGAL_NTS square(x()) + CGAL_NTS square(y()) + CGAL_NTS square(z()); 00243 } 00244 00245 template < class R > 00246 inline 00247 typename VectorC3<R>::Vector_3 00248 VectorC3<R>:: 00249 operator/(const typename VectorC3<R>::FT &c) const 00250 { 00251 return VectorC3<R>(x()/c, y()/c, z()/c); 00252 } 00253 00254 template < class R > 00255 inline 00256 typename VectorC3<R>::Direction_3 00257 VectorC3<R>::direction() const 00258 { 00259 return Direction_3(*this); 00260 } 00261 00262 CGAL_END_NAMESPACE 00263 00264 #endif // CGAL_CARTESIAN_VECTOR_3_H