27 #ifndef MLN_CORE_CONCEPT_GPOINT_HH
28 # define MLN_CORE_CONCEPT_GPOINT_HH
35 # include <mln/core/concept/site.hh>
36 # include <mln/core/concept/gdpoint.hh>
37 # include <mln/value/scalar.hh>
38 # include <mln/algebra/vec.hh>
39 # include <mln/util/ord.hh>
40 # include <mln/debug/format.hh>
47 template <
typename E>
struct Gpoint;
54 template <
typename P,
typename D >
55 struct set_binary_< op::
plus,
61 template <
typename P,
typename D >
62 struct set_binary_< op::
minus,
68 template <
typename L,
typename R >
69 struct set_binary_< op::
minus,
72 typedef mln_delta(L)
ret;
75 template < typename L, typename R >
76 struct set_binary_< op::times,
78 mln::Object, mln::
value::scalar_<R> >
83 template <
typename L,
typename R >
84 struct set_binary_< op::
div,
121 template <
typename E>
151 template <
typename L,
typename R>
175 template <
typename L,
typename R>
192 template <typename P, typename D>
210 template <typename P, typename D>
217 template <typename P, typename S>
230 template <typename P>
231 std::ostream& operator<<(std::ostream& ostr, const
Gpoint<P>& p);
244 template <typename P, typename D>
258 template <typename P, typename D>
268 template <typename P, typename D>
275 template <typename P>
280 template <typename P,
unsigned n, typename
T>
286 # ifndef MLN_INCLUDE_ONLY
291 template <
typename E>
295 typedef mln_grid(E) grid;
296 typedef mln_delta(E)
delta;
297 typedef mln_vec(E) vec;
298 vec (E::*m)() const = & E::to_vec;
304 template <typename L, typename R>
306 bool operator==(const
Gpoint<L>& lhs, const
Gpoint<R>& rhs)
308 mlc_equal(mln_grid(L), mln_grid(R))::check();
309 return exact(lhs).to_vec() ==
exact(rhs).to_vec();
312 template <
typename L,
typename R>
315 operator-(const Gpoint<L>& lhs, const Gpoint<R>& rhs)
317 mlc_equal(mln_grid(L), mln_grid(R))::check();
318 mln_delta(L) tmp =
exact(lhs).to_vec() -
exact(rhs).to_vec();
319 mln_postcondition(rhs + tmp == lhs);
323 template <typename P, typename D>
326 operator+(const Gpoint<P>& p, const Gdpoint<D>& dp)
328 mlc_equal(mln_grid(P), mln_grid(D))::check();
329 P tmp =
exact(p).to_vec() +
exact(dp).to_vec();
333 template <
typename P,
typename D>
336 operator-(
const Gpoint<P>& p,
const Gdpoint<D>& dp)
338 mlc_equal(mln_grid(P), mln_grid(D))::check();
339 P tmp =
exact(p).to_vec() -
exact(dp).to_vec();
343 template <
typename P,
typename S>
346 operator*(
const Gpoint<P>& p,
const value::scalar_<S>& s)
349 const unsigned n = P::dim;
351 for (
unsigned i = 0; i < n; ++i)
356 template <
typename P>
358 std::ostream& operator<<(std::ostream& ostr, const Gpoint<P>&
p)
362 for (
unsigned i = 0; i < n; ++i)
367 template <
typename P,
typename D>
369 P&
operator+=(Gpoint<P>& p,
const Gdpoint<D>& dp)
371 mlc_equal(mln_grid(P), mln_grid(D))::check();
372 return exact(p) = p + dp;
375 template <
typename P,
typename D>
377 P&
operator-=(Gpoint<P>& p,
const Gdpoint<D>& dp)
379 mlc_equal(mln_grid(P), mln_grid(D))::check();
380 return exact(p) = p - dp;
384 template <
typename P,
typename S>
387 operator/(
const Gpoint<P>& p,
const value::scalar_<S>& s_)
390 const unsigned n = P::dim;
392 for (
unsigned i = 0; i < n; ++i)
401 template <
typename P>
404 from_to_(
const Gpoint<P>& p_, mln_delta(P)& dp)
410 const P& p =
exact(p_);
411 for (
unsigned i = 0; i < n; ++i)
415 template <
typename P,
unsigned n,
typename T>
418 from_to_(
const Gpoint<P>& from_, algebra::vec<n,T>& to)
420 mlc_bool(n == P::dim)::check();
421 const P& from =
exact(from_);
422 for (
unsigned i = 0; i < n; ++i)
423 to[i] = static_cast< T >(from[i]);
427 # endif // ! MLN_INCLUDE_ONLY
433 #endif // ! MLN_CORE_CONCEPT_GPOINT_HH