* 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 | 21 +++++++++-
milena/mln/value/interval.hh | 87 +++++++++++++++++++++++++++++++++++++++-
4 files changed, 118 insertions(+), 3 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 647018e..551ff9d 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 d051c13..7fa217d 100644
--- a/milena/mln/value/int_u.hh
+++ b/milena/mln/value/int_u.hh
@@ -39,6 +39,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>
@@ -159,6 +160,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>;
@@ -181,7 +192,6 @@ namespace mln
std::istream& operator>>(std::istream& istr, int_u<n>& i);
-
// Conversions
/// \internal Conversion: int_u -> unsigned.
@@ -300,6 +310,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