27 #ifndef MLN_CORE_POINT_HH
28 # define MLN_CORE_POINT_HH
40 # include <mln/core/def/coord.hh>
41 # include <mln/core/concept/proxy.hh>
42 # include <mln/core/concept/gpoint.hh>
43 # include <mln/core/internal/coord_impl.hh>
44 # include <mln/fun/i2v/all_to.hh>
46 # include <mln/metal/bool.hh>
47 # include <mln/metal/is_not.hh>
48 # include <mln/algebra/vec.hh>
49 # include <mln/metal/converts_to.hh>
50 # include <mln/algebra/h_vec.hh>
51 # include <mln/util/yes.hh>
58 template <
typename G,
typename C>
struct point;
59 template <
typename G,
typename C>
struct dpoint;
74 template <
typename G,
typename C1,
typename C2>
75 void from_to_(
const point<G,C1>& from, point<G,C2>&
to);
77 template <
unsigned n,
typename C1,
typename G,
typename C2>
79 from_to_(
const mln::algebra::vec<n,C1>& from, point<G,C2>&
to);
81 template <
unsigned n,
typename C1,
typename G>
83 from_to_(
const mln::algebra::vec<n,C1>& from, point<G,C1>&
to);
95 template <
typename G,
typename C>
98 typedef mln::algebra::vec<G::dim, float> ret;
107 template <
typename G,
typename C>
109 public internal::mutable_coord_impl_< G::dim, C, point<G,C> >
134 typedef mln::algebra::vec<G::dim, float>
vec;
161 template <
typename C2>
162 point(
const mln::algebra::vec<dim,C2>& v);
164 point(
const mln::algebra::vec<dim,C>& v);
169 explicit point(C ind);
171 point(C sli, C row, C col);
185 template <
typename F>
206 operator typename internal::vec_of_point<G,C>::ret ()
const;
221 mln::algebra::vec<G::dim, C>& hook_coord_();
224 mln::algebra::vec<G::dim, C> coord_;
233 template <
typename P,
typename E>
236 template <
typename G,
typename C,
typename E>
239 typename point<G,C>::vec to_vec()
const;
243 const E& exact_()
const;
252 template <
typename G,
typename C>
253 const mln::algebra::vec<point<G,C>::dim - 1, C>& cut_(
const point<G,C>& p);
255 template <
typename C>
256 const util::yes& cut_(
const point<grid::tick,C>& p);
260 # ifndef MLN_INCLUDE_ONLY
266 template <
typename C,
typename C2>
269 convert_data_(metal::bool_<false>,
const C2& v)
271 return static_cast<C
>(v);
274 template <
typename C,
typename C2>
277 convert_data_(metal::bool_<true>,
const C2& v)
279 return static_cast<C
>(round(v));
282 template <
typename C,
typename C2>
285 convert_data(
const C2& v)
291 return convert_data_<C>(
293 mlc_and(mlc_is_not(C,
float),
294 mlc_is_not(C,
double)),
295 mlc_or(mlc_is(C2,
float),
296 mlc_is(C2,
double)))::eval(), v);
311 template <
typename G,
typename C1,
typename C2>
314 from_to_(
const point<G,C1>& from, point<G,C2>&
to)
316 mlc_converts_to(C1,C2)::check();
317 enum { dim = G::dim };
319 for (
unsigned i = 0; i < dim; ++i)
320 to[i] = mln::internal::convert_data<C2>(from[i]);
324 template <
unsigned n,
typename C1,
typename G,
typename C2>
327 from_to_(
const mln::algebra::vec<n,C1>& from, point<G,C2>& to)
329 mlc_converts_to(C1, C2)::check();
330 enum { dim = G::dim };
331 mlc_bool(G::dim == n)::check();
334 for (
unsigned i = dim - 2; i < dim; ++i)
335 to[i] = mln::internal::convert_data<C2>(from[j++]);
336 for (
unsigned i = 2; i < dim; ++i, ++j)
337 to[i-j] = mln::internal::convert_data<C2>(from[j]);
340 template <
typename C1,
typename G,
typename C2>
343 from_to_(
const mln::algebra::vec<1,C1>& from, point<G,C2>& to)
345 mlc_converts_to(C1, C2)::check();
346 enum { dim = G::dim };
347 mlc_bool(G::dim == 1)::check();
349 to[0] = mln::internal::convert_data<C2>(from[0]);
352 template <
unsigned n,
typename C1,
typename G>
355 from_to_(
const mln::algebra::vec<n,C1>& from, point<G,C1>& to)
357 enum { dim = G::dim };
358 mlc_bool(G::dim == n)::check();
361 for (
unsigned i = dim - 2; i < dim; ++i)
363 for (
unsigned i = 2; i < dim; ++i, ++j)
367 template <
typename C1,
typename G>
370 from_to_(
const mln::algebra::vec<1,C1>& from, point<G,C1>& to)
372 enum { dim = G::dim };
373 mlc_bool(G::dim == 1)::check();
383 template <
typename G,
typename C>
388 return this->coord_[i];
391 template <
typename G,
typename C>
396 return this->coord_[i];
399 template <
typename G,
typename C>
404 return this->coord_[dim - 1];
407 template <
typename G,
typename C>
412 return this->coord_[dim - 1];
418 template <
typename G,
typename C>
424 template <
typename G,
typename C>
425 template <
typename C2>
429 convert::over_load::from_to_(v, *
this);
433 template <
typename G,
typename C>
437 convert::over_load::from_to_(v, *
this);
441 template <
typename G,
typename C>
445 metal::bool_<(dim == 1)>::check();
449 template <
typename G,
typename C>
453 metal::bool_<(dim == 2)>::check();
458 template <
typename G,
typename C>
462 metal::bool_<(dim == 3)>::check();
468 template <
typename G,
typename C>
469 template <
typename F>
473 mlc_converts_to(mln_result(F), C)::check();
474 const F& f = exact(f_);
475 for (
unsigned i = 0; i < dim; ++i)
476 coord_[i] = static_cast<C>( f(i) );
479 template <
typename G,
typename C>
486 template <
typename G,
typename C>
495 template <
typename G,
typename C>
499 metal::bool_<(dim == 1)>::check();
503 template <
typename G,
typename C>
506 point<G,C>::operator=(
const literal::zero_t&)
508 metal::bool_<(dim == 1)>::check();
513 template <
typename G,
typename C>
517 metal::bool_<(dim == 1)>::check();
521 template <
typename G,
typename C>
524 point<G,C>::operator=(
const literal::one_t&)
526 metal::bool_<(dim == 1)>::check();
531 template <
typename G,
typename C>
538 template <
typename G,
typename C>
541 template <
typename G,
typename C>
546 for (
unsigned i = 0; i < dim; ++i)
547 coord_[i] = static_cast<C>(coord_[i] + dp[i]);
551 template <
typename G,
typename C>
556 for (
unsigned i = 0; i < dim; ++i)
561 template <
typename G,
typename C>
568 template <
typename G,
typename C>
570 typename point<G,C>::vec
576 mln::algebra::vec<G::dim, float> tmp;
578 for (
unsigned i = dim - 2; i < dim; ++i)
579 tmp[j++] = mln::internal::convert_data<float>(coord_[i]);
580 for (
unsigned i = 2; i < dim; ++i, ++j)
581 tmp[j] = mln::internal::convert_data<float>(coord_[i-j]);
589 template <
typename G,
typename C>
602 for (
unsigned i = dim - 2; i < dim; ++i)
603 tmp[j++] = coord_[i];
605 for (
unsigned i = 2; i < dim; ++i, ++j)
606 tmp[j] = coord_[i-j];
615 template <
typename G,
typename C>
620 static const point<G,C> the_(all_to(mln_max(C)));
624 template <
typename G,
typename C>
629 static const point<G,C> the_(all_to(mln_min(C)));
633 template <
typename G,
typename C>
635 mln::algebra::vec<G::dim, C>&
644 template <
typename G,
typename C,
typename E>
649 return internal::force_exact<const E>(*this);
652 template <
typename G,
typename C,
typename E>
654 typename point<G,C>::vec
657 return exact_().get_subject().to_vec();
660 template <
typename G,
typename C,
typename E>
664 return exact_().get_subject();
669 template <
typename G,
typename C>
671 const mln::algebra::vec<point<G,C>::dim - 1, C>&
672 cut_(
const point<G,C>& p)
674 return *(mln::algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec());
677 template <
typename C>
680 cut_(
const point<grid::tick,C>& p)
687 # endif // ! MLN_INCLUDE_ONLY
693 #endif // ! MLN_CORE_POINT_HH