| 
    BWAPI
   
    
   
   | 
  
  
  
 
00001 // Copyright (c) 2000,2001 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_d/include/CGAL/Kernel_d/PointCd.h $ 00019 // $Id: PointCd.h 42940 2008-04-17 13:32:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Michael Seel 00023 #ifndef CGAL_POINTCDXXX_H 00024 #define CGAL_POINTCDXXX_H 00025 00026 #include <CGAL/basic.h> 00027 #include <CGAL/Origin.h> 00028 #include <CGAL/Kernel_d/Tuple_d.h> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 #define PointCd PointCd2 00032 00033 template <class FT, class LA> class PointCd; 00034 template <class FT, class LA> 00035 std::istream& operator>>(std::istream&, PointCd<FT,LA>&); 00036 template <class FT, class LA> 00037 std::ostream& operator<<(std::ostream&, const PointCd<FT,LA>&); 00038 00039 template <class _FT, class _LA > 00040 class PointCd : public Handle_for< Tuple_d<_FT,_LA> > { 00041 typedef Tuple_d<_FT,_LA> Tuple; 00042 typedef Handle_for<Tuple> Base; 00043 typedef PointCd<_FT,_LA> Self; 00044 00045 using Base::ptr; 00046 00047 typename _LA::Vector& vector_rep() { return ptr()->v; } 00048 const typename _LA::Vector& vector_rep() const { return ptr()->v; } 00049 _FT& entry(int i) { return ptr()->v[i]; } 00050 const _FT& entry(int i) const { return ptr()->v[i]; } 00051 PointCd(const Base& b) : Base(b) {} 00052 00053 public: 00054 /*{\Mtypes 4}*/ 00055 00056 typedef _FT RT; 00057 typedef _FT FT; 00058 typedef _LA LA; 00059 typedef typename Tuple::const_iterator Cartesian_const_iterator; 00060 typedef typename Tuple::Homogeneous_const_iterator Homogeneous_const_iterator; 00061 00062 friend class VectorCd<FT,LA>; 00063 friend class HyperplaneCd<FT,LA>; 00064 00065 /*{\Mcreation 4}*/ 00066 00067 PointCd(int d = 0) : Base( Tuple(d) ) {} 00068 PointCd(int d, const Origin&) : Base( Tuple(d) ) {} 00069 00070 template <class InputIterator> 00071 PointCd(int d, InputIterator first, InputIterator last) 00072 : Base( Tuple(d,first,last) ) 00073 { if ( first == last ) return; 00074 // else first specifies common denominator: 00075 CGAL_assertion_msg(FT(*first)!=FT(0), 00076 "PointCd::constructor: denominator must be nonzero."); 00077 for (int i=0; i<d; ++i) entry(i)/=FT(*first); 00078 } 00079 00080 template <class InputIterator> 00081 PointCd (int d, InputIterator first, InputIterator last, 00082 const FT& D) : Base( Tuple(d,first,last) ) 00083 { CGAL_assertion_msg(D!=FT(0),"PointCd::constructor: D must be nonzero."); 00084 for (int i=0; i<d; ++i) entry(i)/=D; 00085 } 00086 00087 PointCd(int x, int y, int w = 1) : Base( Tuple((FT)x,(FT)y) ) 00088 { CGAL_assertion_msg(w!=0,"PointCd::construction: w == 0."); 00089 vector_rep()/=w; } 00090 00091 PointCd(const FT& x, const FT& y, const FT& w = 1) 00092 : Base( Tuple(x,y) ) 00093 { CGAL_assertion_msg(w!=FT(0),"PointCd::construction: w == 0."); 00094 vector_rep()/=w; } 00095 00096 PointCd(int x, int y, int z, int w) : 00097 Base( Tuple(FT(x),FT(y),FT(z), MatchHelper()) ) 00098 { CGAL_assertion_msg(w!=0,"PointCd::construction: w == 0."); 00099 vector_rep()/=w; } 00100 00101 PointCd(const FT& x, const FT& y, const FT& z, const FT& w) 00102 : Base( Tuple(x,y,z,MatchHelper()) ) 00103 { CGAL_assertion_msg(w!=FT(0),"PointCd::construction: w == 0."); 00104 vector_rep()/=w; } 00105 00106 PointCd(const PointCd<FT,LA>& p) : Base(p) {} 00107 ~PointCd() {} 00108 00109 int dimension() const { return ptr()->size(); } 00110 00111 FT cartesian(int i) const 00112 { CGAL_assertion_msg((0<=i && i<dimension()), 00113 "PointCd::cartesian(): index out of range."); 00114 return entry(i); 00115 } 00116 FT operator[](int i) const { return cartesian(i); } 00117 FT homogeneous(int i) const 00118 { CGAL_assertion_msg((0<=i && i<=(dimension())), 00119 "PointCd::homogeneous(): index out of range."); 00120 if (i!=dimension()) return entry(i); else return FT(1); 00121 } 00122 00123 Cartesian_const_iterator cartesian_begin() const 00124 { return ptr()->begin(); } 00125 Cartesian_const_iterator cartesian_end() const 00126 { return ptr()->end(); } 00127 00128 Homogeneous_const_iterator homogeneous_begin() const 00129 { return Homogeneous_const_iterator(ptr()->begin(),ptr()->end()); } 00130 Homogeneous_const_iterator homogeneous_end() const 00131 { return Homogeneous_const_iterator(ptr()->beyondend()); } 00132 00133 PointCd<FT,LA> transform(const Aff_transformationCd<FT,LA>& t) const; 00134 00135 inline VectorCd<FT,LA> operator-(const Origin& o) const; 00136 00137 VectorCd<FT,LA> operator-(const PointCd<FT,LA>& q) const 00138 { VectorCd<FT,LA> res(dimension()); 00139 res.ptr()->cartesian_sub(ptr(),q.ptr()); 00140 return res; 00141 } 00142 00143 PointCd<FT,LA> operator+(const VectorCd<FT,LA>& v) const; 00144 PointCd<FT,LA> operator-(const VectorCd<FT,LA>& v) const; 00145 PointCd<FT,LA>& operator+=(const VectorCd<FT,LA>& v); 00146 PointCd<FT,LA>& operator-=(const VectorCd<FT,LA>& v); 00147 00148 static Comparison_result cmp( 00149 const PointCd<FT,LA>& p1, const PointCd<FT,LA>& p2) 00150 { Compare_componentwise<FT,LA> cmpobj; 00151 return cmpobj(p1.vector_rep(),p2.vector_rep()); 00152 } 00153 00154 bool operator==(const PointCd<FT,LA>& q) const 00155 { if (this->identical(q)) return true; 00156 if (dimension()!=q.dimension()) return false; 00157 return vector_rep()==q.vector_rep(); 00158 } 00159 00160 bool operator!=(const PointCd<FT,LA>& q) const 00161 { return !(*this==q); } 00162 00163 bool operator==(const Origin&) const 00164 { for (int i = 0; i < dimension(); i++) 00165 if (cartesian(i) != FT(0)) return false; 00166 return true; 00167 } 00168 00169 friend std::istream& operator>> <> 00170 (std::istream&, PointCd<FT,LA>&); 00171 friend std::ostream& operator<< <> 00172 (std::ostream&, const PointCd<FT,LA>&); 00173 00174 FT hx() const { return cartesian(0); } 00175 FT hy() const { return cartesian(1); } 00176 FT hz() const { return cartesian(2); } 00177 FT hw() const { return FT(1); } 00178 FT x() const { return cartesian(0); } 00179 FT y() const { return cartesian(1); } 00180 FT z() const { return cartesian(2); } 00181 00182 }; // PointCd 00183 00184 #undef PointCd 00185 CGAL_END_NAMESPACE 00186 #endif // CGAL_POINTCDXXX_H 00187 //----------------------- end of file ---------------------------------- 00188
 1.7.6.1