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/Point_2.h $ 00019 // $Id: Point_2.h 43244 2008-05-21 13:48:05Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Stefan Schirra 00023 00024 #ifndef CGAL_POINT_2_H 00025 #define CGAL_POINT_2_H 00026 00027 #include <CGAL/Origin.h> 00028 #include <CGAL/Bbox_2.h> 00029 #include <boost/static_assert.hpp> 00030 #include <boost/type_traits.hpp> 00031 #include <CGAL/Kernel/Return_base_tag.h> 00032 #include <CGAL/representation_tags.h> 00033 #include <CGAL/Dimension.h> 00034 00035 CGAL_BEGIN_NAMESPACE 00036 00037 template <class R_> 00038 class Point_2 : public R_::Kernel_base::Point_2 00039 { 00040 typedef typename R_::RT RT; 00041 typedef typename R_::FT FT; 00042 typedef typename R_::Vector_2 Vector_2; 00043 typedef typename R_::Aff_transformation_2 Aff_transformation_2; 00044 typedef typename R_::Kernel_base::Point_2 RPoint_2; 00045 00046 typedef Point_2 Self; 00047 BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Point_2>::value)); 00048 00049 public: 00050 00051 typedef Dimension_tag<2> Ambient_dimension; 00052 typedef Dimension_tag<0> Feature_dimension; 00053 00054 typedef RPoint_2 Rep; 00055 typedef typename R_::Cartesian_const_iterator_2 Cartesian_const_iterator; 00056 00057 const Rep& rep() const 00058 { 00059 return *this; 00060 } 00061 00062 Rep& rep() 00063 { 00064 return *this; 00065 } 00066 00067 typedef R_ R; 00068 00069 Point_2() {} 00070 00071 Point_2(const Origin& o) 00072 : RPoint_2(typename R::Construct_point_2()(Return_base_tag(), o)) 00073 {} 00074 00075 Point_2(const RPoint_2& p) 00076 : RPoint_2(p) 00077 {} 00078 00079 template < typename T1, typename T2 > 00080 Point_2(const T1 &x, const T2 &y) 00081 : Rep(typename R::Construct_point_2()(Return_base_tag(), x, y)) 00082 {} 00083 00084 Point_2(const RT& hx, const RT& hy, const RT& hw) 00085 : RPoint_2(typename R::Construct_point_2()(Return_base_tag(), hx, hy, hw)) 00086 {} 00087 00088 typename Qualified_result_of<typename R::Compute_x_2,Point_2>::type 00089 x() const 00090 { 00091 return typename R::Compute_x_2()(*this); 00092 } 00093 00094 typename Qualified_result_of<typename R::Compute_y_2,Point_2>::type 00095 y() const 00096 { 00097 return typename R::Compute_y_2()(*this); 00098 } 00099 00100 typename Qualified_result_of<typename R::Compute_x_2,Point_2>::type 00101 cartesian(int i) const 00102 { 00103 CGAL_kernel_precondition( (i == 0) || (i == 1) ); 00104 return (i==0) ? x() : y(); 00105 } 00106 00107 typename Qualified_result_of<typename R::Compute_x_2,Point_2>::type 00108 operator[](int i) const 00109 { 00110 return cartesian(i); 00111 } 00112 00113 Cartesian_const_iterator cartesian_begin() const 00114 { 00115 return typename R::Construct_cartesian_const_iterator_2()(*this); 00116 } 00117 00118 Cartesian_const_iterator cartesian_end() const 00119 { 00120 return typename R::Construct_cartesian_const_iterator_2()(*this,2); 00121 } 00122 00123 00124 00125 typename Qualified_result_of<typename R::Compute_hx_2,Point_2>::type 00126 hx() const 00127 { 00128 return typename R::Compute_hx_2()(*this); 00129 } 00130 00131 typename Qualified_result_of<typename R::Compute_hy_2,Point_2>::type 00132 hy() const 00133 { 00134 return typename R::Compute_hy_2()(*this); 00135 } 00136 00137 typename Qualified_result_of<typename R::Compute_hw_2,Point_2>::type 00138 hw() const 00139 { 00140 return typename R::Compute_hw_2()(*this); 00141 } 00142 00143 int dimension() const 00144 { 00145 return 2; 00146 } 00147 00148 typename Qualified_result_of<typename R::Compute_hx_2,Point_2>::type 00149 homogeneous(int i) const 00150 { 00151 CGAL_kernel_precondition( (i >= 0) || (i <= 2) ); 00152 return (i==0) ? hx() : (i==1)? hy() : hw(); 00153 } 00154 00155 Bbox_2 bbox() const 00156 { 00157 return R().construct_bbox_2_object()(*this); 00158 } 00159 00160 Point_2 transform(const Aff_transformation_2 &t) const 00161 { 00162 return t.transform(*this); 00163 } 00164 00165 }; 00166 00167 00168 template <class R > 00169 std::ostream& 00170 insert(std::ostream& os, const Point_2<R>& p,const Cartesian_tag&) 00171 { 00172 switch(os.iword(IO::mode)) { 00173 case IO::ASCII : 00174 return os << p.x() << ' ' << p.y(); 00175 case IO::BINARY : 00176 write(os, p.x()); 00177 write(os, p.y()); 00178 return os; 00179 default: 00180 return os << "PointC2(" << p.x() << ", " << p.y() << ')'; 00181 } 00182 } 00183 00184 template <class R > 00185 std::ostream& 00186 insert(std::ostream& os, const Point_2<R>& p,const Homogeneous_tag&) 00187 { 00188 switch(os.iword(IO::mode)) 00189 { 00190 case IO::ASCII : 00191 return os << p.hx() << ' ' << p.hy() << ' ' << p.hw(); 00192 case IO::BINARY : 00193 write(os, p.hx()); 00194 write(os, p.hy()); 00195 write(os, p.hw()); 00196 return os; 00197 default: 00198 return os << "PointH2(" << p.hx() << ", " 00199 << p.hy() << ", " 00200 << p.hw() << ')'; 00201 } 00202 } 00203 00204 template < class R > 00205 std::ostream& 00206 operator<<(std::ostream& os, const Point_2<R>& p) 00207 { 00208 return insert(os, p, typename R::Kernel_tag() ); 00209 } 00210 00211 00212 template <class R > 00213 std::istream& 00214 extract(std::istream& is, Point_2<R>& p, const Cartesian_tag&) 00215 { 00216 typename R::FT x, y; 00217 switch(is.iword(IO::mode)) { 00218 case IO::ASCII : 00219 is >> x >> y; 00220 break; 00221 case IO::BINARY : 00222 read(is, x); 00223 read(is, y); 00224 break; 00225 default: 00226 std::cerr << "" << std::endl; 00227 std::cerr << "Stream must be in ascii or binary mode" << std::endl; 00228 break; 00229 } 00230 if (is) 00231 p = Point_2<R>(x, y); 00232 return is; 00233 } 00234 00235 00236 template <class R > 00237 std::istream& 00238 extract(std::istream& is, Point_2<R>& p, const Homogeneous_tag&) 00239 { 00240 typename R::RT hx, hy, hw; 00241 switch(is.iword(IO::mode)) 00242 { 00243 case IO::ASCII : 00244 is >> hx >> hy >> hw; 00245 break; 00246 case IO::BINARY : 00247 read(is, hx); 00248 read(is, hy); 00249 read(is, hw); 00250 break; 00251 default: 00252 std::cerr << "" << std::endl; 00253 std::cerr << "Stream must be in ascii or binary mode" << std::endl; 00254 break; 00255 } 00256 if (is) 00257 p = Point_2<R>(hx, hy, hw); 00258 return is; 00259 } 00260 00261 template < class R > 00262 std::istream& 00263 operator>>(std::istream& is, Point_2<R>& p) 00264 { 00265 return extract(is, p, typename R::Kernel_tag() ); 00266 } 00267 00268 CGAL_END_NAMESPACE 00269 00270 #endif // CGAL_POINT_2_H