26 #ifndef MLN_CORE_CONCEPT_GPOINT_HH
27 # define MLN_CORE_CONCEPT_GPOINT_HH
34 # include <mln/core/concept/site.hh>
35 # include <mln/core/concept/gdpoint.hh>
36 # include <mln/value/scalar.hh>
37 # include <mln/algebra/vec.hh>
38 # include <mln/util/ord.hh>
39 # include <mln/debug/format.hh>
46 template <
typename E>
struct Gpoint;
53 template <
typename P,
typename D >
54 struct set_binary_< op::
plus,
60 template <
typename P,
typename D >
61 struct set_binary_< op::
minus,
67 template <
typename L,
typename R >
68 struct set_binary_< op::
minus,
71 typedef mln_delta(L) ret;
74 template < typename L, typename R >
75 struct set_binary_< op::times,
77 mln::Object, mln::value::scalar_<R> >
82 template <
typename L,
typename R >
83 struct set_binary_< op::
div,
93 typedef mln::internal::ord_vec< P > ret;
104 typedef Site<void> super;
114 template <
typename E>
136 template <
typename P>
138 from_to_(
const Gpoint<P>& from, mln_delta(P)& to);
140 template <
typename P,
unsigned n,
typename T>
142 from_to_(
const Gpoint<P>& from, algebra::vec<n,T>& to);
144 template <
unsigned n,
typename T,
typename P>
146 from_to_(
const algebra::vec<n,T>& from,
Gpoint<P>& to);
168 template <
typename L,
typename R>
169 bool operator==(
const Gpoint<L>& lhs,
const Gpoint<R>& rhs);
192 template <
typename L,
typename R>
194 operator-(const Gpoint<L>& lhs, const Gpoint<R>& rhs);
209 template <typename P, typename D>
211 operator+(const Gpoint<P>& p, const Gdpoint<D>& dp);
227 template <typename P, typename D>
229 operator-(const Gpoint<P>& p, const Gdpoint<D>& dp);
234 template <typename P, typename S>
236 operator*(const Gpoint<P>& p, const value::scalar_<S>& s);
247 template <typename P>
248 std::ostream& operator<<(std::ostream& ostr, const Gpoint<P>& p);
261 template <typename P, typename D>
262 P& operator+=(Gpoint<P>& p, const Gdpoint<D>& dp);
275 template <typename P, typename D>
276 P& operator-=(Gpoint<P>& p, const Gdpoint<D>& dp);
285 template <typename P, typename D>
286 P operator/(const Gpoint<P>& p, const value::scalar_<D>& dp);
292 # ifndef MLN_INCLUDE_ONLY
297 template <
typename E>
301 typedef mln_grid(E) grid;
302 typedef mln_delta(E) delta;
303 typedef mln_vec(E) vec;
304 vec (E::*m)() const = & E::to_vec;
318 template <
typename P>
321 from_to_(
const Gpoint<P>& p_, mln_delta(P)& dp)
327 const P& p = exact(p_);
328 for (
unsigned i = 0; i < n; ++i)
333 template <
typename P,
unsigned n,
typename T>
336 from_to_(
const Gpoint<P>& from_, algebra::vec<n,T>& to)
338 mlc_bool(n == P::dim)::check();
339 const P& from = exact(from_);
340 for (
unsigned i = 0; i < n; ++i)
341 to[i] = static_cast< T >(from[i]);
345 template <
unsigned n,
typename T,
typename P>
348 from_to_(
const algebra::vec<n,T>& from, Gpoint<P>& to_)
350 mlc_bool(P::dim == n)::check();
352 for (
unsigned i = 0; i < n; ++i)
353 to[i] = static_cast< typename P::coord >(from[i]);
363 template <
typename L,
typename R>
367 mlc_equal(mln_grid(L), mln_grid(R))::check();
368 return exact(lhs).to_vec() == exact(rhs).to_vec();
371 template <
typename L,
typename R>
376 mlc_equal(mln_grid(L), mln_grid(R))::check();
377 mln_delta(L) tmp = exact(lhs).to_vec() - exact(rhs).to_vec();
378 mln_postcondition(rhs + tmp == lhs);
382 template <
typename P,
typename D>
387 mlc_equal(mln_grid(P), mln_grid(D))::check();
388 P tmp = exact(p).to_vec() + exact(dp).to_vec();
392 template <
typename P,
typename D>
397 mlc_equal(mln_grid(P), mln_grid(D))::check();
398 P tmp = exact(p).to_vec() - exact(dp).to_vec();
402 template <
typename P,
typename S>
405 operator*(
const Gpoint<P>& p,
const value::scalar_<S>& s)
408 const unsigned n = P::dim;
410 for (
unsigned i = 0; i < n; ++i)
415 template <
typename P>
417 std::ostream& operator<<(std::ostream& ostr, const Gpoint<P>& p)
421 for (
unsigned i = 0; i < n; ++i)
422 ostr <<
debug::format(exact(p)[i]) << (i == n - 1 ?
')' :
',');
426 template <
typename P,
typename D>
430 mlc_equal(mln_grid(P), mln_grid(D))::check();
431 return exact(p) = p + dp;
434 template <
typename P,
typename D>
438 mlc_equal(mln_grid(P), mln_grid(D))::check();
439 return exact(p) = p - dp;
443 template <
typename P,
typename S>
446 operator/(
const Gpoint<P>& p,
const value::scalar_<S>& s_)
449 const unsigned n = P::dim;
451 for (
unsigned i = 0; i < n; ++i)
456 # endif // ! MLN_INCLUDE_ONLY
462 #endif // ! MLN_CORE_CONCEPT_GPOINT_HH