
* mln/core/site_set/box.hh: add crop_wrt(), nrows() and nco --- milena/ChangeLog | 6 +++++ milena/mln/core/site_set/box.hh | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 0 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index cd2632d..069fe9b 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,9 @@ +2008-10-29 Guillaume Lazzara <z@lrde.epita.fr> + + Add new methods to box. + + * mln/core/site_set/box.hh: add crop_wrt(), nrows() and ncols. + 2008-10-28 Guillaume Lazzara <z@lrde.epita.fr> Update the window and the neighborhood on graph vertices. diff --git a/milena/mln/core/site_set/box.hh b/milena/mln/core/site_set/box.hh index 5a47fa1..019d6ad 100644 --- a/milena/mln/core/site_set/box.hh +++ b/milena/mln/core/site_set/box.hh @@ -147,10 +147,19 @@ namespace mln /// FIXME: Do we want a routine as well like geom::bbox()? P center() const; + /// Return the column count of this box. + unsigned ncols() const; + + /// Return the row count of this box. + unsigned nrows() const; + /// Test that the box owns valid data, i.e., is initialized and /// with pmin being 'less-than' pmax. bool is_valid() const; + /// Crop this bbox in order to fit in the reference box \p b. + void crop_wrt(const box<P>& b); + /// Return the size of this site set in memory. std::size_t memory_size() const; @@ -194,6 +203,22 @@ namespace mln template <typename P> inline + void + box<P>::crop_wrt(const box<P>& ref) + { + if (pmin_.col() < ref.pmin().col()) + pmin_.col() = ref.pmin().col(); + if (pmin_.row() < ref.pmin().row()) + pmin_.row() = ref.pmin().row(); + + if (pmax_.col() > ref.pmax().col()) + pmax_.col() = ref.pmax().col(); + if (pmax_.row() > ref.pmax().row()) + pmax_.row() = ref.pmax().row(); + } + + template <typename P> + inline P box<P>::pmin() const { @@ -359,6 +384,24 @@ namespace mln template <typename P> inline + unsigned + box<P>::ncols() const + { + mln_precondition(is_valid()); + return pmax().col() - pmin().col(); + } + + template <typename P> + inline + unsigned + box<P>::nrows() const + { + mln_precondition(is_valid()); + return pmax().row() - pmin().row(); + } + + template <typename P> + inline std::size_t box<P>::memory_size() const { -- 1.5.6.5