00001 // Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory 00002 // 00003 // This file is part of the Olena Library. This library is free 00004 // software; you can redistribute it and/or modify it under the terms 00005 // of the GNU General Public License version 2 as published by the 00006 // Free Software Foundation. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this library; see the file COPYING. If not, write to 00015 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 // Boston, MA 02110-1301, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software library without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to 00022 // produce an executable, this file does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public 00024 // License. This exception does not however invalidate any other 00025 // reasons why the executable file might be covered by the GNU General 00026 // Public License. 00027 00028 #ifndef OLENA_CORE_ABSTRACT_POINT_HH 00029 # define OLENA_CORE_ABSTRACT_POINT_HH 00030 00031 # include <mlc/type.hh> 00032 # include <ntg/utils/debug.hh> 00033 # include <oln/core/coord.hh> 00034 00035 # include <iostream> 00036 # include <sstream> 00037 00038 namespace oln 00039 { 00040 namespace abstract { 00041 template<class Exact> 00042 struct point; // fwd declaration 00043 00044 template<class Exact> 00045 struct dpoint; // fwd declaration 00046 } // end of abstract 00047 00048 template<class Exact> 00049 struct point_traits; // fwd declaration 00050 00056 template<class Exact> 00057 struct point_traits<abstract::point<Exact> > 00058 { 00059 00060 }; 00061 00062 namespace abstract { 00063 00070 template<class Exact> 00071 struct point : public mlc_hierarchy::any<Exact> 00072 { 00073 00074 public: 00075 00076 typedef point<Exact> self_type; 00077 typedef Exact exact_type; 00078 typedef typename point_traits<Exact>::dpoint_type dpoint_type; 00079 00080 enum { dim = point_traits<Exact>::dim }; 00081 00083 00084 const exact_type& 00085 point_ref() const 00086 { 00087 return this->exact(); 00088 } 00089 00091 00092 coord 00093 nth(const unsigned dim) const 00094 { 00095 return coord_[dim]; 00096 } 00097 00099 00100 coord& 00101 nth(const unsigned dim) 00102 { 00103 return coord_[dim]; 00104 } 00105 00111 exact_type& 00112 operator+=(const abstract::dpoint<dpoint_type>& dp) 00113 { 00114 return this->exact().plus_assign_dp(dp.exact()); 00115 } 00116 00123 exact_type& 00124 operator-=(const abstract::dpoint<dpoint_type>& dp) 00125 { 00126 return this->exact().minus_assign_dp(dp.exact()); 00127 } 00128 00134 dpoint_type 00135 operator-(const self_type& p) const 00136 { 00137 return this->exact().minus_p(p.exact()); 00138 } 00139 00140 00147 exact_type 00148 operator+(const abstract::dpoint<dpoint_type>& dp) const 00149 { 00150 return this->exact().plus_dp(dp.exact()); 00151 } 00152 00160 exact_type 00161 operator-(const abstract::dpoint<dpoint_type>& dp) const 00162 { 00163 return this->exact().minus_dp(dp.exact()); 00164 } 00165 00170 exact_type 00171 operator-() const 00172 { 00173 return this->exact().minus(); 00174 } 00175 00176 00183 bool 00184 operator==(const self_type& p) const 00185 { 00186 for (unsigned i = 0; i < dim; ++i) 00187 if (p.nth(i) != nth(i)) 00188 return false; 00189 return true; 00190 } 00191 00192 00200 bool 00201 operator!=(const self_type& p) const 00202 { 00203 for (unsigned i = 0; i < dim; ++i) 00204 if (p.nth(i) != nth(i)) 00205 return true; 00206 return false; 00207 } 00208 00209 00210 static std::string name() 00211 { 00212 return std::string("point<") + Exact::name() + ">"; 00213 } 00214 00215 protected: 00216 00217 point() 00218 {} 00219 00220 private: 00221 00226 coord coord_[dim]; 00227 00228 }; 00229 00230 } // end of abstract 00231 00232 00233 namespace internal 00234 { 00235 00241 template<class Exact> 00242 struct default_less< abstract::point<Exact> > 00243 { 00244 00256 bool operator()(const abstract::point<Exact>& l, 00257 const abstract::point<Exact>& r) const 00258 { 00259 for (unsigned i = 0; i < abstract::point<Exact>::dim; ++i) 00260 if (l.nth(i) < r.nth(i)) 00261 return true; 00262 else if (l.nth(i) > r.nth(i)) 00263 return false; 00264 return false; 00265 } 00266 }; 00267 00268 } // internal 00269 00270 } // end of oln 00271 00272 00273 #endif // ! OLENA_CORE_ABSTRACT_POINT_HH