• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

point.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_CORE_CONCEPT_POINT_HH
00027 # define MLN_CORE_CONCEPT_POINT_HH
00028 
00034 # include <mln/core/concept/point_site.hh>
00035 # include <mln/core/concept/dpoint.hh>
00036 # include <mln/value/concept/scalar.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042   // Fwd decl.
00043   template <typename E> struct Point;
00044 
00045 
00046   // Point category flag type.
00047   template <>
00048   struct Point<void>
00049   {
00050     typedef Point_Site<void> super;
00051   };
00052 
00053 
00061   template <typename P>
00062   struct Point : public Point_Site<P>
00063   {
00066     typedef P point;
00067 
00070     const P& to_point() const;
00071 
00072   protected:
00073     Point();
00074   };
00075 
00076 
00088   template <typename P, typename D>
00089   P& operator+=(Point<P>& p, const Dpoint<D>& dp);
00090 
00091 
00103   template <typename P, typename D>
00104   P& operator-=(Point<P>& p, const Dpoint<D>& dp);
00105 
00114   template <typename P, typename D>
00115   P& operator/(Point<P>& p, const value::Scalar<D>& dp);
00116 
00117   // FIXME : add operators and traits?
00118 
00119 # ifndef MLN_INCLUDE_ONLY
00120 
00121   template <typename P>
00122   inline
00123   Point<P>::Point()
00124   {
00125   }
00126 
00127   template <typename P>
00128   inline
00129   const P&
00130   Point<P>::to_point() const
00131   {
00132     return exact(*this);
00133   }
00134 
00135   template <typename P, typename D>
00136   inline
00137   P& operator+=(Point<P>& p_, const Dpoint<D>& dp_)
00138   {
00139     P& p = exact(p_);
00140     const D& dp = exact(dp_);
00141     // FIXME: Use to_vec()!
00142     for (unsigned i = 0; i < P::dim; ++i)
00143       p[i] += dp[i];
00144     return p;
00145   }
00146 
00147   template <typename P, typename D>
00148   inline
00149   P& operator-=(Point<P>& p_, const Dpoint<D>& dp_)
00150   {
00151     P& p = exact(p_);
00152     const D& dp = exact(dp_);
00153     // FIXME: Use to_vec()!
00154     for (unsigned i = 0; i < P::dim; ++i)
00155       p[i] -= dp[i];
00156     return p;
00157   }
00158 
00159 
00160   template <typename P, typename D>
00161   inline
00162   P&
00163   operator/(Point<P>& p_, const value::Scalar<D>& s_)
00164   {
00165     P& p = exact(p_);
00166     const D& s = exact(s_);
00167     for (unsigned i = 0; i < P::dim; ++i)
00168       p[i] /= s;
00169     return p;
00170   }
00171 
00172 # endif // ! MLN_INCLUDE_ONLY
00173 
00174 } // end of namespace mln
00175 
00176 
00177 
00178 #endif // ! MLN_CORE_CONCEPT_POINT_HH

Generated on Tue Oct 4 2011 15:24:19 for Milena (Olena) by  doxygen 1.7.1