00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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;
00043
00044 template<class Exact>
00045 struct dpoint;
00046 }
00047
00048 template<class Exact>
00049 struct point_traits;
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 }
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 }
00269
00270 }
00271
00272
00273 #endif // ! OLENA_CORE_ABSTRACT_POINT_HH