
--- scribo/ChangeLog | 4 + ...from_double_link.hh => from_double_link_any.hh} | 60 +++++++++++--------- 2 files changed, 37 insertions(+), 27 deletions(-) copy scribo/scribo/primitive/group/{from_double_link.hh => from_double_link_any.hh} (67%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 58ff670..a7f2dc7 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,9 @@ 2010-11-16 Guillaume Lazzara <z@lrde.epita.fr> + * scribo/primitive/group/from_double_link_any.hh: New. + +2010-11-16 Guillaume Lazzara <z@lrde.epita.fr> + * scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh: New. diff --git a/scribo/scribo/primitive/group/from_double_link.hh b/scribo/scribo/primitive/group/from_double_link_any.hh similarity index 67% copy from scribo/scribo/primitive/group/from_double_link.hh copy to scribo/scribo/primitive/group/from_double_link_any.hh index 3af395d..b3bd82a 100644 --- a/scribo/scribo/primitive/group/from_double_link.hh +++ b/scribo/scribo/primitive/group/from_double_link_any.hh @@ -1,5 +1,4 @@ -// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -24,8 +23,8 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_PRIMITIVE_GROUP_FROM_DOUBLE_LINK_HH -# define SCRIBO_PRIMITIVE_GROUP_FROM_DOUBLE_LINK_HH +#ifndef SCRIBO_PRIMITIVE_GROUP_FROM_DOUBLE_LINK_ANY_HH +# define SCRIBO_PRIMITIVE_GROUP_FROM_DOUBLE_LINK_ANY_HH /// \file @@ -46,7 +45,6 @@ # include <scribo/core/object_groups.hh> # include <scribo/core/component_set.hh> # include <scribo/primitive/internal/find_root.hh> -# include <scribo/primitive/internal/is_link_valid.hh> namespace scribo @@ -59,10 +57,8 @@ namespace scribo { /*! Group components from left and right links information and - validate These links. A link must exist in both ways to be - validated. + validate These links. - \param[in] components A component set. \param[in] left_link The left neighbor of each line of text. \param[in] right_link The right neighbor of each line of text. @@ -70,8 +66,8 @@ namespace scribo */ template <typename L> object_groups<L> - from_double_link(const object_links<L>& left_link, - const object_links<L>& right_link); + from_double_link_any(const object_links<L>& left_link, + const object_links<L>& right_link); @@ -81,34 +77,44 @@ namespace scribo template <typename L> inline object_groups<L> - from_double_link(const object_links<L>& left_link, - const object_links<L>& right_link) + from_double_link_any(const object_links<L>& left_link, + const object_links<L>& right_link) { - trace::entering("scribo::primitive::group::from_double_link"); - - mln_precondition(left_link.nelements() == right_link.nelements()); - + trace::entering("scribo::primitive::group::from_double_link_any"); object_groups<L> parent(left_link); parent.init(); + for_all_comps(i, left_link.components()) { - mln::util::couple<bool, unsigned> - nbh = internal::is_link_valid(left_link, right_link, i); - if (nbh.first()) + unsigned + pi = internal::find_root(parent, i), + pli = internal::find_root(parent, left_link(i)); + + if (pi != pli) + { + if (pli < pi) + parent(pli) = pi; + else + parent(pi) = pli; + } + + pi = internal::find_root(parent, i); + unsigned pri = internal::find_root(parent, right_link(i)); + + if (pi != pri) { - unsigned par = internal::find_root(parent, nbh.second()); - if (par < i) - parent(par) = i; + if (pri < pi) + parent(pri) = pi; else - parent(i) = par; + parent(pi) = pri; } } - for (unsigned i = parent.nelements() - 1; i < parent.nelements(); --i) - parent(i) = parent(parent(i)); + for_all_groups(g, parent) + internal::find_root(parent, g); - trace::exiting("scribo::primitive::group::from_double_link"); + trace::exiting("scribo::primitive::group::from_double_link_any"); return parent; } @@ -122,4 +128,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_PRIMITIVE_GROUP_FROM_DOUBLE_LINK_HH +#endif // ! SCRIBO_PRIMITIVE_GROUP_FROM_DOUBLE_LINK_ANY_HH -- 1.5.6.5