
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Introduce Gpoint and Gdpoint. The concepts of Point_Site and Delta_Point_Site are made obsolete. They are replaced by Gpoint and Gdpoint ('G' meaning "grid" for short). As a consequence, the concept of Point is also obsolete. * doc/tutorial/examples/p_array.cc: Add an assertion. * mln/core/macros.hh (mln_delta, mln_vec): New. * mln/core/point.hh (M): Rename parameter as... (G): ...this; it is a Grid type (not a mesh). (point_): Change inheritance to Gpoint. (grid, vec, delta): New. (point_): New overload ctor for vec. * mln/core/dpoint.hh: Likewise. * mln/core/point2d.hh: Layout. * mln/core/concept/status.txt: New. * mln/core/concept/point.hh: Copy to... * mln/core/concept/gpoint.hh: ...this new file. (operator): Now rely on to_vec, no more on [i]. * mln/core/concept/delta_point_site.hh: Copy to... * mln/core/concept/gdpoint.hh: ...this new file. (operator): Now rely on to_vec, no more on [i]. doc/tutorial/examples/p_array.cc | 3 mln/core/concept/gdpoint.hh | 132 ++++++------------- mln/core/concept/gpoint.hh | 265 +++++++++++++++++++++++++++++++-------- mln/core/concept/status.txt | 10 + mln/core/dpoint.hh | 131 ++++++++++--------- mln/core/macros.hh | 22 +++ mln/core/point.hh | 195 +++++++++++++++------------- mln/core/point2d.hh | 107 +++++++++++---- 8 files changed, 544 insertions(+), 321 deletions(-) Index: doc/tutorial/examples/p_array.cc --- doc/tutorial/examples/p_array.cc (revision 2029) +++ doc/tutorial/examples/p_array.cc (working copy) @@ -55,10 +55,13 @@ { mln_piter_(Arr2) p(arr2); for_all(p) + { +// mln_assertion(make::point2d(p.row(), p.col()) == p); // FIXME: Make it work. std::cout << "point " << p << ": #" << index_of_in(p, arr2) << " in arr2, #" << index_of_in(p, arr1) << " in arr1" << std::endl; } + } mln_invariant(arr2 < arr1); } Index: mln/core/macros.hh --- mln/core/macros.hh (revision 2029) +++ mln/core/macros.hh (working copy) @@ -91,6 +91,12 @@ // d +/// Shortcuts to access the delta type associated to T. +/// \{ +# define mln_delta(T) typename T::delta +# define mln_delta_(T) T::delta +/// \} + /// Shortcuts to access the dpoint type associated to T. /// \{ # define mln_dpoint(T) typename T::dpoint @@ -145,6 +151,16 @@ # define mln_fwd_viter_(T) T::fwd_viter /// \} + +// g + +/// Shortcuts to access the grid type associated to T. +/// \{ +# define mln_grid(T) typename T::grid +# define mln_grid_(T) T::grid +/// \} + + // i /// Shortcuts to access the image type associated to T. @@ -275,6 +291,12 @@ # define mln_value_(T) T::value /// \} +/// Shortcuts to access the algebra::vector (vec) type associated to T. +/// \{ +# define mln_vec(T) typename T::vec +# define mln_vec_(T) T::vec +/// \} + /// Shortcuts to access the type of value set (vset) associated to T. /// \{ # define mln_vset(T) typename T::vset Index: mln/core/point.hh --- mln/core/point.hh (revision 2029) +++ mln/core/point.hh (working copy) @@ -32,10 +32,10 @@ * * \brief Definition of the generic point class mln::point_. * - * \todo Try to generalize less_than with Ml and Mr. + * \todo Try to generalize less_than with Gl and Gr. */ -# include <mln/core/concept/point.hh> +# include <mln/core/concept/gpoint.hh> # include <mln/core/internal/coord_impl.hh> # include <mln/fun/i2v/all_to.hh> @@ -49,8 +49,8 @@ { /// \{ Fwd decls. - template <typename M, typename C> struct point_; - template <typename M, typename C> struct dpoint_; + template <typename G, typename C> struct point_; + template <typename G, typename C> struct dpoint_; namespace literal { struct zero_t; struct one_t; @@ -64,11 +64,11 @@ // Helper point_to_. - template <typename M, typename C> + template <typename G, typename C> struct point_to_ { - typedef algebra::vec<M::dim, C> metal_vec; - typedef mln::h_vec<M::dim, C> h_vec; + typedef algebra::vec<G::dim, C> metal_vec; + typedef mln::h_vec<G::dim, C> h_vec; }; } // end of namespace mln::internal @@ -80,28 +80,34 @@ * Parameters are \c n the dimension of the space and \c C the * coordinate type in this space. */ - template <typename M, typename C> - struct point_ : public Point< point_<M,C> >, - public internal::mutable_coord_impl_< M::dim, C, point_<M,C> > + template <typename G, typename C> + struct point_ : public Gpoint< point_<G,C> >, + public internal::mutable_coord_impl_< G::dim, C, point_<G,C> > { /*! \var dim * \brief Dimension of the space. * \invariant dim > 0 */ - enum { dim = M::dim }; + enum { dim = G::dim }; - /// Mesh associated type. - typedef M mesh; + /// Grid associated type. + typedef G grid; /// Dpoint associated type. - typedef dpoint_<M,C> dpoint; + typedef dpoint_<G,C> dpoint; + + /// Delta associated type. + typedef dpoint_<G,C> delta; /// DPsite associated type. - typedef dpoint_<M,C> dpsite; + typedef dpoint_<G,C> dpsite; /// Coordinate associated type. typedef C coord; + /// Algebra vector (vec) associated type. + typedef algebra::vec<G::dim, C> vec; + /*! \brief Read-only access to the \p i-th coordinate value. * \param[in] i The coordinate index. * \pre \p i < \c dim @@ -117,6 +123,10 @@ /// Constructor without argument. point_(); + /// Constructor from an algebra vector. + template <typename C2> + point_(const algebra::vec<dim,C2>& v); + /// \{ Constructors with different numbers of arguments /// (coordinates) w.r.t. the dimension. point_(C ind); @@ -126,12 +136,12 @@ /// \{ Constructors/assignments with literals. point_(const literal::origin_t&); - point_<M,C>& operator=(const literal::origin_t&); + point_<G,C>& operator=(const literal::origin_t&); // Works only in 1D: point_(const literal::zero_t&); - point_<M,C>& operator=(const literal::zero_t&); + point_<G,C>& operator=(const literal::zero_t&); point_(const literal::one_t&); - point_<M,C>& operator=(const literal::one_t&); + point_<G,C>& operator=(const literal::one_t&); /// \} /// Constructor; coordinates are set by function \p f. @@ -142,29 +152,26 @@ void set_all(C c); /// Origin point (all coordinates are 0). - static const point_<M,C> origin; + static const point_<G,C> origin; /// Shifting by \p dp. - point_<M,C>& operator+=(const dpoint& dp); + point_<G,C>& operator+=(const dpoint& dp); /// Shifting by \p the inverse of dp. - point_<M,C>& operator-=(const dpoint& dp); - - /// Type of the array of coordinates. - typedef algebra::vec<M::dim, C> vec_t; + point_<G,C>& operator-=(const dpoint& dp); /// Hook to coordinates. - operator typename internal::point_to_<M, C>::metal_vec () const; - operator algebra::vec<M::dim, float> () const; + operator typename internal::point_to_<G, C>::metal_vec () const; + operator algebra::vec<G::dim, float> () const; /// Explicit conversion towards mln::algebra::vec. - const algebra::vec<M::dim, C>& to_vec() const; + const algebra::vec<G::dim, C>& to_vec() const; /// Transform to point in homogene coordinate system. - h_vec<M::dim, C> to_h_vec() const; + h_vec<G::dim, C> to_h_vec() const; protected: - algebra::vec<M::dim, C> coord_; + algebra::vec<G::dim, C> coord_; }; @@ -183,9 +190,9 @@ * not bound to the way of browsing a domain with a forward point * iterator. */ - template <typename M, typename Cl, typename Cr> - struct less_than< point_<M,Cl>, - point_<M,Cr> > + template <typename G, typename Cl, typename Cr> + struct less_than< point_<G,Cl>, + point_<G,Cr> > { /*! \brief Comparison between a couple of points \a lhs and \a * rhs. @@ -193,8 +200,8 @@ * \return True if \p lhs is before \p rhs in the sense of the * coordinates lexicographic comparison, otherwise false. */ - bool operator()(const point_<M,Cl>& lhs, - const point_<M,Cr>& rhs) const; + bool operator()(const point_<G,Cl>& lhs, + const point_<G,Cr>& rhs) const; }; } // end of namespace mln::util @@ -202,17 +209,17 @@ # ifndef MLN_INCLUDE_ONLY - template <typename M, typename C> + template <typename G, typename C> inline - C point_<M,C>::operator[](unsigned i) const + C point_<G,C>::operator[](unsigned i) const { assert(i < dim); return this->coord_[i]; } - template <typename M, typename C> + template <typename G, typename C> inline - C& point_<M,C>::operator[](unsigned i) + C& point_<G,C>::operator[](unsigned i) { assert(i < dim); return this->coord_[i]; @@ -220,32 +227,40 @@ // Constructors. - template <typename M, typename C> + template <typename G, typename C> + inline + point_<G,C>::point_() + { + } + + template <typename G, typename C> + template <typename C2> inline - point_<M,C>::point_() + point_<G,C>::point_(const algebra::vec<dim,C2>& v) { + coord_ = v; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::point_(C ind) + point_<G,C>::point_(C ind) { metal::bool_<(dim == 1)>::check(); coord_[0] = ind; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::point_(C row, C col) + point_<G,C>::point_(C row, C col) { metal::bool_<(dim == 2)>::check(); coord_[0] = row; coord_[1] = col; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::point_(C sli, C row, C col) + point_<G,C>::point_(C sli, C row, C col) { metal::bool_<(dim == 3)>::check(); coord_[0] = sli; @@ -253,10 +268,10 @@ coord_[2] = col; } - template <typename M, typename C> + template <typename G, typename C> template <typename F> inline - point_<M,C>::point_(const Function_i2v<F>& f_) + point_<G,C>::point_(const Function_i2v<F>& f_) { mlc_converts_to(mln_result(F), C)::check(); const F& f = exact(f_); @@ -264,98 +279,98 @@ coord_[i] = f(i); } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::point_(const literal::origin_t&) + point_<G,C>::point_(const literal::origin_t&) { coord_.set_all(0); } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>& - point_<M,C>::operator=(const literal::origin_t&) + point_<G,C>& + point_<G,C>::operator=(const literal::origin_t&) { coord_.set_all(0); return *this; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::point_(const literal::zero_t&) + point_<G,C>::point_(const literal::zero_t&) { metal::bool_<(dim == 1)>::check(); coord_[0] = 1; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>& - point_<M,C>::operator=(const literal::zero_t&) + point_<G,C>& + point_<G,C>::operator=(const literal::zero_t&) { metal::bool_<(dim == 1)>::check(); coord_[0] = 1; return *this; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::point_(const literal::one_t&) + point_<G,C>::point_(const literal::one_t&) { metal::bool_<(dim == 1)>::check(); coord_[0] = 1; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>& - point_<M,C>::operator=(const literal::one_t&) + point_<G,C>& + point_<G,C>::operator=(const literal::one_t&) { metal::bool_<(dim == 1)>::check(); coord_[0] = 1; return *this; } - template <typename M, typename C> + template <typename G, typename C> inline - void point_<M,C>::set_all(C c) + void point_<G,C>::set_all(C c) { coord_.set_all(c); } - template <typename M, typename C> - const point_<M,C> point_<M,C>::origin = all_to(0); + template <typename G, typename C> + const point_<G,C> point_<G,C>::origin = all_to(0); - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>& - point_<M,C>::operator+=(const dpoint& dp) + point_<G,C>& + point_<G,C>::operator+=(const dpoint& dp) { for (unsigned i = 0; i < dim; ++i) coord_[i] += dp[i]; return *this; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>& - point_<M,C>::operator-=(const dpoint& dp) + point_<G,C>& + point_<G,C>::operator-=(const dpoint& dp) { for (unsigned i = 0; i < dim; ++i) coord_[i] -= dp[i]; return *this; } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::operator typename internal::point_to_<M, C>::metal_vec () const + point_<G,C>::operator typename internal::point_to_<G, C>::metal_vec () const { - return coord_; // FIXME: Is-it OK? + return coord_; // FIXGE: Is-it OK? } - template <typename M, typename C> + template <typename G, typename C> inline - point_<M,C>::operator algebra::vec<M::dim, float> () const + point_<G,C>::operator algebra::vec<G::dim, float> () const { algebra::vec<dim, float> tmp; for (unsigned i = 0; i < dim; ++i) @@ -363,22 +378,22 @@ return tmp; } - template <typename M, typename C> + template <typename G, typename C> inline - const algebra::vec<M::dim, C>& - point_<M,C>::to_vec() const + const algebra::vec<G::dim, C>& + point_<G,C>::to_vec() const { return coord_; } - template <typename M, typename C> + template <typename G, typename C> inline - h_vec<M::dim, C> point_<M,C>::to_h_vec() const + h_vec<G::dim, C> point_<G,C>::to_h_vec() const { - h_vec<M::dim, C> tmp; + h_vec<G::dim, C> tmp; for (unsigned i = 0; i < dim; ++i) tmp[i] = coord_[i]; - tmp[M::dim] = 1; + tmp[G::dim] = 1; return tmp; } @@ -386,13 +401,13 @@ namespace util { - template <typename M, typename Cl, typename Cr> + template <typename G, typename Cl, typename Cr> bool - less_than< point_<M,Cl>, - point_<M,Cr> >::operator()(const point_<M,Cl>& lhs, - const point_<M,Cr>& rhs) const + less_than< point_<G,Cl>, + point_<G,Cr> >::operator()(const point_<G,Cl>& lhs, + const point_<G,Cr>& rhs) const { - enum { n = M::dim }; + enum { n = G::dim }; typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t; static const less_t op = less_t(); return op(lhs.to_vec(), rhs.to_vec()); Index: mln/core/dpoint.hh --- mln/core/dpoint.hh (revision 2029) +++ mln/core/dpoint.hh (working copy) @@ -33,7 +33,7 @@ * \brief Definition of the generic delta-point class mln::dpoint_. */ -# include <mln/core/concept/dpoint.hh> +# include <mln/core/concept/gdpoint.hh> # include <mln/core/internal/coord_impl.hh> # include <mln/fun/i2v/all.hh> # include <mln/algebra/vec.hh> @@ -43,7 +43,7 @@ { /// \{ Fwd decls. - template <typename M, typename C> struct point_; + template <typename G, typename C> struct point_; namespace literal { struct zero_t; struct one_t; @@ -53,34 +53,37 @@ /*! \brief Generic delta-point class. * - * Parameters are \c M the dimension of the space and \c C the + * Parameters are \c G the dimension of the space and \c C the * coordinate type in this space. */ - template <typename M, typename C> - struct dpoint_ : public Dpoint< dpoint_<M,C> >, - public internal::mutable_coord_impl_< M::dim, C, dpoint_<M,C> > + template <typename G, typename C> + struct dpoint_ : public Gdpoint< dpoint_<G,C> >, + public internal::mutable_coord_impl_< G::dim, C, dpoint_<G,C> > { /*! \var dim * \brief Dimension of the space. * \invariant dim > 0 */ - enum { dim = M::dim }; + enum { dim = G::dim }; - /// Mesh associated type. - typedef M mesh; + /// Grid associated type. + typedef G grid; /// Point associated type. - typedef point_<M,C> point; + typedef point_<G,C> point; /// Psite associated type. - typedef point_<M,C> psite; + typedef point_<G,C> psite; /// Site associated type. - typedef point_<M,C> site; + typedef point_<G,C> site; /// Coordinate associated type. typedef C coord; + /// Algebra vector (vec) associated type. + typedef algebra::vec<G::dim, C> vec; + /*! \brief Read-only access to the \p i-th coordinate value. * \param[in] i The coordinate index. * \pre \p i < \c dim @@ -96,6 +99,10 @@ /// Constructor without argument. dpoint_(); + /// Constructor from an algebra vector. + template <typename C2> + dpoint_(const algebra::vec<dim,C2>& v); + /// \{ Constructors with different numbers of arguments /// (coordinates) w.r.t. the dimension. dpoint_(C ind); @@ -105,10 +112,10 @@ /// \{ Constructors/assignments with literals. dpoint_(const literal::zero_t&); - dpoint_<M,C>& operator=(const literal::zero_t&); + dpoint_<G,C>& operator=(const literal::zero_t&); // Works only in 1D: dpoint_(const literal::one_t&); - dpoint_<M,C>& operator=(const literal::one_t&); + dpoint_<G,C>& operator=(const literal::one_t&); /// \} /// Constructor; coordinates are set by function \p f. @@ -120,13 +127,13 @@ /// Conversion towards a algebra::vec. template <typename Q> - operator algebra::vec<M::dim, Q>() const; + operator algebra::vec<G::dim, Q>() const; /// Explicit conversion. - const algebra::vec<M::dim, C>& to_vec() const; + const algebra::vec<G::dim, C>& to_vec() const; protected: - algebra::vec<M::dim, C> coord_; + algebra::vec<G::dim, C> coord_; }; @@ -141,9 +148,9 @@ * * Both delta-points have to be defined on the same topology. */ - template <typename M, typename Cl, typename Cr> - struct less_than< dpoint_<M,Cl>, - dpoint_<M,Cr> > + template <typename G, typename Cl, typename Cr> + struct less_than< dpoint_<G,Cl>, + dpoint_<G,Cr> > { /*! \brief Comparison between a couple of delta-points \a lhs * and \a rhs. @@ -151,8 +158,8 @@ * \return True if \p lhs is before \p rhs in the sense of the * coordinates lexicographic comparison, otherwise false. */ - bool operator()(const dpoint_<M,Cl>& lhs, - const dpoint_<M,Cr>& rhs) const; + bool operator()(const dpoint_<G,Cl>& lhs, + const dpoint_<G,Cr>& rhs) const; }; } // end of namespace mln::util @@ -160,48 +167,56 @@ # ifndef MLN_INCLUDE_ONLY - template <typename M, typename C> + template <typename G, typename C> inline - C dpoint_<M,C>::operator[](unsigned i) const + C dpoint_<G,C>::operator[](unsigned i) const { assert(i < dim); return coord_[i]; } - template <typename M, typename C> + template <typename G, typename C> inline - C& dpoint_<M,C>::operator[](unsigned i) + C& dpoint_<G,C>::operator[](unsigned i) { assert(i < dim); return coord_[i]; } - template <typename M, typename C> + template <typename G, typename C> + inline + dpoint_<G,C>::dpoint_() + { + } + + template <typename G, typename C> + template <typename C2> inline - dpoint_<M,C>::dpoint_() + dpoint_<G,C>::dpoint_(const algebra::vec<dim,C2>& v) { + coord_ = v; } - template <typename M, typename C> + template <typename G, typename C> inline - dpoint_<M,C>::dpoint_(C ind) + dpoint_<G,C>::dpoint_(C ind) { metal::bool_<(dim == 1)>::check(); coord_[0] = ind; } - template <typename M, typename C> + template <typename G, typename C> inline - dpoint_<M,C>::dpoint_(C row, C col) + dpoint_<G,C>::dpoint_(C row, C col) { metal::bool_<(dim == 2)>::check(); coord_[0] = row; coord_[1] = col; } - template <typename M, typename C> + template <typename G, typename C> inline - dpoint_<M,C>::dpoint_(C sli, C row, C col) + dpoint_<G,C>::dpoint_(C sli, C row, C col) { metal::bool_<(dim == 3)>::check(); coord_[0] = sli; @@ -209,44 +224,44 @@ coord_[2] = col; } - template <typename M, typename C> + template <typename G, typename C> inline - dpoint_<M,C>::dpoint_(const literal::zero_t&) + dpoint_<G,C>::dpoint_(const literal::zero_t&) { coord_.set_all(0); } - template <typename M, typename C> + template <typename G, typename C> inline - dpoint_<M,C>& - dpoint_<M,C>::operator=(const literal::zero_t&) + dpoint_<G,C>& + dpoint_<G,C>::operator=(const literal::zero_t&) { coord_.set_all(0); return *this; } - template <typename M, typename C> + template <typename G, typename C> inline - dpoint_<M,C>::dpoint_(const literal::one_t&) + dpoint_<G,C>::dpoint_(const literal::one_t&) { metal::bool_<(dim == 1)>::check(); coord_[0] = 1; } - template <typename M, typename C> + template <typename G, typename C> inline - dpoint_<M,C>& - dpoint_<M,C>::operator=(const literal::one_t&) + dpoint_<G,C>& + dpoint_<G,C>::operator=(const literal::one_t&) { metal::bool_<(dim == 1)>::check(); coord_[0] = 1; return *this; } - template <typename M, typename C> + template <typename G, typename C> template <typename F> inline - dpoint_<M,C>::dpoint_(const Function_i2v<F>& f_) + dpoint_<G,C>::dpoint_(const Function_i2v<F>& f_) { mlc_converts_to(mln_result(F), C)::check(); const F& f = exact(f_); @@ -254,26 +269,26 @@ coord_[i] = f(i); } - template <typename M, typename C> + template <typename G, typename C> inline - void dpoint_<M,C>::set_all(C c) + void dpoint_<G,C>::set_all(C c) { for (unsigned i = 0; i < dim; ++i) coord_[i] = c; } - template <typename M, typename C> + template <typename G, typename C> template <typename Q> inline - dpoint_<M,C>::operator algebra::vec<M::dim, Q> () const + dpoint_<G,C>::operator algebra::vec<G::dim, Q> () const { return coord_; } - template <typename M, typename C> + template <typename G, typename C> inline - const algebra::vec<M::dim, C>& - dpoint_<M,C>::to_vec() const + const algebra::vec<G::dim, C>& + dpoint_<G,C>::to_vec() const { return coord_; } @@ -281,13 +296,13 @@ namespace util { - template <typename M, typename Cl, typename Cr> + template <typename G, typename Cl, typename Cr> bool - less_than< dpoint_<M,Cl>, - dpoint_<M,Cr> >::operator()(const dpoint_<M,Cl>& lhs, - const dpoint_<M,Cr>& rhs) const + less_than< dpoint_<G,Cl>, + dpoint_<G,Cr> >::operator()(const dpoint_<G,Cl>& lhs, + const dpoint_<G,Cr>& rhs) const { - enum { n = M::dim }; + enum { n = G::dim }; typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t; static const less_t op = less_t(); return op(lhs.to_vec(), rhs.to_vec()); Index: mln/core/point2d.hh --- mln/core/point2d.hh (revision 2029) +++ mln/core/point2d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -42,6 +42,12 @@ namespace mln { + /*! \brief Type alias for a point defined on the 2D square grid with + * integer coordinates. + */ + typedef point_<grid::square, int> point2d; + + namespace internal { @@ -50,56 +56,101 @@ template <typename C, typename E> struct site_const_impl< point_<grid::square, C>, E > { + C row() const; + C col() const; + C operator[](unsigned i) const; + private: + const E& exact_() const; + }; + + + // Specialization for point_<M,C>. + + template <typename C, typename E> + struct site_mutable_impl< point_<grid::square, C>, E > : + site_const_impl < point_<grid::square, C>, E > + { + C& row(); + C& col(); + C& operator[](unsigned i); + private: + typedef site_const_impl< point_<grid::square, C>, E > super; + E& exact_(); + }; + + + +# ifndef MLN_INCLUDE_ONLY + // Either unproxy() or to_site() can be used below. In the // former case, the unproxied features ind() because it is a // point_ or another proxy to a point_. - C row() const + + // site_const_impl + + template <typename C, typename E> + C + site_const_impl< point_<grid::square, C>, E >::row() const { - return internal::force_exact<const E>(*this).to_site().row(); + return exact_().to_site().row(); } - C col() const + + template <typename C, typename E> + C + site_const_impl< point_<grid::square, C>, E >::col() const { - return internal::force_exact<const E>(*this).to_site().col(); + return exact_().to_site().col(); } - C operator[](unsigned i) const + + template <typename C, typename E> + C + site_const_impl< point_<grid::square, C>, E >::operator[](unsigned i) const { mln_precondition(i < 2); - return internal::force_exact<const E>(*this).to_site()[i]; + return exact_().to_site()[i]; } - }; - - - // Specialization for point_<M,C>. template <typename C, typename E> - struct site_mutable_impl< point_<grid::square, C>, E > : - site_const_impl < point_<grid::square, C>, E > + const E& + site_const_impl< point_<grid::square, C>, E >::exact_() const { - private: - typedef site_const_impl< point_<grid::square, C>, E > super; - public: + return internal::force_exact<const E>(*this); + } - using super::row; - using super::col; + // site_mutable_impl - C& row() + template <typename C, typename E> + C& + site_mutable_impl< point_<grid::square, C>, E >::row() { - return internal::force_exact<E>(*this).to_site().row(); + return exact_().to_site().row(); } - C& col() + + template <typename C, typename E> + C& + site_mutable_impl< point_<grid::square, C>, E >::col() { - return internal::force_exact<E>(*this).to_site().col(); + return exact_().to_site().col(); } - }; - } // end of namespace mln::internal + template <typename C, typename E> + C& + site_mutable_impl< point_<grid::square, C>, E >::operator[](unsigned i) + { + mln_precondition(i < 2); + return exact_().to_site()[i]; + } + template <typename C, typename E> + E& + site_mutable_impl< point_<grid::square, C>, E >::exact_() + { + return internal::force_exact<E>(*this); + } +# endif // ! MLN_INCLUDE_ONLY - /*! \brief Type alias for a point defined on the 2D square grid with - * integer coordinates. - */ - typedef point_<grid::square, int> point2d; + } // end of namespace mln::internal } // end of namespace mln Index: mln/core/concept/status.txt --- mln/core/concept/status.txt (revision 0) +++ mln/core/concept/status.txt (revision 0) @@ -0,0 +1,10 @@ +obsolete replacement +----------------- -------------- +point -> gpoint +point_site -> pseudo_site + +dpoint -> gdpoint +delta_point_site -> + +point_iterator -> site_iterator +point_set -> site_set Index: mln/core/concept/gpoint.hh --- mln/core/concept/gpoint.hh (revision 2029) +++ mln/core/concept/gpoint.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,16 +25,16 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_CONCEPT_POINT_HH -# define MLN_CORE_CONCEPT_POINT_HH +#ifndef MLN_CORE_CONCEPT_GPOINT_HH +# define MLN_CORE_CONCEPT_GPOINT_HH -/*! \file mln/core/concept/point.hh +/*! \file mln/core/concept/gpoint.hh * - * \brief Definition of the concept of mln::Point. + * \brief Definition of the concept of mln::Gpoint. */ -# include <mln/core/concept/point_site.hh> -# include <mln/core/concept/dpoint.hh> +# include <mln/core/concept/object.hh> +# include <mln/core/concept/gdpoint.hh> # include <mln/value/concept/scalar.hh> @@ -42,14 +42,43 @@ { // Fwd decl. - template <typename E> struct Point; + template <typename E> struct Gpoint; - // Point category flag type. + + namespace trait + { + + template < typename P, typename D > + struct set_binary_< op::plus, + mln::Gpoint, P, mln::Gdpoint, D > + { + typedef P ret; + }; + + template < typename P, typename D > + struct set_binary_< op::minus, + mln::Gpoint, P, mln::Gdpoint, D > + { + typedef P ret; + }; + + template < typename L, typename R > + struct set_binary_< op::minus, + mln::Gpoint, L, mln::Gpoint, R > + { + typedef mln_delta(L) ret; + }; + + } // end of namespace mln::trait + + + + // Gpoint category flag type. template <> - struct Point<void> + struct Gpoint<void> { - typedef Point_Site<void> super; + typedef Object<void> super; }; @@ -60,20 +89,111 @@ * For instance, mln::point2d is the type of elements defined on the * discrete square grid of the 2D plane. */ - template <typename P> - struct Point : public Point_Site<P> + template <typename E> + struct Gpoint : public Object<E> { - /*! \brief The associated point type is itself. + /* + typedef grid; + typedef delta; + typedef vec; + const vec& to_vec() const */ - typedef P point; + protected: + Gpoint(); + }; + + - /*! \brief It is a Point so it returns itself. + /*! \brief Equality comparison between a couple of grid point \p lhs + * and \p rhs. + * + * \param[in] lhs A first grid point. + * \param[in] rhs A second grid point. + * + * \pre Both \p lhs and \p rhs have to be defined on the same + * topology; otherwise this test does not compile. + * + * \return True if both grid points have the same + * coordinates, otherwise false. + * + * \relates mln::Gpoint */ - const P& to_point() const; + template <typename L, typename R> + bool operator==(const Gpoint<L>& lhs, const Gpoint<R>& rhs); - protected: - Point(); - }; + + /*! \brief Difference between a couple of grid point \p lhs and \p + * rhs. + * + * \param[in] lhs A first grid point. + * \param[in] rhs A second grid point. + * + * \warning There is no type promotion in milena so the client + * has to make sure that both points are defined with the same + * type of coordinates. + * + * \pre Both \p lhs and \p rhs have to be defined on the same + * topology and with the same type of coordinates; otherwise this + * test does not compile. + * + * \post The result, \p dp, is such as \p lhs == \p rhs + \p dp. + * + * \return A delta point (temporary object). + * + * \relates mln::Gpoint + * \see mln::Gdpoint + */ + template <typename L, typename R> + mln_delta(L) + operator-(const Gpoint<L>& lhs, const Gpoint<R>& rhs); + + + /*! \brief Add a delta-point \p rhs to a grid point \p lhs. + * + * \param[in] p A grid point. + * \param[in] dp A delta-point. + * + * The type of \p dp has to compatible with the type of \p p. + * + * \return A point (temporary object). + * + * \relates mln::Gpoint + * \see mln::Gdpoint + */ + template <typename P, typename D> + P + operator+(const Gpoint<P>& p, const Gdpoint<D>& dp); + + + + /*! \brief Substract a delta-point \p rhs to a grid point \p lhs. + * + * \param[in] p A grid point. + * \param[in] dp A delta-point. + * + * The type of \p dp has to compatible with the type of \p p. + * + * \return A point (temporary object). + * + * \see mln::Gdpoint + * \see mln::Gdpoint + */ + template <typename P, typename D> + P + operator-(const Gpoint<P>& p, const Gdpoint<D>& dp); + + + /*! \brief Print a grid point \p p into the output stream \p ostr. + * + * \param[in,out] ostr An output stream. + * \param[in] p A grid point. + * + * \return The modified output stream \p ostr. + * + * \relates mln::Gpoint + */ + template <typename P> + std::ostream& operator<<(std::ostream& ostr, const Gpoint<P>& p); /*! \brief Shift a point \p by a delta-point \p dp. @@ -85,10 +205,10 @@ * \pre The type of \p dp has to be compatible with the type of \p * p. * - * \relates mln::Point + * \relates mln::Gpoint */ template <typename P, typename D> - P& operator+=(Point<P>& p, const Dpoint<D>& dp); + P& operator+=(Gpoint<P>& p, const Gdpoint<D>& dp); /*! \brief Shift a point \p by the negate of a delta-point \p dp. @@ -100,10 +220,10 @@ * \pre The type of \p dp has to be compatible with the type of \p * p. * - * \relates mln::Point + * \relates mln::Gpoint */ template <typename P, typename D> - P& operator-=(Point<P>& p, const Dpoint<D>& dp); + P& operator-=(Gpoint<P>& p, const Gdpoint<D>& dp); /*! \brief Divise a point \p by a scalar \p s. * @@ -111,64 +231,101 @@ * \param[in] dp A scalar. * \return A reference to the point \p p once divised by \p s. * - * \relates mln::Point + * \relates mln::Gpoint */ template <typename P, typename D> - P& operator/(Point<P>& p, const value::Scalar<D>& dp); + P operator/(Gpoint<P>& p, const value::Scalar<D>& dp); // FIXME : add operators and traits? + + # ifndef MLN_INCLUDE_ONLY - template <typename P> + // Gpoint + + template <typename E> inline - Point<P>::Point() + Gpoint<E>::Gpoint() { + typedef mln_grid(E) grid; + typedef mln_delta(E) delta; + typedef mln_vec(E) vec; + const vec& (E::*m)() const = & E::to_vec; + m = 0; } - template <typename P> + // Operators. + + template <typename L, typename R> inline - const P& - Point<P>::to_point() const + bool operator==(const Gpoint<L>& lhs, const Gpoint<R>& rhs) { - return exact(*this); + mlc_equal(mln_grid(L), mln_grid(R))::check(); + return exact(lhs).to_vec() == exact(rhs).to_vec(); + } + + template <typename L, typename R> + inline + mln_delta(L) // FIXME: promote! + operator-(const Gpoint<L>& lhs, const Gpoint<R>& rhs) + { + mlc_equal(mln_grid(L), mln_grid(R))::check(); + mln_delta(L) tmp = exact(lhs).to_vec() - exact(rhs).to_vec(); + mln_postcondition(rhs + tmp == lhs); + return tmp; } template <typename P, typename D> inline - P& operator+=(Point<P>& p_, const Dpoint<D>& dp_) + P // FIXME: promote! + operator+(const Gpoint<P>& p, const Gdpoint<D>& dp) { - P& p = exact(p_); - const D& dp = exact(dp_); - // FIXME: Use to_vec()! - for (unsigned i = 0; i < P::dim; ++i) - p[i] += dp[i]; - return p; + mlc_equal(mln_grid(P), mln_grid(D))::check(); + P tmp = exact(p).to_vec() + exact(dp).to_vec(); + return tmp; } template <typename P, typename D> inline - P& operator-=(Point<P>& p_, const Dpoint<D>& dp_) + P // FIXME: promote! + operator-(const Gpoint<P>& p, const Gdpoint<D>& dp) { - P& p = exact(p_); - const D& dp = exact(dp_); - // FIXME: Use to_vec()! - for (unsigned i = 0; i < P::dim; ++i) - p[i] -= dp[i]; - return p; + mlc_equal(mln_grid(P), mln_grid(D))::check(); + P tmp = exact(p).to_vec() - exact(dp).to_vec(); + return tmp; } + template <typename P> + inline + std::ostream& operator<<(std::ostream& ostr, const Gpoint<P>& p) + { + return ostr << exact(p).to_vec(); + } template <typename P, typename D> inline - P& - operator/(Point<P>& p_, const value::Scalar<D>& s_) + P& operator+=(Gpoint<P>& p, const Gdpoint<D>& dp) + { + mlc_equal(mln_grid(P), mln_grid(D))::check(); + return exact(p) = p + dp; + } + + template <typename P, typename D> + inline + P& operator-=(Gpoint<P>& p, const Gdpoint<D>& dp) + { + mlc_equal(mln_grid(P), mln_grid(D))::check(); + return exact(p) = p - dp; + } + + + template <typename P, typename S> + inline + P + operator/(Gpoint<P>& p, const value::Scalar<S>& s_) { - P& p = exact(p_); - const D& s = exact(s_); - for (unsigned i = 0; i < P::dim; ++i) - p[i] /= s; - return p; + return p.to_vec() / s_; } # endif // ! MLN_INCLUDE_ONLY @@ -177,4 +334,4 @@ -#endif // ! MLN_CORE_CONCEPT_POINT_HH +#endif // ! MLN_CORE_CONCEPT_GPOINT_HH Index: mln/core/concept/gdpoint.hh --- mln/core/concept/gdpoint.hh (revision 2029) +++ mln/core/concept/gdpoint.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,12 +25,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH -# define MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH +#ifndef MLN_CORE_CONCEPT_GDPOINT_HH +# define MLN_CORE_CONCEPT_GDPOINT_HH /*! \file mln/core/concept/delta_point_site.hh * - * \brief Definition of the concept of mln::Delta_Point_Site. + * \brief Definition of the concept of mln::Gdpoint. */ # include <mln/core/concept/object.hh> @@ -42,7 +42,7 @@ { // Fwd decl. - template <typename E> struct Delta_Point_Site; + template <typename E> struct Gdpoint; @@ -51,16 +51,16 @@ template < typename L, typename R > struct set_binary_< op::plus, - mln::Delta_Point_Site, L, mln::Delta_Point_Site, R > + mln::Gdpoint, L, mln::Gdpoint, R > { - typedef mln_dpoint(L) ret; + typedef L ret; }; template < typename L, typename R > struct set_binary_< op::minus, - mln::Delta_Point_Site, L, mln::Delta_Point_Site, R > + mln::Gdpoint, L, mln::Gdpoint, R > { - typedef mln_dpoint(L) ret; + typedef L ret; }; } // end of namespace mln::trait @@ -69,7 +69,7 @@ /// Delta point site category flag type. template <> - struct Delta_Point_Site<void> + struct Gdpoint<void> { typedef Object<void> super; }; @@ -78,24 +78,18 @@ /*! \brief FIXME: Doc! */ template <typename E> - struct Delta_Point_Site : public Object<E> + struct Gdpoint : public Object<E> { - typedef Delta_Point_Site<void> category; + typedef Gdpoint<void> category; /* - enum { dim }; - typedef mesh; - - typedef point; - typedef dpoint; - typedef coord; - - const dpoint& to_dpoint() const; - coord operator[](unsigned i) const; + typedef grid; + typedef vec; + const vec& to_vec() const; */ protected: - Delta_Point_Site(); + Gdpoint(); }; @@ -104,25 +98,21 @@ template <typename D> std::ostream& - operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp); - + operator<<(std::ostream& ostr, const Gdpoint<D>& dp); - template <typename L, typename R> - bool - operator==(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); template <typename L, typename R> bool - operator<(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); + operator==(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs); template <typename L, typename R> - mln_dpoint(L) // FIXME: promote! - operator+(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); + L // FIXME: promote! + operator+(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs); template <typename L, typename R> - mln_dpoint(L) // FIXME: promote! - operator-(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); + L // FIXME: promote! + operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs); @@ -131,88 +121,48 @@ template <typename E> inline - Delta_Point_Site<E>::Delta_Point_Site() + Gdpoint<E>::Gdpoint() { - int dim = E::dim; - mln_invariant(dim > 0); - dim = 0; - typedef mln_mesh(E) mesh; - typedef mln_point(E) point; - typedef mln_dpoint(E) dpoint; - typedef mln_coord(E) coord; - const dpoint& (E::*m1)() const = & E::to_dpoint; - m1 = 0; - coord (E::*m2)(unsigned i) const = & E::operator[]; - m2 = 0; + typedef mln_grid(E) grid; + typedef mln_vec(E) vec; + const vec& (E::*m)() const = & E::to_vec; + m = 0; } template <typename D> inline - std::ostream& operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp_) + std::ostream& operator<<(std::ostream& ostr, const Gdpoint<D>& dp) { - const D& dp = exact(dp_); - ostr << '('; - for (unsigned i = 0; i < D::dim; ++i) - ostr << dp[i] << (i == D::dim - 1 ? ')' : ','); - return ostr; + return ostr << exact(dp).to_vec(); } template <typename L, typename R> inline - bool operator==(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) + bool operator==(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs) { - mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); - const L& lhs = exact(lhs_); - const R& rhs = exact(rhs_); - for (unsigned i = 0; i < L::dim; ++i) - if (lhs[i] != rhs[i]) - return false; - return true; - } - - template <typename L, typename R> - inline - bool operator<(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) - { - mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); - const L& lhs = exact(lhs_); - const R& rhs = exact(rhs_); - for (unsigned i = 0; i < L::dim; ++i) - { - if (lhs[i] == rhs[i]) - continue; - return lhs[i] < rhs[i]; - } - return false; + mlc_equal(mln_grid(L), mln_grid(R))::check(); + return exact(lhs).to_vec() == exact(rhs).to_vec(); } template <typename L, typename R> inline - mln_dpoint(L) // FIXME: promote! - operator+(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) + L // FIXME: promote! + operator+(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs) { - mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); - const L& lhs = exact(lhs_); - const R& rhs = exact(rhs_); - mln_dpoint(L) tmp; - for (unsigned i = 0; i < L::dim; ++i) - tmp[i] = lhs[i] + rhs[i]; + mlc_equal(mln_grid(L), mln_grid(R))::check(); + L tmp = exact(lhs).to_vec() + exact(rhs).to_vec(); return tmp; } template <typename L, typename R> inline - mln_dpoint(L) // FIXME: promote! - operator-(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) + L // FIXME: promote! + operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs) { - mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); - const L& lhs = exact(lhs_); - const R& rhs = exact(rhs_); - mln_dpoint(L) tmp; - for (unsigned i = 0; i < L::dim; ++i) - tmp[i] = lhs[i] - rhs[i]; + mlc_equal(mln_grid(L), mln_grid(R))::check(); + L tmp = exact(lhs).to_vec() - exact(rhs).to_vec(); return tmp; } @@ -221,4 +171,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH +#endif // ! MLN_CORE_CONCEPT_GDPOINT_HH