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/Homogeneous_kernel/include/CGAL/Homogeneous/PointH2.h $ 00019 // $Id: PointH2.h 42834 2008-04-10 14:41:35Z spion $ 00020 // 00021 // 00022 // Author(s) : Stefan Schirra 00023 00024 #ifndef CGAL_HOMOGENEOUS_POINT_2_H 00025 #define CGAL_HOMOGENEOUS_POINT_2_H 00026 00027 #include <CGAL/Origin.h> 00028 #include <boost/utility/enable_if.hpp> 00029 #include <boost/type_traits.hpp> 00030 #include <boost/mpl/and.hpp> 00031 #include <boost/mpl/logical.hpp> 00032 #include <boost/utility.hpp> 00033 00034 CGAL_BEGIN_NAMESPACE 00035 00036 template < class R_ > 00037 class PointH2 00038 { 00039 typedef typename R_::FT FT; 00040 typedef typename R_::RT RT; 00041 typedef typename R_::Vector_2 Vector_2; 00042 typedef typename R_::Point_2 Point_2; 00043 typedef typename R_::Direction_2 Direction_2; 00044 00045 typedef Rational_traits<FT> Rat_traits; 00046 00047 // Reference-counting is handled in Vector_2. 00048 Vector_2 base; 00049 00050 public: 00051 00052 typedef FT Cartesian_coordinate_type; 00053 typedef const RT& Homogeneous_coordinate_type; 00054 typedef typename Vector_2::Cartesian_const_iterator Cartesian_const_iterator; 00055 typedef R_ R; 00056 00057 PointH2() {} 00058 00059 PointH2(const Origin &) 00060 : base(NULL_VECTOR) {} 00061 00062 template < typename Tx, typename Ty > 00063 PointH2(const Tx & x, const Ty & y, 00064 typename boost::enable_if< boost::mpl::and_<boost::is_convertible<Tx, RT>, 00065 boost::is_convertible<Ty, RT> > >::type* = 0) 00066 : base(x, y) {} 00067 00068 PointH2(const FT& x, const FT& y) 00069 : base(x, y) {} 00070 00071 PointH2(const RT& hx, const RT& hy, const RT& hw) 00072 : base(hx, hy, hw) {} 00073 00074 bool operator==( const PointH2<R>& p) const; 00075 bool operator!=( const PointH2<R>& p) const; 00076 00077 const RT & hx() const { return base.hx(); } 00078 const RT & hy() const { return base.hy(); } 00079 const RT & hw() const { return base.hw(); } 00080 00081 FT x() const { return FT(hx()) / FT(hw()); } 00082 FT y() const { return FT(hy()) / FT(hw()); } 00083 00084 FT cartesian(int i) const; 00085 FT operator[](int i) const; 00086 const RT & homogeneous(int i) const; 00087 00088 Cartesian_const_iterator cartesian_begin() const 00089 { 00090 return base.cartesian_begin(); 00091 } 00092 00093 Cartesian_const_iterator cartesian_end() const 00094 { 00095 return base.cartesian_end(); 00096 } 00097 00098 int dimension() const; 00099 00100 Direction_2 direction() const; 00101 }; 00102 00103 template < class R > 00104 inline 00105 bool 00106 PointH2<R>::operator==( const PointH2<R>& p) const 00107 { 00108 return base == p.base; 00109 } 00110 00111 template < class R > 00112 inline 00113 bool 00114 PointH2<R>::operator!=( const PointH2<R>& p) const 00115 { return !(*this == p); } 00116 00117 template < class R > 00118 inline 00119 typename PointH2<R>::FT 00120 PointH2<R>::cartesian(int i) const 00121 { 00122 return base.cartesian(i); 00123 } 00124 00125 template < class R > 00126 inline 00127 const typename PointH2<R>::RT & 00128 PointH2<R>::homogeneous(int i) const 00129 { 00130 return base.homogeneous(i); 00131 } 00132 00133 template < class R > 00134 inline 00135 typename PointH2<R>::FT 00136 PointH2<R>::operator[](int i) const 00137 { return base[i]; } 00138 00139 00140 template < class R > 00141 inline 00142 int 00143 PointH2<R>::dimension() const 00144 { return base.dimension(); } 00145 00146 template < class R > 00147 inline 00148 typename PointH2<R>::Direction_2 00149 PointH2<R>::direction() const 00150 { return typename PointH2<R>::Direction_2(*this); } 00151 00152 CGAL_END_NAMESPACE 00153 00154 #endif // CGAL_HOMOGENEOUS_POINT_2_H