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 #ifndef MLN_CORE_CONCEPT_POINT_SITE_HH
00027 # define MLN_CORE_CONCEPT_POINT_SITE_HH
00028 
00034 # include <mln/core/concept/object.hh>
00035 # include <mln/core/concept/delta_point_site.hh>
00036 # include <mln/core/grids.hh>
00037 # include <mln/trait/all.hh>
00038 
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   
00045   template <typename E> struct Point_Site;
00046 
00047 
00048 
00049   namespace trait
00050   {
00051 
00052     template < typename P, typename D >
00053     struct set_binary_< op::plus,
00054                         mln::Point_Site, P, mln::Delta_Point_Site, D >
00055     {
00056       typedef mln_point(P) ret;
00057     };
00058 
00059     template < typename P, typename D >
00060     struct set_binary_< op::minus,
00061                         mln::Point_Site, P, mln::Delta_Point_Site, D >
00062     {
00063       typedef mln_point(P) ret;
00064     };
00065 
00066     template < typename L, typename R >
00067     struct set_binary_< op::minus,
00068                         mln::Point_Site, L, mln::Point_Site, R >
00069     {
00070       typedef mln_dpoint(L) ret;
00071     };
00072 
00073   } 
00074 
00075 
00076 
00077 
00079   template <>
00080   struct Point_Site<void>
00081   {
00082     typedef Object<void> super;
00083   };
00084 
00085 
00105   template <typename E>
00106   struct Point_Site : public Object<E>
00107   {
00108     typedef Point_Site<void> category;
00109 
00110     
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123   protected:
00124     Point_Site();
00125   };
00126 
00127 
00142   template <typename L, typename R>
00143   bool operator==(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
00144 
00145 
00167   template <typename L, typename R>
00168   mln_dpoint(L)
00169   operator-(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
00170 
00171 
00185   template <typename P, typename D>
00186   mln_point(P)
00187   operator+(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
00189 
00190 
00204   template <typename P, typename D>
00205   mln_point(P)
00206   operator-(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
00208 
00209 
00219   template <typename P>
00220   std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p);
00221 
00222 
00223 
00224 
00225 # ifndef MLN_INCLUDE_ONLY
00226 
00227   template <typename E>
00228   inline
00229   Point_Site<E>::Point_Site()
00230   {
00231     int dim = E::dim;
00232     mln_invariant(dim > 0);
00233     dim = 0;
00234     typedef mln_mesh(E)   mesh;
00235     typedef mln_point(E)  point;
00236     typedef mln_dpoint(E) dpoint;
00237     typedef mln_coord(E)  coord;
00238     const point& (E::*m1)() const = & E::to_point;
00239     m1 = 0;
00240     coord (E::*m2)(unsigned i) const = & E::operator[];
00241     m2 = 0;
00242   }
00243 
00244 
00245   
00246 
00247   
00248   
00249   template <typename L, typename R>
00250   inline
00251   bool operator==(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
00252   {
00253     mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
00254     const L& lhs = exact(lhs_);
00255     const R& rhs = exact(rhs_);
00256     for (unsigned i = 0; i < L::dim; ++i)
00257       if (lhs[i] != rhs[i])
00258         return false;
00259     return true;
00260   }
00261 
00262   
00263   
00264   template <typename L, typename R>
00265   inline
00266   mln_dpoint(L) 
00267   operator-(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
00268   {
00269     mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
00270     const L& lhs = exact(lhs_);
00271     const R& rhs = exact(rhs_);
00272     mln_dpoint(L) tmp;
00273     for (unsigned i = 0; i < L::dim; ++i)
00274       tmp[i] = lhs[i] - rhs[i];
00275     mln_postcondition(rhs_ + tmp == lhs_);
00276     return tmp;
00277   }
00278 
00279   template <typename P, typename D>
00280   inline
00281   mln_point(P) 
00282   operator+(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
00283   {
00284     mln::metal::bool_<(int(P::dim) == int(D::dim))>::check();
00285     const P& p  = exact(p_);
00286     const D& dp = exact(dp_);
00287     mln_point(P) tmp;
00288     for (unsigned i = 0; i < P::dim; ++i)
00289       tmp[i] = p[i] + dp[i];
00290     return tmp;
00291   }
00292 
00293   template <typename P, typename D>
00294   inline
00295   mln_point(P) 
00296   operator-(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
00297   {
00298     mln::metal::bool_<(int(P::dim) == int(D::dim))>::check();
00299     const P& p  = exact(p_);
00300     const D& dp = exact(dp_);
00301     mln_point(P) tmp;
00302     for (unsigned i = 0; i < P::dim; ++i)
00303       tmp[i] = p[i] - dp[i];
00304     return tmp;
00305   }
00306 
00307   
00308   
00309   template <typename P>
00310   inline
00311   std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p_)
00312   {
00313     const P& p = exact(p_);
00314     ostr << '(';
00315     for (unsigned i = 0; i < P::dim; ++i)
00316         ostr << p[i] << (i == P::dim - 1 ? ')' : ',');
00317     return ostr;
00318   }
00319 
00320 # endif // ! MLN_INCLUDE_ONLY
00321 
00322 } 
00323 
00324 
00325 #endif // ! MLN_CORE_CONCEPT_POINT_SITE_HH