https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Have site sets comparisons work again.
* mln/core/site_set/box.hh: Layout.
* mln/core/site_set/operators.hh: Have it work.
* mln/core/concept/box.hh (is_empty): New.
* mln/core/concept/site_set.hh: Layout.
* mln/geom/nsites.hh (nistes): Rename site set overload as...
* mln/set/card.hh (card): ...this...
...in this new file.
* mln/set/sym_diff.hh: Add fwd decl.
* mln/set/unique.hh: New.
* mln/set/all.hh: Update.
* tests/core/site_set/operators.cc: Revamp.
* tests/geom/nsites.cc: New.
* tests/geom/Makefile.am: Update.
* tests/set/uni.cc: Fix include.
* tests/set/sym_diff.cc: Likewise.
* tests/set/inter.cc: Likewise.
* tests/set/unique.cc: New.
* tests/set/card.cc: New.
* tests/set/Makefile.am: Update.
mln/core/concept/box.hh | 44 ++--
mln/core/concept/site_set.hh | 1
mln/core/site_set/box.hh | 3
mln/core/site_set/operators.hh | 368 ++++++++++++++++++++++++++++++++++-----
mln/geom/nsites.hh | 107 -----------
mln/set/all.hh | 5
mln/set/card.hh | 81 +++-----
mln/set/sym_diff.hh | 3
mln/set/unique.hh | 84 ++++++++
tests/core/site_set/operators.cc | 67 +++----
tests/geom/Makefile.am | 4
tests/geom/nsites.cc | 44 ++++
tests/set/Makefile.am | 6
tests/set/card.cc | 49 +++++
tests/set/inter.cc | 3
tests/set/sym_diff.cc | 6
tests/set/uni.cc | 2
tests/set/unique.cc | 50 +++++
18 files changed, 667 insertions(+), 260 deletions(-)
Index: mln/core/site_set/box.hh
--- mln/core/site_set/box.hh (revision 3071)
+++ mln/core/site_set/box.hh (working copy)
@@ -174,7 +174,6 @@
template <typename P>
std::ostream& operator<<(std::ostream& ostr, const box<P>& b);
- // Procedures
/// Return the minimum box including box \p a and box \p b
template <typename P>
@@ -182,6 +181,8 @@
box<P>
larger_than(const box<P> a, const box<P> b);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename P>
Index: mln/core/site_set/operators.hh
--- mln/core/site_set/operators.hh (revision 3071)
+++ mln/core/site_set/operators.hh (working copy)
@@ -36,7 +36,9 @@
/// \todo Re-vamp this file now!
+# include <algorithm>
# include <mln/core/concept/site_set.hh>
+# include <mln/set/card.hh>
# include <mln/util/yes.hh> // Temporary include.
@@ -45,10 +47,12 @@
namespace mln
{
+ template <typename E> struct Box;
template <typename Sl, typename Sr>
- Sl& operator+=(Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs);
+ Sl&
+ operator+=(Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs);
/// Equality test between site sets \p lhs and \p rhs.
@@ -59,7 +63,8 @@
/// \relates mln::Site_Set
///
template <typename Sl, typename Sr>
- bool operator==(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs);
+ bool
+ operator==(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs);
@@ -71,7 +76,8 @@
/// \relates mln::Site_Set
///
template <typename Sl, typename Sr>
- bool operator<=(const Site_Set<Sl>& lhs, const Site_Set<Sr>&
rhs);
+ bool
+ operator<=(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs);
@@ -84,7 +90,8 @@
/// \relates mln::Site_Set
///
template <typename Sl, typename Sr>
- bool operator<(const Site_Set<Sl>& lhs, const Site_Set<Sr>&
rhs);
+ bool
+ operator<(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs);
@@ -99,13 +106,314 @@
/// \relates mln::Site_Set
///
template <typename S>
- std::ostream& operator<<(std::ostream& ostr, const Site_Set<S>&
set);
+ std::ostream&
+ operator<<(std::ostream& ostr, const Site_Set<S>& set);
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ template <typename Sl, typename Sr>
+ inline
+ std::set< mln_site(Sl), util::ord<mln_site(Sl)> >
+ sym_diff_std_set(const Site_Set<Sl>& lhs, const Site_Set<Sr>&
rhs)
+ {
+ typedef mln_site(Sl) P;
+ mlc_converts_to(mln_psite(Sr), P)::check();
+ std::set< P, util::ord<P> > sl, sr, sd;
+ convert::from_to(lhs, sl);
+ convert::from_to(rhs, sr);
+ std::set_symmetric_difference(sl.begin(), sl.end(),
+ sr.begin(), sr.end(),
+ std::inserter(sd, sd.begin()),
+ util::ord<P>());
+ return sd;
+ }
+
+ template <typename S>
+ inline
+ std::set< mln_site(S), util::ord<mln_site(S)> >
+ to_std_set(const Site_Set<S>& s)
+ {
+ std::set< mln_site(S), util::ord<mln_site(S)> > std_s;
+ convert::from_to(s, std_s);
+ return std_s;
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ leq_std_set(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs)
+ {
+ typedef mln_site(Sl) P;
+ mlc_converts_to(mln_psite(Sr), P)::check();
+ std::set< P, util::ord<P> > sl, sr;
+ convert::from_to(lhs, sl);
+ convert::from_to(rhs, sr);
+ return std::includes(sr.begin(), sr.end(),
+ sl.begin(), sl.end(),
+ util::ord<P>());
+ }
+
+ } // end of namespace mln::internal
+
+
+ namespace impl
+ {
+
+ // Implementations for "operator ==" between site sets.
+
+ template <typename Bl, typename Br>
+ inline
+ bool
+ operator_equal_boxes(const Box<Bl>& lhs_, const Box<Br>& rhs_)
+ {
+ const Bl& lhs = exact(lhs_);
+ const Br& rhs = exact(rhs_);
+ if (lhs.is_empty() != rhs.is_empty())
+ return false;
+ if (lhs.is_empty() && rhs.is_empty())
+ return true;
+ return lhs.pmin() == rhs.pmin() && lhs.pmax() == rhs.pmax();
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_uniques(const Site_Set<Sl>& lhs,
+ const Site_Set<Sr>& rhs)
+ {
+ if (set::card(lhs) != set::card(rhs))
+ return false;
+ return mln::internal::sym_diff_std_set(lhs, rhs).empty();
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_unique_multiple(const Site_Set<Sl>& lhs,
+ const Site_Set<Sr>& rhs)
+ {
+ if (set::card(lhs) != set::card(rhs))
+ return false;
+ return mln::internal::to_std_set(lhs) == mln::internal::to_std_set(rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_multiples(const Site_Set<Sl>& lhs,
+ const Site_Set<Sr>& rhs)
+ {
+ // FIXME: Approximate code...
+ if (set::card(lhs) != set::card(rhs))
+ return false;
+ return mln::internal::to_std_set(lhs) == mln::internal::to_std_set(rhs);
+ }
+
+
+ // Implementations for "operator <" between site sets.
+
+ template <typename Bl, typename Br>
+ inline
+ bool
+ operator_less_boxes(const Box<Bl>& lhs_, const Box<Br>& rhs_)
+ {
+ const Bl& lhs = exact(lhs_);
+ const Br& rhs = exact(rhs_);
+ if (rhs.is_empty())
+ return false; // We cannot have "lhs < empty_set".
+ // From this line, rhs is not empty.
+ if (lhs.is_empty())
+ return true; // We have "empty set < a non empty set".
+ // From here, both lhs and rhs are not empty.
+ if (set::card(lhs) >= set::card(rhs))
+ return false;
+ return lhs.crop_wrt(rhs) == lhs;
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_uniques(const Site_Set<Sl>& lhs,
+ const Site_Set<Sr>& rhs)
+ {
+ if (set::card(lhs) >= set::card(rhs))
+ return false;
+ return mln::internal::leq_std_set(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_unique_multiple(const Site_Set<Sl>& lhs,
+ const Site_Set<Sr>& rhs)
+ {
+ if (set::card(lhs) >= set::card(rhs))
+ return false;
+ return mln::internal::leq_std_set(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_multiples(const Site_Set<Sl>& lhs,
+ const Site_Set<Sr>& rhs)
+ {
+ // FIXME: Approximate code...
+ if (set::card(lhs) >= set::card(rhs))
+ return false;
+ return mln::internal::leq_std_set(lhs, rhs);
+ }
+
+ } // end of namespace mln::impl
+
+
+
+
+ namespace internal
+ {
+
+ // Dispatch for "operator ==" between site sets.
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_dispatch(trait::site_set::arity::unique,
+ const Box<Sl>& lhs,
+ trait::site_set::arity::unique,
+ const Box<Sr>& rhs)
+ {
+ return impl::operator_equal_boxes(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_dispatch(trait::site_set::arity::unique,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::unique,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_equal_uniques(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_dispatch(trait::site_set::arity::unique,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::multiple,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_equal_unique_multiple(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_dispatch(trait::site_set::arity::multiple,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::unique,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_equal_unique_multiple(rhs, lhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_dispatch(trait::site_set::arity::multiple,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::multiple,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_equal_multiples(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_equal_dispatch(const Site_Set<Sl>& lhs, const
Site_Set<Sr>& rhs)
+ {
+ return operator_equal_dispatch(mln_trait_site_set_arity(Sl)(), exact(lhs),
+ mln_trait_site_set_arity(Sr)(), exact(rhs));
+ }
+
+
+ // Dispatch for "operator <" between site sets.
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_dispatch(trait::site_set::arity::unique,
+ const Box<Sl>& lhs,
+ trait::site_set::arity::unique,
+ const Box<Sr>& rhs)
+ {
+ return impl::operator_less_boxes(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_dispatch(trait::site_set::arity::unique,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::unique,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_less_uniques(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_dispatch(trait::site_set::arity::unique,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::multiple,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_less_unique_multiple(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_dispatch(trait::site_set::arity::multiple,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::unique,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_less_unique_multiple(rhs, lhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_dispatch(trait::site_set::arity::multiple,
+ const Site_Set<Sl>& lhs,
+ trait::site_set::arity::multiple,
+ const Site_Set<Sr>& rhs)
+ {
+ return impl::operator_less_multiples(lhs, rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ inline
+ bool
+ operator_less_dispatch(const Site_Set<Sl>& lhs, const
Site_Set<Sr>& rhs)
+ {
+ return operator_less_dispatch(mln_trait_site_set_arity(Sl)(), exact(lhs),
+ mln_trait_site_set_arity(Sr)(), exact(rhs));
+ }
+
+ } // end of namespace mln::internal
+
+
// Operator +=.
template <typename Sl, typename Sr>
@@ -129,60 +437,36 @@
template <typename Sl, typename Sr>
inline
bool
- operator==(const Site_Set<Sl>&, const Site_Set<Sr>&)
+ operator==(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs)
{
-// // FIXME: Same grid!
-// const Sl& lhs = exact(lhs_);
-// const Sr& rhs = exact(rhs_);
-
-// // exhaustive test:
-// mln_fwd_piter(Sl) pl(lhs);
-// mln_fwd_piter(Sr) pr(rhs);
-// for (pl.start(), pr.start();
-// pl.is_valid() && pr.is_valid();
-// pl.next(), pr.next())
-// if (pl != pr)
-// return false; // difference found
-
-// // both sets are equal only if both browsings are completed
-// // at the same time:
-// return ! pl.is_valid() && ! pr.is_valid();
- return util::yes(true);
+ mlc_equal(mln_site(Sl), mln_site(Sr))::check();
+ return internal::operator_equal_dispatch(lhs, rhs);
}
- // Operator <=.
+ // Operator <.
template <typename Sl, typename Sr>
inline
bool
- operator<=(const Site_Set<Sl>&, const Site_Set<Sr>&)
+ operator<(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs)
{
-// // FIXME: Same grid!
-// const Sl& lhs = exact(lhs_);
-// const Sr& rhs = exact(rhs_);
-
-// // exhaustive test:
-// mln_piter(Sl) pl(lhs);
-// for_all(pl)
-// if (! rhs.has(pl))
-// return false;
- return util::yes(true);
+ mlc_equal(mln_site(Sl), mln_site(Sr))::check();
+ return internal::operator_less_dispatch(lhs, rhs);
}
- // Operator <.
+ // Operator <=.
template <typename Sl, typename Sr>
inline
bool
- operator<(const Site_Set<Sl>&, const Site_Set<Sr>&)
+ operator<=(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs)
{
-// // FIXME: Same grid!
-// const Sl& lhs = exact(lhs_);
-// const Sr& rhs = exact(rhs_);
-// return lhs <= rhs && lhs != rhs;
- return util::yes(true);
+ mlc_equal(mln_site(Sl), mln_site(Sr))::check();
+ if (set::card(lhs) > set::card(rhs))
+ return false;
+ return lhs < rhs || lhs == rhs;
}
Index: mln/core/concept/box.hh
--- mln/core/concept/box.hh (revision 3071)
+++ mln/core/concept/box.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +29,9 @@
#ifndef MLN_CORE_CONCEPT_BOX_HH
# define MLN_CORE_CONCEPT_BOX_HH
-/*! \file mln/core/concept/box.hh
- *
- * \brief Definition of the concept of mln::Box.
- */
+/// \file mln/core/concept/box.hh
+///
+/// Definition of the concept of mln::Box.
# include <mln/core/concept/site_set.hh>
@@ -84,23 +84,15 @@
*/
unsigned nsites() const;
+ /// Test if this box is empty.
+ bool is_empty() const;
+
protected:
Box();
};
- /*! \brief Equality test between boxes \p lhs and \p rhs.
- *
- * \param[in] lhs A box.
- * \param[in] rhs Another box.
- *
- * \relates mln::Box
- */
- template <typename Bl, typename Br>
- bool operator==(const Box<Bl>& lhs, const Box<Br>& rhs);
-
-
/*! \brief Inclusion test between boxes \p lhs and \p rhs.
*
@@ -141,7 +133,10 @@
inline
unsigned Box<E>::len(unsigned i) const
{
- return 1 + exact(this)->pmax()[i] - exact(this)->pmin()[i];
+ return
+ exact(this)->is_valid()
+ ? 1 + exact(this)->pmax()[i] - exact(this)->pmin()[i]
+ : 0u;
}
template <typename E>
@@ -169,19 +164,18 @@
return count;
}
-
- // Operators.
-
- template <typename Bl, typename Br>
+ template <typename E>
inline
- bool operator==(const Box<Bl>& lhs_, const Box<Br>& rhs_)
+ bool
+ Box<E>::is_empty() const
{
- // FIXME: Same grid!
- const Bl& lhs = exact(lhs_);
- const Br& rhs = exact(rhs_);
- return lhs.pmin() == rhs.pmin() && lhs.pmax() == rhs.pmax();
+ // A non-valid box is empty.
+ return ! exact(this)->is_valid();
}
+
+ // Operators.
+
template <typename Bl, typename Br>
inline
bool operator<=(const Box<Bl>& lhs_, const Box<Br>& rhs_)
Index: mln/core/concept/site_set.hh
--- mln/core/concept/site_set.hh (revision 3071)
+++ mln/core/concept/site_set.hh (working copy)
@@ -128,6 +128,7 @@
# ifndef MLN_INCLUDE_ONLY
+
namespace convert
{
Index: mln/geom/nsites.hh
--- mln/geom/nsites.hh (revision 3071)
+++ mln/geom/nsites.hh (working copy)
@@ -29,10 +29,11 @@
# define MLN_GEOM_NSITES_HH
/// \file mln/geom/nsites.hh
+///
/// Compute the number of sites of an image or a site set.
-# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/image.hh>
+# include <mln/set/card.hh>
namespace mln
@@ -41,10 +42,6 @@
namespace geom
{
- /// Compute the number of sites of the site set \p input.
- template <typename S>
- unsigned nsites(const Site_Set<S>& s);
-
/// Compute the number of sites of the image \p input.
template <typename I>
unsigned nsites(const Image<I>& input);
@@ -52,102 +49,6 @@
# ifndef MLN_INCLUDE_ONLY
-
- // Implementations.
-
- namespace impl
- {
-
- // Generic version.
-
- namespace generic
- {
-
- template <typename S>
- unsigned nsites(const Site_Set<S>& s_)
- {
- trace::entering("geom::impl::generic::nsites");
- const S& s = exact(s_);
- mln_precondition(s.is_valid());
-
- unsigned n = 0;
- mln_piter(S) p(s);
- for_all(p)
- ++n;
-
- trace::exiting("geom::impl::generic::nsites");
- return n;
- }
-
- } // end of namespace mln::geom::impl::generic
-
-
- // A single specialization.
-
- template <typename S>
- inline
- unsigned nsites_method(const Site_Set<S>& s)
- {
- trace::entering("geom::impl::nsites_method");
- unsigned n = exact(s).nsites();
- trace::exiting("geom::impl::nsites_method");
- return n;
- }
-
- } // end of namespace mln::geom::impl
-
-
-
- // Dispatch.
-
- namespace internal
- {
-
- template <typename S>
- inline
- unsigned nsites_dispatch(mln::trait::site_set::nsites::any,
- const Site_Set<S>& s)
- {
- return impl::generic::nsites(s);
- }
-
- template <typename S>
- inline
- unsigned nsites_dispatch(mln::trait::site_set::nsites::known,
- const Site_Set<S>& s)
- {
- return impl::nsites_method(s);
- }
-
- // Dispatch facade.
-
- template <typename S>
- inline
- unsigned nsites_dispatch(const Site_Set<S>& s)
- {
- return nsites_dispatch(mln_trait_site_set_nsites(S)(),
- s);
- }
-
- } // end of namespace mln::geom::internal
-
-
-
- // Facades.
-
- template <typename S>
- inline
- unsigned nsites(const Site_Set<S>& s)
- {
- trace::entering("geom::nsites");
- mln_precondition(exact(s).is_valid());
-
- unsigned n = internal::nsites_dispatch(s);
-
- trace::exiting("geom::nsites");
- return n;
- }
-
template <typename I>
inline
unsigned nsites(const Image<I>& input_)
@@ -158,8 +59,8 @@
mln_precondition(input.has_data());
mln_precondition(input.domain().is_valid());
- // Relies on the nsites routines on a site set.
- unsigned n = internal::nsites_dispatch(input.domain());
+ // Relies on the card routine on a site set.
+ unsigned n = mln::set::internal::card_dispatch(input.domain());
trace::exiting("geom::nsites");
return n;
Index: mln/set/unique.hh
--- mln/set/unique.hh (revision 0)
+++ mln/set/unique.hh (revision 0)
@@ -0,0 +1,84 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_SET_UNIQUE_HH
+# define MLN_SET_UNIQUE_HH
+
+/// \file mln/set/unique.hh
+///
+/// Give the unique set.
+
+# include <algorithm>
+# include <iterator>
+
+# include <mln/core/site_set/p_set.hh>
+# include <mln/convert/from_to.hh>
+# include <mln/util/ord.hh>
+
+
+namespace mln
+{
+
+ namespace set
+ {
+
+ /// Give the unique set of \p s.
+ ///
+ /// \relates mln::Site_Set
+ ///
+ template <typename S>
+ p_set<mln_site(S)>
+ unique(const Site_Set<S>& s);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ inline
+ p_set<mln_site(S)>
+ unique(const Site_Set<S>& s)
+ {
+ trace::entering("set::unique");
+
+ typedef mln_site(S) P;
+ std::set< P, util::ord<P> > s_;
+ convert::from_to(s, s_);
+ p_set<P> su;
+ convert::from_to(s_, su);
+
+ trace::exiting("set::unique");
+ return su;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::set
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SET_UNIQUE_HH
Index: mln/set/all.hh
--- mln/set/all.hh (revision 3071)
+++ mln/set/all.hh (working copy)
@@ -32,7 +32,8 @@
/// \file mln/set/all.hh
///
/// File that includes all set-related routines.
-
+///
+/// \todo Move geom::sites here (set::nsites).
namespace mln
{
@@ -43,6 +44,7 @@
}
+# include <mln/set/card.hh>
# include <mln/set/compute.hh>
# include <mln/set/diff.hh>
# include <mln/set/inter.hh>
@@ -50,6 +52,7 @@
# include <mln/set/has.hh>
# include <mln/set/sym_diff.hh>
# include <mln/set/uni.hh>
+# include <mln/set/unique.hh>
#endif // ! MLN_SET_ALL_HH
Index: mln/set/card.hh
--- mln/set/card.hh (revision 3064)
+++ mln/set/card.hh (working copy)
@@ -25,29 +25,25 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_GEOM_NSITES_HH
-# define MLN_GEOM_NSITES_HH
+#ifndef MLN_SET_CARD_HH
+# define MLN_SET_CARD_HH
-/// \file mln/geom/nsites.hh
-/// Compute the number of sites of an image or a site set.
+/// \file mln/set/card.hh
+///
+/// Compute the cardinality of a site set.
# include <mln/core/concept/site_set.hh>
-# include <mln/core/concept/image.hh>
namespace mln
{
- namespace geom
+ namespace set
{
- /// Compute the number of sites of the site set \p input.
+ /// Compute the cardinality of the site set \p s.
template <typename S>
- unsigned nsites(const Site_Set<S>& s);
-
- /// Compute the number of sites of the image \p input.
- template <typename I>
- unsigned nsites(const Image<I>& input);
+ unsigned card(const Site_Set<S>& s);
# ifndef MLN_INCLUDE_ONLY
@@ -64,9 +60,9 @@
{
template <typename S>
- unsigned nsites(const Site_Set<S>& s_)
+ unsigned card(const Site_Set<S>& s_)
{
- trace::entering("geom::impl::generic::nsites");
+ trace::entering("set::impl::generic::card");
const S& s = exact(s_);
mln_precondition(s.is_valid());
@@ -75,26 +71,26 @@
for_all(p)
++n;
- trace::exiting("geom::impl::generic::nsites");
+ trace::exiting("set::impl::generic::card");
return n;
}
- } // end of namespace mln::geom::impl::generic
+ } // end of namespace mln::set::impl::generic
// A single specialization.
template <typename S>
inline
- unsigned nsites_method(const Site_Set<S>& s)
+ unsigned card_from_method(const Site_Set<S>& s)
{
- trace::entering("geom::impl::nsites_method");
+ trace::entering("set::impl::card_from_method");
unsigned n = exact(s).nsites();
- trace::exiting("geom::impl::nsites_method");
+ trace::exiting("set::impl::card_from_method");
return n;
}
- } // end of namespace mln::geom::impl
+ } // end of namespace mln::set::impl
@@ -105,71 +101,54 @@
template <typename S>
inline
- unsigned nsites_dispatch(mln::trait::site_set::nsites::any,
+ unsigned card_dispatch(mln::trait::site_set::nsites::any,
const Site_Set<S>& s)
{
- return impl::generic::nsites(s);
+ return impl::generic::card(s);
}
template <typename S>
inline
- unsigned nsites_dispatch(mln::trait::site_set::nsites::known,
+ unsigned card_dispatch(mln::trait::site_set::nsites::known,
const Site_Set<S>& s)
{
- return impl::nsites_method(s);
+ return impl::card_from_method(s);
}
// Dispatch facade.
template <typename S>
inline
- unsigned nsites_dispatch(const Site_Set<S>& s)
+ unsigned card_dispatch(const Site_Set<S>& s)
{
- return nsites_dispatch(mln_trait_site_set_nsites(S)(),
+ return card_dispatch(mln_trait_site_set_nsites(S)(),
s);
}
- } // end of namespace mln::geom::internal
+ } // end of namespace mln::set::internal
- // Facades.
+ // Facade.
template <typename S>
inline
- unsigned nsites(const Site_Set<S>& s)
+ unsigned card(const Site_Set<S>& s)
{
- trace::entering("geom::nsites");
+ trace::entering("set::card");
mln_precondition(exact(s).is_valid());
- unsigned n = internal::nsites_dispatch(s);
-
- trace::exiting("geom::nsites");
- return n;
- }
-
- template <typename I>
- inline
- unsigned nsites(const Image<I>& input_)
- {
- trace::entering("geom::nsites");
- const I& input = exact(input_);
-
- mln_precondition(input.has_data());
- mln_precondition(input.domain().is_valid());
-
- // Relies on the nsites routines on a site set.
- unsigned n = internal::nsites_dispatch(input.domain());
+ unsigned n = internal::card_dispatch(s);
- trace::exiting("geom::nsites");
+ trace::exiting("set::card");
return n;
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::geom
+ } // end of namespace mln::set
} // end of namespace mln
-#endif // ! MLN_GEOM_NSITES_HH
+#endif // ! MLN_SET_CARD_HH
Property changes on: mln/set/card.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/set/sym_diff.hh
--- mln/set/sym_diff.hh (revision 3071)
+++ mln/set/sym_diff.hh (working copy)
@@ -45,6 +45,9 @@
namespace mln
{
+ template <typename P> class p_set;
+
+
namespace set
{
Index: tests/core/site_set/operators.cc
--- tests/core/site_set/operators.cc (revision 3071)
+++ tests/core/site_set/operators.cc (working copy)
@@ -31,42 +31,49 @@
/// Tests of operators on mln::Site_Set.
#include <mln/core/site_set/p_set.hh>
+#include <mln/core/routine/ops.hh>
#include <mln/core/alias/point2d.hh>
+#include <mln/core/alias/box2d.hh>
int main()
{
using namespace mln;
- p_set<point2d> pst1, pst2, pst3, pst4;
- pst1.insert(point2d( 2, 7));
- pst1.insert(point2d( 2, 1));
- pst1.insert(point2d(-4, 0));
- pst1.insert(point2d( 0, 0));
- pst1.insert(point2d( 1, 1));
- pst1.insert(point2d( 6, 5));
- pst2.insert(point2d( 2, 7));
- pst2.insert(point2d(-2, 1));
- pst2.insert(point2d(-4, 0));
- pst2.insert(point2d( 1,-1));
- pst2.insert(point2d( 6, 5));
- pst3.insert(point2d( 2, 7));
- pst3.insert(point2d( 2, 1));
- pst3.insert(point2d(-4, 0));
- pst3.insert(point2d( 0, 0));
- pst3.insert(point2d( 1, 1));
- pst3.insert(point2d( 6, 5));
- pst3.insert(point2d(-2, 1));
- pst3.insert(point2d( 1,-1));
-
- mln_assertion(pst1 <= pst3);
- mln_assertion(pst2 <= pst3);
- mln_assertion(pst3 <= pst3);
- mln_assertion(pst4 <= pst1);
- mln_assertion(pst4 <= pst2);
- mln_assertion(pst4 <= pst3);
- mln_assertion(pst4 <= pst4);
+ point2d a(0,0), b(1,1), c(2,2);
-// mln_assertion(! (pst3 <= pst1));
-// mln_assertion(! (pst3 <= pst2));
+ {
+ p_set<point2d> s1, s2;
+ s1.insert(a);
+ s2.insert(b);
+ mln_assertion(s1 != s2);
+ mln_assertion(! (s1 == s2));
+ mln_assertion(! (s1 < s2));
+ mln_assertion(! (s1 <= s2));
+ mln_assertion(! (s1 > s2));
+ mln_assertion(! (s1 >= s2));
+ }
+
+ {
+ p_set<point2d> s1, s2;
+ s1.insert(a);
+ s2.insert(b);
+ s2.insert(a);
+ mln_assertion(s1 != s2);
+ mln_assertion(s1 < s2);
+ mln_assertion(s1 <= s2);
+ mln_assertion(s2 > s1);
+ mln_assertion(! (s1 == s2));
+ mln_assertion(! (s1 > s2));
+ mln_assertion(! (s1 >= s2));
+ }
+
+ {
+ box2d
+ b1 = make::box2d(0,0, 1,1),
+ b2 = make::box2d(0,0, 1,2);
+ mln_assertion(b1 < b2);
+ mln_assertion(! (b1 < b1));
+ mln_assertion(! (b2 < b1));
+ }
}
Index: tests/geom/nsites.cc
--- tests/geom/nsites.cc (revision 0)
+++ tests/geom/nsites.cc (revision 0)
@@ -0,0 +1,44 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file tests/geom/nsites.cc
+///
+/// Tests on mln::geom::nsites.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/geom/nsites.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ // trace::quiet = false;
+ image2d<int> ima(make::box2d(-1,-4, 2,6));
+ mln_assertion(geom::nsites(ima) == ((2 - (-1) + 1) * (6 - (-4) + 1)));
+}
Index: tests/geom/Makefile.am
--- tests/geom/Makefile.am (revision 3071)
+++ tests/geom/Makefile.am (working copy)
@@ -15,12 +15,14 @@
ncols \
ninds \
nrows \
+nsites \
nslis \
pmin_pmax \
resize \
seed2tiling \
seed2tiling_roundness
+
bbox_SOURCES = bbox.cc
max_col_SOURCES = max_col.cc
max_ind_SOURCES = max_ind.cc
@@ -33,10 +35,12 @@
ncols_SOURCES = ncols.cc
ninds_SOURCES = ninds.cc
nrows_SOURCES = nrows.cc
+nsites_SOURCES = nsites.cc
nslis_SOURCES = nslis.cc
pmin_pmax_SOURCES = pmin_pmax.cc
resize_SOURCES = resize.cc
seed2tiling_SOURCES = seed2tiling.cc
seed2tiling_roundness_SOURCES = seed2tiling_roundness.cc
+
TESTS = $(check_PROGRAMS)
Index: tests/set/uni.cc
--- tests/set/uni.cc (revision 3071)
+++ tests/set/uni.cc (working copy)
@@ -31,7 +31,7 @@
/// Tests on mln::set::uni.
#include <mln/set/uni.hh>
-#include <mln/core/alias/dpoint2d.hh>
+#include <mln/core/alias/point2d.hh>
int main()
Index: tests/set/sym_diff.cc
--- tests/set/sym_diff.cc (revision 3071)
+++ tests/set/sym_diff.cc (working copy)
@@ -31,7 +31,7 @@
/// Tests on mln::set::sym_diff.
#include <mln/set/sym_diff.hh>
-#include <mln/core/alias/dpoint2d.hh>
+#include <mln/core/alias/point2d.hh>
int main()
@@ -56,9 +56,9 @@
mln_assertion(pst3.has(point2d( 2, 1)));
mln_assertion(pst3.has(point2d( 0, 0)));
mln_assertion(pst3.has(point2d( 1, 1)));
- mln_assertion(!pst3.has(point2d( 2, 7)));
mln_assertion(pst3.has(point2d(-2, 1)));
- mln_assertion(!pst3.has(point2d(-4, 0)));
mln_assertion(pst3.has(point2d( 1,-1)));
+ mln_assertion(! pst3.has(point2d( 2, 7)));
+ mln_assertion(! pst3.has(point2d(-4, 0)));
mln_assertion(!pst3.has(point2d( 6, 5)));
}
Index: tests/set/inter.cc
--- tests/set/inter.cc (revision 3071)
+++ tests/set/inter.cc (working copy)
@@ -31,8 +31,7 @@
/// Tests on mln::set::inter.
#include <mln/set/inter.hh>
-#include <mln/core/alias/dpoint2d.hh>
-#include <mln/core/alias/window2d.hh>
+#include <mln/core/alias/point2d.hh>
int main()
Index: tests/set/Makefile.am
--- tests/set/Makefile.am (revision 3071)
+++ tests/set/Makefile.am (working copy)
@@ -3,16 +3,20 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
+ card \
compute \
diff \
inter \
sym_diff \
- uni
+ uni \
+ unique
+card_SOURCES = card.cc
compute_SOURCES = compute.cc
diff_SOURCES = diff.cc
inter_SOURCES = inter.cc
sym_diff_SOURCES = sym_diff.cc
uni_SOURCES = uni.cc
+unique_SOURCES = unique.cc
TESTS = $(check_PROGRAMS)
Index: tests/set/unique.cc
--- tests/set/unique.cc (revision 0)
+++ tests/set/unique.cc (revision 0)
@@ -0,0 +1,50 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file tests/set/unique.cc
+///
+/// Tests on mln::set::unique.
+
+#include <mln/set/unique.hh>
+#include <mln/core/site_set/p_array.hh>
+#include <mln/core/alias/point2d.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ p_array<point2d> a;
+ a.insert(point2d(1, 1));
+ a.insert(point2d(0, 0));
+ a.insert(point2d(0, 0));
+ a.insert(point2d(1, 1));
+ a.insert(point2d(1, 1));
+ mln_assertion(a.nsites() == 5);
+ mln_assertion(set::unique(a).nsites() == 2);
+}
Index: tests/set/card.cc
--- tests/set/card.cc (revision 0)
+++ tests/set/card.cc (revision 0)
@@ -0,0 +1,49 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file tests/set/card.cc
+///
+/// Tests on mln::set::card.
+
+#include <mln/core/site_set/p_array.hh>
+#include <mln/core/alias/point2d.hh>
+#include <mln/set/card.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ p_array<point2d> a;
+ a.insert(point2d(1, 1));
+ a.insert(point2d(0, 0));
+ a.insert(point2d(0, 0));
+ a.insert(point2d(1, 1));
+ a.insert(point2d(1, 1));
+ mln_assertion(set::card(a) == a.nsites());
+}