|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60247 - in sandbox/itl: boost/itl libs/itl/test libs/itl/test/fastest_itl_interval_ libs/itl/test/test_casual_ libs/itl/test/test_itl_interval_
From: afojgo_at_[hidden]
Date: 2010-03-06 11:51:09
Author: jofaber
Date: 2010-03-06 11:51:08 EST (Sat, 06 Mar 2010)
New Revision: 60247
URL: http://svn.boost.org/trac/boost/changeset/60247
Log:
Added itl::inner_complement and itl::distance for itl::interval and tests.
Text files modified:
sandbox/itl/boost/itl/interval.hpp | 98 +++++++++++++++++++++++++++++++++++----
sandbox/itl/libs/itl/test/fastest_itl_interval_/fastest_itl_interval.cpp | 6 ++
sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp | 4 -
sandbox/itl/libs/itl/test/test_itl_interval.hpp | 12 ++++
sandbox/itl/libs/itl/test/test_itl_interval_/test_itl_interval.cpp | 5 ++
5 files changed, 111 insertions(+), 14 deletions(-)
Modified: sandbox/itl/boost/itl/interval.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval.hpp (original)
+++ sandbox/itl/boost/itl/interval.hpp 2010-03-06 11:51:08 EST (Sat, 06 Mar 2010)
@@ -272,8 +272,6 @@
set_upb(upb_min(sectant));
return *this;
}
-
-
//==========================================================================
//= Representation
@@ -490,6 +488,19 @@
: x.upper() - x.lower();
}
+ static typename IntervalT::difference_type
+ distance(const IntervalT& x1, const IntervalT& x2)
+ {
+ if(x1.empty() || x2.empty())
+ return itl::neutron<typename IntervalT::difference_type>::value();
+ else if(IntervalT::domain_less(x1.upper(), x2.lower()))
+ return x2.lower() - x1.upper();
+ else if(IntervalT::domain_less(x2.upper(), x1.lower()))
+ return x1.lower() - x2.upper();
+ else
+ return itl::neutron<typename IntervalT::difference_type>::value();
+ }
+
static bool unaligned_lwb_equal(const IntervalT&, const IntervalT&)
{ return false; }
@@ -518,6 +529,19 @@
: static_cast<typename IntervalT::difference_type>(succ(x.last() - x.first()));
}
+ static typename IntervalT::difference_type
+ distance(const IntervalT& x1, const IntervalT& x2)
+ {
+ if(x1.empty() || x2.empty())
+ return itl::neutron<typename IntervalT::difference_type>::value();
+ else if(IntervalT::domain_less(x1.last(), x2.first()))
+ return static_cast<typename IntervalT::difference_type>(pred(x2.first() - x1.last()));
+ else if(IntervalT::domain_less(x2.last(), x1.first()))
+ return static_cast<typename IntervalT::difference_type>(pred(x1.first() - x2.last()));
+ else
+ return itl::neutron<typename IntervalT::difference_type>::value();
+ }
+
static bool unaligned_lwb_equal(const IntervalT& x1, const IntervalT& x2)
{
if(x1.is_left(open_bounded) && x2.is_left(closed_bounded))
@@ -1023,9 +1047,9 @@
[a b) : left_over
\endcode
*/
-template <class DomainT, ITL_COMPARE Compare>
-inline interval<DomainT,Compare> right_subtract(interval<DomainT,Compare> left,
- const interval<DomainT,Compare>& right_minuend)
+template <class DomainT, ITL_COMPARE Compare, template<class,ITL_COMPARE>class Interval>
+inline Interval<DomainT,Compare> right_subtract(Interval<DomainT,Compare> left,
+ const Interval<DomainT,Compare>& right_minuend)
{
return left.right_subtract(right_minuend);
}
@@ -1039,9 +1063,9 @@
[c d) : right_over
\endcode
*/
-template <class DomainT, ITL_COMPARE Compare>
-inline interval<DomainT,Compare> left_subtract(interval<DomainT,Compare> right,
- const interval<DomainT,Compare>& left_minuend)
+template <class DomainT, ITL_COMPARE Compare, template<class,ITL_COMPARE>class Interval>
+inline Interval<DomainT,Compare> left_subtract(Interval<DomainT,Compare> right,
+ const Interval<DomainT,Compare>& left_minuend)
{
return right.left_subtract(left_minuend);
}
@@ -1051,9 +1075,9 @@
//==============================================================================
/** Returns the intersection of \c left and \c right interval. */
-template <class DomainT, ITL_COMPARE Compare>
-inline itl::interval<DomainT,Compare> operator & (itl::interval<DomainT,Compare> left,
- const itl::interval<DomainT,Compare>& right)
+template <class DomainT, ITL_COMPARE Compare, template<class,ITL_COMPARE>class Interval>
+inline Interval<DomainT,Compare> operator & (Interval<DomainT,Compare> left,
+ const Interval<DomainT,Compare>& right)
{
return left &= right;
}
@@ -1075,6 +1099,58 @@
}
//==============================================================================
+//= Complement
+//==============================================================================
+
+template <class DomainT, ITL_COMPARE Compare,
+ template<class,ITL_COMPARE>class Interval>
+Interval<DomainT,Compare> inner_complement(const Interval<DomainT,Compare>& left,
+ const Interval<DomainT,Compare>& right)
+{
+ if(left.exclusive_less(right))
+ return hull(left, right).left_subtract(left).right_subtract(right);
+ else if(right.exclusive_less(left))
+ return hull(right, left).left_subtract(right).right_subtract(left);
+ else
+ return neutron<Interval<DomainT,Compare> >::value();
+}
+
+//==============================================================================
+//= Distance
+//==============================================================================
+
+template <class DomainT, ITL_COMPARE Compare,
+ template<class,ITL_COMPARE>class Interval>
+inline typename Interval<DomainT,Compare>::difference_type
+ distance(const Interval<DomainT,Compare>& left,
+ const Interval<DomainT,Compare>& right)
+{
+ using namespace boost::mpl;
+ return if_<
+ bool_<is_continuous<DomainT>::value>,
+ continuous_interval<interval<DomainT,Compare> >,
+ discrete_interval<interval<DomainT,Compare> >
+ >
+ ::type::distance(left, right);
+}
+
+template <class DomainT, ITL_COMPARE Compare,
+ template<class,ITL_COMPARE>class Interval>
+inline typename Interval<DomainT,Compare>::difference_type
+ length(const Interval<DomainT,Compare>& inter_val)
+{
+ using namespace boost::mpl;
+ return if_<
+ bool_<is_continuous<DomainT>::value>,
+ continuous_interval<interval<DomainT,Compare> >,
+ discrete_interval<interval<DomainT,Compare> >
+ >
+ ::type::length(inter_val);
+}
+
+
+
+//==============================================================================
//= Representation
//==============================================================================
Modified: sandbox/itl/libs/itl/test/fastest_itl_interval_/fastest_itl_interval.cpp
==============================================================================
--- sandbox/itl/libs/itl/test/fastest_itl_interval_/fastest_itl_interval.cpp (original)
+++ sandbox/itl/libs/itl/test/fastest_itl_interval_/fastest_itl_interval.cpp 2010-03-06 11:51:08 EST (Sat, 06 Mar 2010)
@@ -21,6 +21,7 @@
using namespace unit_test;
using namespace boost::itl;
+#include "../test_itl_interval_shared.hpp"
#include "../test_itl_interval.hpp"
BOOST_AUTO_TEST_CASE
@@ -70,3 +71,8 @@
BOOST_AUTO_TEST_CASE
(fastest_itl_interval_subtract_4_bicremental_types)
{ interval_subtract_4_bicremental_types<bicremental_type_5>(); }
+
+BOOST_AUTO_TEST_CASE
+(fastest_itl_interval_inner_complement_4_bicremental_types)
+{ interval_inner_complement_4_bicremental_types<bicremental_type_6>(); }
+
Modified: sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp (original)
+++ sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp 2010-03-06 11:51:08 EST (Sat, 06 Mar 2010)
@@ -62,8 +62,6 @@
BOOST_AUTO_TEST_CASE(casual)
{
- interval_map<int, float> map_1;
- interval_map<int, float> map_2;
- map_1 & map_2;
+ ;
}
Modified: sandbox/itl/libs/itl/test/test_itl_interval.hpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_itl_interval.hpp (original)
+++ sandbox/itl/libs/itl/test/test_itl_interval.hpp 2010-03-06 11:51:08 EST (Sat, 06 Mar 2010)
@@ -408,4 +408,16 @@
BOOST_CHECK_EQUAL( diff_2, I4_7D );
}
+template <class T>
+void interval_inner_complement_4_bicremental_types()
+{
+ test_inner_complement(interval<T>(), interval<T>());
+ test_inner_complement(interval<T>(), I_D(6,9));
+ test_inner_complement(C_D(2,4), interval<T>());
+ test_inner_complement(I_I(2,5), C_I(3,9));
+ test_inner_complement(I_I(2,4), I_D(6,9));
+ test_inner_complement(I_D(7,9), C_I(0,3));
+}
+
+
#endif // __test_itl_interval_hpp_JOFA_081006__
Modified: sandbox/itl/libs/itl/test/test_itl_interval_/test_itl_interval.cpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_itl_interval_/test_itl_interval.cpp (original)
+++ sandbox/itl/libs/itl/test/test_itl_interval_/test_itl_interval.cpp 2010-03-06 11:51:08 EST (Sat, 06 Mar 2010)
@@ -23,6 +23,7 @@
using namespace boost::itl;
+#include "../test_itl_interval_shared.hpp"
#include "../test_itl_interval.hpp"
BOOST_AUTO_TEST_CASE_TEMPLATE
@@ -73,3 +74,7 @@
(test_itl_interval_subtract_4_bicremental_types, T, bicremental_types)
{ interval_subtract_4_bicremental_types<T>(); }
+BOOST_AUTO_TEST_CASE_TEMPLATE
+(test_itl_interval_inner_complement_4_bicremental_types, T, bicremental_types)
+{ interval_inner_complement_4_bicremental_types<T>(); }
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk