
* mln/core/site_set/box.hh: New member 'merge()'. * tests/core/site_set/Makefile.am, * tests/core/site_set/box.cc: New test. --- milena/ChangeLog | 9 +++++++ milena/mln/core/site_set/box.hh | 24 ++++++++++++++++++++ milena/tests/core/site_set/Makefile.am | 2 + .../{other/box_runend_piter.cc => site_set/box.cc} | 17 +++++++------ 4 files changed, 44 insertions(+), 8 deletions(-) copy milena/tests/core/{other/box_runend_piter.cc => site_set/box.cc} (82%) diff --git a/milena/ChangeLog b/milena/ChangeLog index f76dc74..d94e481 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,14 @@ 2010-02-16 Guillaume Lazzara <z@lrde.epita.fr> + Add box<>::merge. + + * mln/core/site_set/box.hh: New member 'merge()'. + + * tests/core/site_set/Makefile.am, + * tests/core/site_set/box.cc: New test. + +2010-02-16 Guillaume Lazzara <z@lrde.epita.fr> + Rename image3d<>::nslices to image3d<>::nslis. * mln/core/image/image3d.hh, diff --git a/milena/mln/core/site_set/box.hh b/milena/mln/core/site_set/box.hh index 375f534..75fb91c 100644 --- a/milena/mln/core/site_set/box.hh +++ b/milena/mln/core/site_set/box.hh @@ -152,6 +152,9 @@ namespace mln /// Crop this bbox in order to fit in the reference box \p b. void crop_wrt(const box<P>& b); + /// Merge inplace with another box. + void merge(const box<P>& b); + /// Return the size of this site set in memory. std::size_t memory_size() const; @@ -212,6 +215,27 @@ namespace mln template <typename P> inline + void + box<P>::merge(const box<P>& b) + { + mln_precondition(is_valid()); + if (! b.is_valid()) + { + // no-op + return; + } + + for (unsigned i = 0; i < P::dim; ++i) + { + if (b.pmin()[i] < pmin_[i]) + pmin_[i] = b.pmin()[i]; + if (b.pmax()[i] > pmax_[i]) + pmax_[i] = b.pmax()[i]; + } + } + + template <typename P> + inline P box<P>::pmin() const { diff --git a/milena/tests/core/site_set/Makefile.am b/milena/tests/core/site_set/Makefile.am index a67544a..c0be39b 100644 --- a/milena/tests/core/site_set/Makefile.am +++ b/milena/tests/core/site_set/Makefile.am @@ -20,6 +20,7 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ + box \ operators \ p_array \ p_complex \ @@ -34,6 +35,7 @@ check_PROGRAMS = \ p_vaccess \ p_vertices +box_SOURCES = box.cc operators_SOURCES = operators.cc p_array_SOURCES = p_array.cc p_complex_SOURCES = p_complex.cc diff --git a/milena/tests/core/other/box_runend_piter.cc b/milena/tests/core/site_set/box.cc similarity index 82% copy from milena/tests/core/other/box_runend_piter.cc copy to milena/tests/core/site_set/box.cc index fe7cb43..ad5c119 100644 --- a/milena/tests/core/other/box_runend_piter.cc +++ b/milena/tests/core/site_set/box.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,19 +23,20 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. +#include <mln/core/site_set/box.hh> #include <mln/core/alias/box2d.hh> -#include <mln/core/box_runend_piter.hh> +#include <mln/core/alias/point2d.hh> int main() { using namespace mln; - box2d b(3,3); - box_runend_piter<point2d> p(b); - unsigned i = 2; - for_all(p) - mln_assertion(p == point2d(i, 2)); + box2d + b1(point2d(0,0), point2d(3, 4)), + b2(point2d(-1,-1), point2d(4, 5)); - mln_assertion(p.run_length() == 3); + b1.merge(b2); + + mln_assertion(b1 == b2); } -- 1.5.6.5