27 #ifndef MLN_CORE_SITE_SET_BOX_HH
28 # define MLN_CORE_SITE_SET_BOX_HH
36 # include <mln/core/concept/box.hh>
37 # include <mln/core/internal/box_impl.hh>
38 # include <mln/core/point.hh>
39 # include <mln/literal/origin.hh>
46 template <
typename P>
class box;
47 template <
typename P>
class box_fwd_piter_;
48 template <
typename P>
class box_bkd_piter_;
55 struct site_set_<
box<P> >
57 typedef trait::site_set::nsites::known
nsites;
58 typedef trait::site_set::bbox::straight bbox;
59 typedef trait::site_set::contents::fixed contents;
60 typedef trait::site_set::arity::unique arity;
64 struct set_precise_unary_< op::ord,
box<P> >
66 typedef set_precise_unary_< op::ord, box<P> > ret;
67 bool strict(
const box<P>& lhs,
const box<P>& rhs)
const;
82 public internal::box_impl_< P::dim, mln_coord(P), box<P> >,
83 private mlc_is_unqualif(P)::check_t
87 enum { dim = P::dim };
127 explicit box(mln_coord(P) ninds);
128 box(mln_coord(P) nrows, mln_coord(P) ncols);
129 box(mln_coord(P) nslis, mln_coord(P) nrows, mln_coord(P) ncols);
136 bool has(
const P& p)
const;
142 void enlarge(
unsigned dim,
unsigned b);
178 template <
typename P>
179 std::ostream& operator<<(std::ostream& ostr, const box<P>& b);
183 template <
typename P>
190 # ifndef MLN_INCLUDE_ONLY
192 template <
typename P>
202 template <
typename P>
207 if (pmin_.col() < ref.
pmin().col())
208 pmin_.col() = ref.
pmin().col();
209 if (pmin_.row() < ref.
pmin().row())
210 pmin_.row() = ref.
pmin().row();
212 if (pmax_.col() > ref.
pmax().col())
213 pmax_.col() = ref.
pmax().col();
214 if (pmax_.row() > ref.
pmax().row())
215 pmax_.row() = ref.
pmax().row();
218 template <
typename P>
223 mln_precondition(is_valid());
230 for (
unsigned i = 0; i < P::dim; ++i)
232 if (b.
pmin()[i] < pmin_[i])
233 pmin_[i] = b.
pmin()[i];
234 if (b.
pmax()[i] > pmax_[i])
235 pmax_[i] = b.
pmax()[i];
239 template <
typename P>
244 mln_precondition(is_valid());
248 template <
typename P>
256 template <
typename P>
261 mln_precondition(is_valid());
265 template <
typename P>
273 template <
typename P>
276 : pmin_(P::plus_infty()),
277 pmax_(P::minus_infty())
282 template <
typename P>
291 template <
typename P>
295 metal::bool_<(dim == 1)>::check();
297 pmax_ = P(ninds - 1);
300 template <
typename P>
302 box<P>::box(mln_coord(P) nrows, mln_coord(P) ncols)
304 metal::bool_<(dim == 2)>::check();
305 mln_precondition(nrows != 0 && ncols != 0);
308 pmax_ = P(--nrows, --ncols);
309 mln_postcondition(is_valid());
312 template <
typename P>
314 box<P>::box(mln_coord(P) nslis, mln_coord(P) nrows, mln_coord(P) ncols)
316 metal::bool_<(dim == 3)>::check();
318 pmax_ = P(nslis - 1, nrows - 1, ncols - 1);
319 mln_postcondition(is_valid());
322 template <
typename P>
327 mln_precondition(is_valid());
328 for (
unsigned i = 0; i < P::dim; ++i)
329 if (p[i] < pmin_[i] || p[i] > pmax_[i])
334 template <
typename P>
339 mln_precondition(is_valid());
340 for (
unsigned i = 0; i < P::dim; ++i)
342 pmin_[i] =
static_cast<mln_coord(P)
>(pmin_[i] - b);
343 pmax_[i] =
static_cast<mln_coord(P)
>(pmax_[i] + b);
345 mln_postcondition(is_valid());
348 template <
typename P>
353 mln_precondition(is_valid());
354 pmin_[dim] =
static_cast<mln_coord(P)
>(pmin_[dim] - b);
355 pmax_[dim] =
static_cast<mln_coord(P)
>(pmax_[dim] + b);
356 mln_postcondition(is_valid());
359 template <
typename P>
366 for (
unsigned i = 0; i < P::dim; i++)
372 return box<P>(pmin, pmax);
375 template <
typename P>
380 mln_precondition(is_valid());
383 for (
unsigned i = 0; i < P::dim; ++i)
385 tmp.pmin_[i] =
static_cast<mln_coord(P)
>(tmp.pmin_[i] - b);
386 tmp.pmax_[i] =
static_cast<mln_coord(P)
>(tmp.pmax_[i] + b);
392 template <
typename P>
397 mln_precondition(is_valid());
399 for (
unsigned i = 0; i < P::dim; ++i)
400 center[i] =
static_cast<mln_coord(P)
>(pmin_[i] + ((pmax_[i] - pmin_[i]) / 2));
404 template <
typename P>
409 return sizeof(*this);
412 template <
typename P>
414 std::ostream& operator<<(std::ostream& ostr, const box<P>& b)
416 mln_precondition(b.is_valid());
417 return ostr <<
"[" << b.pmin() <<
".." << b.pmax() <<
']';
423 template <
typename P>
426 set_precise_unary_< op::ord, box<P> >::strict(
const box<P>& lhs,
const box<P>& rhs)
const
429 return util::ord_lexi_strict(lhs.
pmin(), lhs.
pmax(),
435 # endif // ! MLN_INCLUDE_ONLY
440 # include <mln/core/site_set/box_piter.hh>
443 #endif // ! MLN_CORE_SITE_SET_BOX_HH