26 #ifndef MLN_CORE_CONCEPT_POINT_SITE_HH
27 # define MLN_CORE_CONCEPT_POINT_SITE_HH
34 # include <mln/core/concept/object.hh>
35 # include <mln/core/concept/delta_point_site.hh>
36 # include <mln/core/grids.hh>
37 # include <mln/trait/all.hh>
45 template <
typename E>
struct Point_Site;
52 template <
typename P,
typename D >
53 struct set_binary_< op::
plus,
56 typedef mln_point(P) ret;
59 template < typename P, typename D >
60 struct set_binary_< op::minus,
61 mln::Point_Site, P, mln::Delta_Point_Site, D >
63 typedef mln_point(P) ret;
66 template < typename L, typename R >
67 struct set_binary_< op::minus,
68 mln::Point_Site, L, mln::Point_Site, R >
70 typedef mln_dpoint(L) ret;
80 struct Point_Site<
void>
82 typedef Object<void> super;
105 template <
typename E>
106 struct Point_Site :
public Object<E>
108 typedef Point_Site<void> category;
142 template <
typename L,
typename R>
143 bool operator==(
const Point_Site<L>& lhs,
const Point_Site<R>& rhs);
167 template <
typename L,
typename R>
169 operator-(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
185 template <typename P, typename D>
187 operator+(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
204 template <typename P, typename D>
206 operator-(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
219 template <typename P>
220 std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p);
225 # ifndef MLN_INCLUDE_ONLY
227 template <
typename E>
229 Point_Site<E>::Point_Site()
232 mln_invariant(dim > 0);
234 typedef mln_mesh(E) mesh;
235 typedef mln_point(E) point;
236 typedef mln_dpoint(E) dpoint;
237 typedef mln_coord(E) coord;
238 const point& (E::*m1)() const = & E::to_point;
240 coord (E::*m2)(
unsigned i) const = & E::operator[];
249 template <typename L, typename R>
251 bool operator==(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
253 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
254 const L& lhs = exact(lhs_);
255 const R& rhs = exact(rhs_);
256 for (
unsigned i = 0; i < L::dim; ++i)
257 if (lhs[i] != rhs[i])
264 template <
typename L,
typename R>
267 operator-(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
269 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
270 const L& lhs = exact(lhs_);
271 const R& rhs = exact(rhs_);
273 for (
unsigned i = 0; i < L::dim; ++i)
274 tmp[i] = lhs[i] - rhs[i];
275 mln_postcondition(rhs_ + tmp == lhs_);
279 template <typename P, typename D>
282 operator+(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
284 mln::metal::bool_<(int(P::dim) == int(D::dim))>::check();
285 const P& p = exact(p_);
286 const D& dp = exact(dp_);
288 for (
unsigned i = 0; i < P::dim; ++i)
289 tmp[i] = p[i] + dp[i];
293 template <typename P, typename D>
296 operator-(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
298 mln::metal::bool_<(int(P::dim) == int(D::dim))>::check();
299 const P& p = exact(p_);
300 const D& dp = exact(dp_);
302 for (
unsigned i = 0; i < P::dim; ++i)
303 tmp[i] = p[i] - dp[i];
309 template <typename P>
311 std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p_)
313 const P& p = exact(p_);
315 for (
unsigned i = 0; i < P::dim; ++i)
316 ostr << p[i] << (i == P::dim - 1 ?
')' :
',');
320 # endif // ! MLN_INCLUDE_ONLY
325 #endif // ! MLN_CORE_CONCEPT_POINT_SITE_HH