milena r1224: Fix for accumulator from point to vec<2, float>

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-02 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Fix for accumulator from point to vec<2, float>. * accu/sum.hh, * core/point.hh, * draw/mesh.hh, * metal/vec.hh, * trait/promote.hh, * util/graph.hh, * value/builtin.hh: Update. --- accu/sum.hh | 2 +- core/point.hh | 12 +++++++++++- draw/mesh.hh | 1 + metal/vec.hh | 21 +++++++++++++++++++++ trait/promote.hh | 24 ++++++++++++++++++++++++ util/graph.hh | 9 +++++---- value/builtin.hh | 1 + 7 files changed, 64 insertions(+), 6 deletions(-) Index: trunk/milena/mln/trait/promote.hh =================================================================== --- trunk/milena/mln/trait/promote.hh (revision 1223) +++ trunk/milena/mln/trait/promote.hh (revision 1224) @@ -88,6 +88,30 @@ }; template <> + struct set_precise_binary_< promote, float, unsigned > + { + typedef float ret; + }; + + template <> + struct set_precise_binary_< promote, unsigned, float > + { + typedef float ret; + }; + + template <> + struct set_precise_binary_< promote, unsigned, double > + { + typedef double ret; + }; + + template <> + struct set_precise_binary_< promote, double, unsigned > + { + typedef double ret; + }; + + template <> struct set_precise_binary_< promote, float, double > { typedef double ret; Index: trunk/milena/mln/core/point.hh =================================================================== --- trunk/milena/mln/core/point.hh (revision 1223) +++ trunk/milena/mln/core/point.hh (revision 1224) @@ -122,6 +122,7 @@ /// Hook to coordinates. operator typename internal::point_to_<M, C>::metal_vec () const; + operator metal::vec<M::dim, float> () const; /// Hook to homogene coordinate. operator typename internal::point_to_<M, C>::h_vec () const; @@ -188,7 +189,16 @@ template <typename M, typename C> point_<M,C>::operator typename internal::point_to_<M, C>::metal_vec () const { - return coord_; + return coord_; // FIXME: Is-it OK? + } + + template <typename M, typename C> + point_<M,C>::operator metal::vec<M::dim, float> () const + { + metal::vec<dim, float> tmp; + for (unsigned i = 0; i < dim; ++i) + tmp[i] = coord_[i]; + return tmp; } template <typename M, typename C> Index: trunk/milena/mln/draw/mesh.hh =================================================================== --- trunk/milena/mln/draw/mesh.hh (revision 1223) +++ trunk/milena/mln/draw/mesh.hh (revision 1224) @@ -73,6 +73,7 @@ for (unsigned i = 0; i < m.gr_.nb_node_; ++i) exact(ima)(m.loc_[i]) = node_v; + } template <typename I, typename P, typename V> Index: trunk/milena/mln/metal/vec.hh =================================================================== --- trunk/milena/mln/metal/vec.hh (revision 1223) +++ trunk/milena/mln/metal/vec.hh (revision 1224) @@ -34,6 +34,7 @@ # include <mln/core/concept/object.hh> # include <mln/trait/all.hh> # include <mln/value/props.hh> +# include <mln/fun/i2v/all.hh> // FIXME: Document. @@ -154,6 +155,13 @@ unsigned size() const; const vec<n, T>& normalize(); + + /// Constructor; coordinates are set by function \p f. + template <typename F> + vec(const Function_i2v<F>& f); + + /// Zero value. + static const vec<n, T> zero; }; } // end of namespace mln::metal @@ -380,6 +388,19 @@ } + template <unsigned n, typename T> + template <typename F> + vec<n, T>::vec(const Function_i2v<F>& f_) + { + const F& f = exact(f_); + for (unsigned i = 0; i < n; ++i) + data_[i] = f(i); + } + + template <unsigned n, typename T> + const vec<n, T> vec<n, T>::zero = all(0); + + // eq template <unsigned n, typename T, typename U> Index: trunk/milena/mln/accu/sum.hh =================================================================== --- trunk/milena/mln/accu/sum.hh (revision 1223) +++ trunk/milena/mln/accu/sum.hh (revision 1224) @@ -99,7 +99,7 @@ void sum_<V,S>::init() { - s_ = 0; + s_ = S::zero; // FIXME } template <typename V, typename S> Index: trunk/milena/mln/value/builtin.hh =================================================================== --- trunk/milena/mln/value/builtin.hh (revision 1223) +++ trunk/milena/mln/value/builtin.hh (revision 1224) @@ -49,6 +49,7 @@ }; template <> struct category< int > { typedef Built_In<void> ret; }; + template <> struct category< unsigned > { typedef Built_In<void> ret; }; template <> struct category< float > { typedef Built_In<void> ret; }; template <> struct category< double > { typedef Built_In<void> ret; }; // FIXME: ... Index: trunk/milena/mln/util/graph.hh =================================================================== --- trunk/milena/mln/util/graph.hh (revision 1223) +++ trunk/milena/mln/util/graph.hh (revision 1224) @@ -32,6 +32,8 @@ # include <cstddef> # include <iostream> # include <vector> +# include <list> +# include <algorithm> /*! \file mln/util/graph.hh * @@ -54,7 +56,7 @@ template<> struct s_node<void> { - std::vector<unsigned> links; + std::list<unsigned> links; }; template<typename T> @@ -123,7 +125,6 @@ links_.push_back (edge); ++nb_link_; nodes_[n1]->links.push_back (n2); - nodes_[n2]->links.push_back (n1); } template<typename N, typename E> @@ -135,7 +136,7 @@ typename std::vector<struct s_node <N>*>::const_iterator it = nodes_.begin (); for (; it != nodes_.end (); ++it) { - typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin (); + typename std::list<unsigned>::const_iterator it2 = (*it)->links.begin (); for (; it2 != (*it)->links.end (); ++it2) mln_precondition((*it2) < nb_node_); } @@ -162,7 +163,7 @@ std::cout << "node number = " << i << " nbh : "; - typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin (); + typename std::list<unsigned>::const_iterator it2 = (*it)->links.begin (); for (; it2 != (*it)->links.end (); ++it2) { std::cout << (*it2)
participants (1)
-
Guillaume Duhamel