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_DPOINT_HH
00029 # define OLENA_CORE_ABSTRACT_DPOINT_HH
00030
00031 # include <mlc/type.hh>
00032 # include <oln/core/coord.hh>
00033 # include <ntg/float.hh>
00034 # include <cmath>
00035
00036 namespace oln {
00037
00038
00039 namespace abstract {
00040 template<class Exact>
00041 struct dpoint;
00042
00043 template<class Exact>
00044 struct point;
00045 }
00046
00047 template<class Exact>
00048 struct dpoint_traits;
00049
00055 template<class Exact>
00056 struct dpoint_traits<abstract::dpoint<Exact> >
00057 {
00058
00059 };
00060
00061
00062 namespace abstract {
00063
00070 template<class Exact>
00071 struct dpoint : public mlc_hierarchy::any<Exact>
00072 {
00073
00074 typedef Exact exact_type;
00075 typedef dpoint<Exact> self_type;
00076 enum { dim = dpoint_traits<exact_type>::dim };
00077 typedef typename dpoint_traits<exact_type>::point_type point_type;
00078
00083 explicit dpoint(const abstract::point<point_type>& p)
00084 {
00085 for (unsigned i = 0; i < dim; ++i)
00086 nth(i) = p.exact().nth(i);
00087 }
00088
00090
00091 coord
00092 nth(const unsigned d) const
00093 {
00094 return coord_[d];
00095 }
00096
00098 coord&
00099 nth(const unsigned d)
00100 {
00101 return coord_[d];
00102 }
00103
00108 exact_type
00109 operator-() const
00110 {
00111 return this->exact().minus();
00112 }
00113
00119 exact_type&
00120 operator+=(const self_type& dp)
00121 {
00122 return this->exact().plus_assign_dp(dp.exact());
00123 }
00124
00130 exact_type&
00131 operator-=(const self_type& dp)
00132 {
00133 return this->exact().minus_assign_dp(dp.exact());
00134 }
00135
00141 exact_type
00142 operator+(const self_type& dp) const
00143 {
00144 return this->exact().plus_dp(dp.exact());
00145 }
00146
00152 exact_type
00153 operator-(const self_type& dp) const
00154 {
00155 return this->exact().minus_dp(dp.exact());
00156 }
00157
00166 bool
00167 operator==(const self_type& dp) const
00168 {
00169 for (unsigned i = 0; i < dim; ++i)
00170 if (dp.nth(i) != nth(i))
00171 return false;
00172 return true;
00173 }
00174
00183 bool
00184 operator!=(const self_type& dp) const
00185 {
00186 for (unsigned i = 0; i < dim; ++i)
00187 if (dp.nth(i) != nth(i))
00188 return true;
00189 return false;
00190 }
00191
00198 bool
00199 is_centered(void) const
00200 {
00201 for (unsigned i = 0; i < dim; ++i)
00202 if (nth(i) != 0)
00203 return false;
00204 return true;
00205 }
00206
00208
00209 ntg::float_d
00210 norm2(void) const
00211 {
00212 double norm = 0;
00213
00214 for (unsigned i = 0; i < dim; ++i)
00215 norm += nth(i) * nth(i);
00216 return sqrt(norm);
00217 }
00218
00220
00221 ntg::float_d
00222 sqr_norm2(void) const
00223 {
00224 double norm = 0;
00225
00226 for (unsigned i = 0; i < dim; ++i)
00227 norm += nth(i) * nth(i);
00228 return norm;
00229 }
00230
00231 static std::string
00232 name()
00233 {
00234 return std::string("dpoint<") +
00235 Exact::name() + ">";
00236 }
00237
00238 protected:
00239
00240 dpoint()
00241 {}
00242
00243 private:
00244
00245 coord coord_[dim];
00246 };
00247
00248 }
00249
00252 namespace internal
00253 {
00254
00261 template<class Exact>
00262 struct default_less< abstract::dpoint<Exact> >
00263 {
00264
00271 bool operator()(const abstract::dpoint<Exact>& l,
00272 const abstract::dpoint<Exact>& r) const
00273 {
00274 for (unsigned i = 0; i < abstract::dpoint<Exact>::dim; ++i)
00275 if (l.nth(i) < r.nth(i))
00276 return true;
00277 else if (l.nth(i) > r.nth(i))
00278 return false;
00279 return false;
00280 }
00281 };
00282
00283 }
00284
00285
00286 }
00287
00288
00289 #endif // ! OLENA_CORE_ABSTRACT_DPOINT_HH