https://svn.lrde.epita.fr/svn/oln/trunk/milena
This is probably *the* bug I have been hunting for *months*! I think it's
also the same bug Aroune faced during his work on the segmentation of
statues.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a missing operator< on (line-)graph psites, so that sorting
them works, as well as storing them in a sorted container (like
std::set).
* mln/core/graph_psite.hh
(operator==(const graph_psite<P>&, const graph_psite<P>&)):
Ensure psites have the same p_graph.
(operator< (const graph_psite<P>&, const graph_psite<P>&)):
New operator.
(graph_psite<P>::graph_psite): Pass RHS to the copy ctor
of the super class.
* mln/core/line_graph_psite.hh
(operator==(const line_graph_psite<P>&, const
line_graph_psite<P>&)):
Ensure psites have the same p_line_graph.
(operator< (const line_graph_psite<P>&, const
line_graph_psite<P>&)):
New operator.
(line_graph_psite<P>::line_graph_psite): Pass RHS to the copy ctor
of the super class.
graph_psite.hh | 40 ++++++++++++++++++++++++++++++++++++----
line_graph_psite.hh | 44 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 76 insertions(+), 8 deletions(-)
Index: mln/core/graph_psite.hh
--- mln/core/graph_psite.hh (revision 2018)
+++ mln/core/graph_psite.hh (working copy)
@@ -87,13 +87,31 @@
util::vertex_id id_;
};
- /// Compare two mln::graph_psite<P> instances.
- /* FIXME: Shouldn't this comparison be part of a much general
+
+ /// Comparison of two mln::graph_psite<P> instances.
+ /// \{
+ /* FIXME: Shouldn't those comparisons be part of a much general
mechanism? */
+
+ /// \brief Is \a lhs equal to \a rhs?
+ ///
+ /// \pre Arguments \a lhs and \a rhs must belong to the same
+ /// mln::p_graph.
template <typename P>
bool
operator==(const graph_psite<P>& lhs, const graph_psite<P>& rhs);
+ /// \brief Is \a lhs ``less'' than \a rhs?
+ ///
+ /// This comparison is required by algorithms sorting psites.
+ ///
+ /// \pre Arguments \a lhs and \a rhs must belong to the same
+ /// mln::p_graph.
+ template <typename P>
+ bool
+ operator< (const graph_psite<P>& lhs, const graph_psite<P>&
rhs);
+ /// \}
+
# ifndef MLN_INCLUDE_ONLY
@@ -119,7 +137,7 @@
template<typename P>
inline
graph_psite<P>::graph_psite(const graph_psite<P>& rhs)
- : super_(),
+ : super_(rhs),
pg_(rhs.pg_),
id_(rhs.id_)
{
@@ -187,11 +205,25 @@
return id_;
}
+
+ /*--------------.
+ | Comparisons. |
+ `--------------*/
+
template <typename P>
bool
operator==(const graph_psite<P>& lhs, const graph_psite<P>& rhs)
{
- return &lhs.pg() == &rhs.pg() && lhs.id() == rhs.id();
+ mln_assertion(&lhs.pg() == &rhs.pg());
+ return lhs.id() == rhs.id();
+ }
+
+ template <typename P>
+ bool
+ operator< (const graph_psite<P>& lhs, const graph_psite<P>&
rhs)
+ {
+ mln_assertion(&lhs.pg() == &rhs.pg());
+ return lhs.id() < rhs.id();
}
Index: mln/core/line_graph_psite.hh
--- mln/core/line_graph_psite.hh (revision 2018)
+++ mln/core/line_graph_psite.hh (working copy)
@@ -111,13 +111,32 @@
point p_;
};
- /// Compare two mln::line_graph_psite<P> instances.
- /* FIXME: Shouldn't this comparison be part of a much general
+
+ /// Comparison of two mln::line_graph_psite<P> instances.
+ /// \{
+ /* FIXME: Shouldn't those comparisons be part of a much general
mechanism? */
+
+ /// \brief Is \a lhs equal to \a rhs?
+ ///
+ /// \pre Arguments \a lhs and \a rhs must belong to the same
+ /// mln::p_line_graph.
template <typename P>
bool
operator==(const line_graph_psite<P>& lhs, const
line_graph_psite<P>& rhs);
+ /// \brief Is \a lhs ``less'' than \a rhs?
+ ///
+ /// This comparison is required by algorithms sorting psites.
+ ///
+ /// \pre Arguments \a lhs and \a rhs must belong to the same
+ /// mln::p_line_graph.
+ template <typename P>
+ bool
+ operator< (const line_graph_psite<P>& lhs, const
line_graph_psite<P>& rhs);
+ /// \}
+
+
/* FIXME: This hand-made delegation is painful. We should rely on
the general mechanism provided by Point_Site. But then again, we
need to refine/adjust the interface of Point_Site w.r.t. the
@@ -160,7 +179,7 @@
template<typename P>
inline
line_graph_psite<P>::line_graph_psite(const line_graph_psite<P>& rhs)
- : super_(),
+ : super_(rhs),
plg_(rhs.plg_),
id_(rhs.id_),
p_()
@@ -268,13 +287,30 @@
}
+ /*--------------.
+ | Comparisons. |
+ `--------------*/
+
template <typename P>
bool
operator==(const line_graph_psite<P>& lhs, const
line_graph_psite<P>& rhs)
{
- return &lhs.plg() == &rhs.plg() && lhs.id() == rhs.id();
+ mln_assertion(&lhs.plg() == &rhs.plg());
+ return lhs.id() == rhs.id();
}
+ template <typename P>
+ bool
+ operator< (const line_graph_psite<P>& lhs, const
line_graph_psite<P>& rhs)
+ {
+ mln_assertion(&lhs.plg() == &rhs.plg());
+ return lhs.id() < rhs.id();
+ }
+
+
+ /*------------------.
+ | Pretty-printing. |
+ `------------------*/
template <typename P>
inline