* mln/labeling/compute.hh: Fix include.
* mln/value/int_u.hh: Add iota definition.
* mln/value/interval.hh: Add span overloads and self_open()
method.
---
milena/ChangeLog | 11 +++++
milena/mln/labeling/compute.hh | 2 +-
milena/mln/value/int_u.hh | 25 ++++++++++-
milena/mln/value/interval.hh | 87 +++++++++++++++++++++++++++++++++++++++-
4 files changed, 121 insertions(+), 4 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index aa215c4..4b7a84a 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,16 @@
2012-10-18 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Some fixes.
+
+ * mln/labeling/compute.hh: Fix include.
+
+ * mln/value/int_u.hh: Add iota definition.
+
+ * mln/value/interval.hh: Add span overloads and self_open()
+ method.
+
+2012-10-18 Guillaume Lazzara <z(a)lrde.epita.fr>
+
New span accumulator.
* mln/accu/math/span.hh: New.
diff --git a/milena/mln/labeling/compute.hh b/milena/mln/labeling/compute.hh
index 4ad48b5..1743181 100644
--- a/milena/mln/labeling/compute.hh
+++ b/milena/mln/labeling/compute.hh
@@ -51,7 +51,7 @@
# include <mln/util/array.hh>
# include <mln/convert/from_to.hh>
# include <mln/geom/ncols.hh>
-# include <mln/value/next.hh>
+# include <mln/value/succ.hh>
namespace mln
diff --git a/milena/mln/value/int_u.hh b/milena/mln/value/int_u.hh
index f3786f9..3b22918 100644
--- a/milena/mln/value/int_u.hh
+++ b/milena/mln/value/int_u.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2010, 2012 EPITA Research and
+// Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -41,6 +41,7 @@
# include <mln/value/concept/integer.hh>
# include <mln/trait/value_.hh>
# include <mln/debug/format.hh>
+# include <mln/value/iota.hh>
# include <mln/value/internal/make_generic_name.hh>
@@ -195,6 +196,16 @@ namespace mln
};
+ // Iota
+
+ template <unsigned n>
+ struct iota<int_u<n> >
+ {
+ static int_u<n> value();
+ };
+
+
+
// Safety.
template <> struct int_u<0>;
template <> struct int_u<1>;
@@ -218,6 +229,7 @@ namespace mln
} // end of namespace mln::value
+
# ifndef MLN_INCLUDE_ONLY
namespace convert
@@ -352,6 +364,15 @@ namespace mln
return this->v_ + 1;
}
+ // Iota
+
+ template <unsigned n>
+ int_u<n>
+ iota<int_u<n> >::value()
+ {
+ return 1;
+ }
+
template <unsigned n>
inline
std::ostream& operator<<(std::ostream& ostr, const int_u<n>&
i)
diff --git a/milena/mln/value/interval.hh b/milena/mln/value/interval.hh
index 13c7947..d3cbbdd 100644
--- a/milena/mln/value/interval.hh
+++ b/milena/mln/value/interval.hh
@@ -34,6 +34,8 @@
# include <iostream>
# include <mln/value/inc.hh>
# include <mln/value/concept/interval.hh>
+# include <mln/util/level.hh>
+
namespace mln
{
@@ -50,6 +52,7 @@ namespace mln
typedef T equiv;
interval();
+ interval(T single);
interval(T first, T last);
interval& operator=(const interval& rhs);
@@ -77,6 +80,11 @@ namespace mln
/// The last value included in this interval.
const T& last() const;
+ /// Open this interval and exclude first and last values from
+ /// it. The interval is then defined on [first + iota, last -
+ /// iota].
+ void self_open();
+
private:
T first_;
T last_;
@@ -164,6 +172,12 @@ namespace mln
interval<T>
span(const interval<T>& r1, const interval<T>& r2);
+ /// \brief Compute the span of \p r1, \p r2, \p r3 and \p r4.
+ template <typename T>
+ interval<T>
+ span(const interval<T>& r1, const interval<T>& r2,
+ const interval<T>& r3, const interval<T>& r4);
+
// op<<
template <typename T>
@@ -207,6 +221,16 @@ namespace mln
}
template <typename T>
+ interval<T>::interval(T single)
+ {
+ first_ = single;
+ last_ = single;
+
+ nvalues_ = 1;
+ }
+
+
+ template <typename T>
interval<T>::interval(T first, T last)
{
mln_precondition(last >= first);
@@ -285,6 +309,18 @@ namespace mln
return last_;
}
+ template <typename T>
+ void
+ interval<T>::self_open()
+ {
+ mln_precondition(! is_degenerated());
+ mln_precondition(nvalues_ > 2);
+
+ first += iota<T>::value();
+ last_ -= iota<T>::value();
+ nvalues_ -= 2;
+ }
+
// comparison
@@ -302,8 +338,49 @@ namespace mln
return ! (lhs == rhs);
}
+ // thresholding
- // set ops
+ template <typename T, typename U>
+ inline
+ bool
+ operator<=(const interval<T>& i, const util::level_t<U>& v)
+ {
+ return i.first() <= v.value;
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator>(const interval<T>& i, const util::level_t<U>& v)
+ {
+ return ! (i <= v);
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator>=(const interval<T>& i, const util::level_t<U>& v)
+ {
+ return v.value <= i.last();
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator<(const interval<T>& i, const util::level_t<U>& v)
+ {
+ return ! (i >= v);
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator==(const interval<T>& i, const util::level_t<U>& v)
+ {
+ return i >= v && i <= v;
+ }
+
+ // set ops
template <typename T>
bool
@@ -357,6 +434,14 @@ namespace mln
std::max(r1.last(), r2.last()));
}
+ template <typename T>
+ interval<T>
+ span(const interval<T>& r1, const interval<T>& r2,
+ const interval<T>& r3, const interval<T>& r4)
+ {
+ return span(span(r1, r2), span(r3, r4));
+ }
+
// op<<
--
1.7.2.5