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_2.h $ 00019 // $Id: Vector_2.h 49057 2009-04-30 14:03:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Herve Bronnimann 00023 00024 #ifndef CGAL_CARTESIAN_VECTOR_2_H 00025 #define CGAL_CARTESIAN_VECTOR_2_H 00026 00027 #include <CGAL/Origin.h> 00028 #include <CGAL/array.h> 00029 #include <CGAL/constant.h> 00030 #include <CGAL/Handle_for.h> 00031 00032 CGAL_BEGIN_NAMESPACE 00033 00034 template < class R_ > 00035 class VectorC2 00036 { 00037 typedef typename R_::FT FT; 00038 typedef typename R_::Point_2 Point_2; 00039 typedef typename R_::Vector_2 Vector_2; 00040 typedef typename R_::Segment_2 Segment_2; 00041 typedef typename R_::Ray_2 Ray_2; 00042 typedef typename R_::Line_2 Line_2; 00043 typedef typename R_::Direction_2 Direction_2; 00044 00045 typedef cpp0x::array<FT, 2> Rep; 00046 typedef typename R_::template Handle<Rep>::type Base; 00047 00048 Base base; 00049 00050 public: 00051 00052 typedef typename Rep::const_iterator Cartesian_const_iterator; 00053 00054 typedef R_ R; 00055 00056 VectorC2() {} 00057 00058 VectorC2(const FT &x, const FT &y) 00059 : base(CGAL::make_array(x, y)) {} 00060 00061 VectorC2(const FT &hx, const FT &hy, const FT &hw) 00062 : base( hw != FT(1) ? CGAL::make_array(hx/hw, hy/hw) 00063 : CGAL::make_array(hx, hy) ) {} 00064 00065 const FT & x() const 00066 { 00067 return CGAL::get(base)[0]; 00068 } 00069 00070 const FT & y() const 00071 { 00072 return CGAL::get(base)[1]; 00073 } 00074 00075 const FT & hx() const 00076 { 00077 return x(); 00078 } 00079 00080 const FT & hy() const 00081 { 00082 return y(); 00083 } 00084 00085 const FT& hw() const 00086 { 00087 return constant<FT, 1>(); 00088 } 00089 00090 Cartesian_const_iterator cartesian_begin() const 00091 { 00092 return CGAL::get(base).begin(); 00093 } 00094 00095 Cartesian_const_iterator cartesian_end() const 00096 { 00097 return CGAL::get(base).end(); 00098 } 00099 00100 }; 00101 00102 template < class R > 00103 CGAL_KERNEL_INLINE 00104 bool 00105 operator==(const VectorC2<R> &v, const VectorC2<R> &w) 00106 { 00107 return w.x() == v.x() && w.y() == v.y(); 00108 } 00109 00110 template < class R > 00111 inline 00112 bool 00113 operator!=(const VectorC2<R> &v, const VectorC2<R> &w) 00114 { 00115 return !(v == w); 00116 } 00117 00118 template < class R > 00119 inline 00120 bool 00121 operator==(const VectorC2<R> &v, const Null_vector &) 00122 { 00123 return CGAL_NTS is_zero(v.x()) && CGAL_NTS is_zero(v.y()); 00124 } 00125 00126 template < class R > 00127 inline 00128 bool 00129 operator==(const Null_vector &n, const VectorC2<R> &v) 00130 { 00131 return v == n; 00132 } 00133 00134 template < class R > 00135 inline 00136 bool 00137 operator!=(const VectorC2<R> &v, const Null_vector &n) 00138 { 00139 return !(v == n); 00140 } 00141 00142 template < class R > 00143 inline 00144 bool 00145 operator!=(const Null_vector &n, const VectorC2<R> &v) 00146 { 00147 return !(v == n); 00148 } 00149 00150 CGAL_END_NAMESPACE 00151 00152 #endif // CGAL_CARTESIAN_VECTOR_2_H