INET Framework for OMNeT++/OMNEST
inet::math::Interval< T > Class Template Reference

N-dimensional interval (cuboid), given by its two opposite corners. More...

#include <Interval.h>

Public Member Functions

 Interval (const Point< T ... > &lower, const Point< T ... > &upper, unsigned char lowerClosed, unsigned char upperClosed, unsigned char fixed)
 
const Point< T ... > & getLower () const
 
const Point< T ... > & getUpper () const
 
unsigned char getLowerClosed () const
 
unsigned char getUpperClosed () const
 
unsigned char getFixed () const
 
template<typename X , int DIMENSION>
Interval< X > get () const
 
template<typename X , int DIMENSION>
void set (const Interval< X > &ix)
 
bool contains (const Point< T ... > &p) const
 
double getVolume () const
 Returns the volume in the dimensions denoted by the 1 bits of dims. More...
 
bool isEmpty () const
 Returns true iff getVolume() == 0. More...
 
Interval< T ... > getIntersected (const Interval< T ... > &o) const
 
Interval< T ... > getShifted (const Point< T ... > &p) const
 
template<typename X , int DIMENSION>
Interval< T ... > getReplaced (Interval< X > ix) const
 
template<typename X , int DIMENSION>
Interval< T ... > getFixed (X x) const
 
std::string str () const
 

Protected Member Functions

template<size_t ... IS>
void checkImpl (std::integer_sequence< size_t, IS... >) const
 
template<size_t ... IS>
bool containsImpl (const Point< T ... > &p, std::integer_sequence< size_t, IS... >) const
 
template<size_t ... IS>
Interval< T ... > intersectImpl (const Interval< T ... > &o, std::integer_sequence< size_t, IS... >) const
 
template<size_t ... IS>
double getVolumeImpl (std::integer_sequence< size_t, IS... >) const
 
template<size_t ... IS>
bool isEmptyImpl (std::integer_sequence< size_t, IS... >) const
 

Protected Attributes

Point< T ... > lower
 
Point< T ... > upper
 
unsigned char lowerClosed
 
unsigned char upperClosed
 
unsigned char fixed
 

Detailed Description

template<typename... T>
class inet::math::Interval< T >

N-dimensional interval (cuboid), given by its two opposite corners.

Constructor & Destructor Documentation

◆ Interval()

template<typename... T>
inet::math::Interval< T >::Interval ( const Point< T ... > &  lower,
const Point< T ... > &  upper,
unsigned char  lowerClosed,
unsigned char  upperClosed,
unsigned char  fixed 
)
inline
108  :
110 #ifndef NDEBUG
111  checkImpl(std::index_sequence_for<T ...>{});
112 #endif
113  }

Member Function Documentation

◆ checkImpl()

template<typename... T>
template<size_t ... IS>
void inet::math::Interval< T >::checkImpl ( std::integer_sequence< size_t, IS... >  ) const
inlineprotected
37  {
38  unsigned char b = 1 << std::tuple_size<std::tuple<T ...>>::value >> 1;
39  bool check = true;
40  std::initializer_list<bool> l1{ check &= std::get<IS>(lower) <= std::get<IS>(upper) ... };
41  (void)l1;
42  if (!check)
43  throw cRuntimeError("Invalid lower or upper arguments");
44  check = true;
45  std::initializer_list<bool> l2{ check &= (fixed & (b >> IS) ? lowerClosed & upperClosed & (b >> IS) && std::get<IS>(lower) == std::get<IS>(upper) : true) ... };
46  (void)l2;
47  if (!check)
48  throw cRuntimeError("Invalid fixed argument, interval = %s, fixed = %d", str().c_str(), fixed);
49  auto m = (1 << std::tuple_size<std::tuple<T ...>>::value) - 1;
50  if (lowerClosed != (lowerClosed & m))
51  throw cRuntimeError("Invalid lowerClosed argument");
52  if (upperClosed != (upperClosed & m))
53  throw cRuntimeError("Invalid upperClosed argument");
54  if (fixed != (fixed & m))
55  throw cRuntimeError("Invalid fixed argument");
56  if (fixed != (lowerClosed & fixed))
57  throw cRuntimeError("Invalid combination of fixed and lowerClosed arguments");
58  if (fixed != (upperClosed & fixed))
59  throw cRuntimeError("Invalid combination of fixed and upperClosed arguments");
60  }

◆ contains()

template<typename... T>
bool inet::math::Interval< T >::contains ( const Point< T ... > &  p) const
inline
139  {
140  return containsImpl(p, std::index_sequence_for<T ...>{});
141  }

◆ containsImpl()

template<typename... T>
template<size_t ... IS>
bool inet::math::Interval< T >::containsImpl ( const Point< T ... > &  p,
std::integer_sequence< size_t, IS... >   
) const
inlineprotected
63  {
64  bool result = true;
65  unsigned char b = 1 << std::tuple_size<std::tuple<T ...>>::value >> 1;
66  (void)std::initializer_list<bool>{ result &= ((lowerClosed & (b >> IS)) ? std::get<IS>(lower) <= std::get<IS>(p) : std::get<IS>(lower) < std::get<IS>(p)) ... };
67  (void)std::initializer_list<bool>{ result &= ((upperClosed & (b >> IS)) ? std::get<IS>(p) <= std::get<IS>(upper) : std::get<IS>(p) < std::get<IS>(upper)) ... };
68  return result;
69  }

◆ get()

template<typename... T>
template<typename X , int DIMENSION>
Interval<X> inet::math::Interval< T >::get ( ) const
inline
122  {
123  unsigned char s = std::tuple_size<std::tuple<T ...>>::value - DIMENSION - 1;
124  return Interval<X>(std::get<DIMENSION>(lower), std::get<DIMENSION>(upper), (lowerClosed >> s) & 0b1, (upperClosed >> s) & 0b1, (fixed >> s) & 0b1);
125  }

◆ getFixed() [1/2]

◆ getFixed() [2/2]

template<typename... T>
template<typename X , int DIMENSION>
Interval<T ...> inet::math::Interval< T >::getFixed ( x) const
inline
169  {
170  unsigned char b = 1 << std::tuple_size<std::tuple<T ...>>::value >> 1;
171  auto m = (b >> DIMENSION);
172  Point<T ...> pl = lower;
173  Point<T ...> pu = upper;
174  std::get<DIMENSION>(pl) = x;
175  std::get<DIMENSION>(pu) = x;
176  return Interval<T ...>(pl, pu, lowerClosed | m, upperClosed | m, fixed | m);
177  }

◆ getIntersected()

◆ getLower()

◆ getLowerClosed()

◆ getReplaced()

template<typename... T>
template<typename X , int DIMENSION>
Interval<T ...> inet::math::Interval< T >::getReplaced ( Interval< X >  ix) const
inline
162  {
163  Interval<T ...> i = *this;
164  i.template set<X, DIMENSION>(ix);
165  return i;
166  }

◆ getShifted()

template<typename... T>
Interval<T ...> inet::math::Interval< T >::getShifted ( const Point< T ... > &  p) const
inline
157  {
158  return Interval<T ...>(lower + p, upper + p, lowerClosed, upperClosed, fixed);
159  }

◆ getUpper()

◆ getUpperClosed()

◆ getVolume()

template<typename... T>
double inet::math::Interval< T >::getVolume ( ) const
inline

Returns the volume in the dimensions denoted by the 1 bits of dims.

144  {
145  return getVolumeImpl(std::index_sequence_for<T ...>{});
146  }

◆ getVolumeImpl()

template<typename... T>
template<size_t ... IS>
double inet::math::Interval< T >::getVolumeImpl ( std::integer_sequence< size_t, IS... >  ) const
inlineprotected
92  {
93  double result = 1;
94  unsigned char b = 1 << std::tuple_size<std::tuple<T ...>>::value >> 1;
95  (void)std::initializer_list<double>{ result *= ((fixed & (b >> IS)) ? 1 : toDouble(std::get<IS>(upper) - std::get<IS>(lower))) ... };
96  return result;
97  }

◆ intersectImpl()

template<typename... T>
template<size_t ... IS>
Interval<T ...> inet::math::Interval< T >::intersectImpl ( const Interval< T ... > &  o,
std::integer_sequence< size_t, IS... >   
) const
inlineprotected
72  {
73  unsigned char b = 1 << std::tuple_size<std::tuple<T ...>>::value >> 1;
74  Point<T ...> l(math::maxnan(std::get<IS>(lower), std::get<IS>(o.lower)) ...);
75  (void)l;
76  Point<T ...> u(math::minnan(std::get<IS>(upper), std::get<IS>(o.upper)) ...);
77  (void)u;
78  unsigned char lc = 0;
79  unsigned char uc = 0;
80  (void)std::initializer_list<unsigned char>{ lc += ((b >> IS) & (std::get<IS>(upper) < std::get<IS>(l) || std::get<IS>(lower) > std::get<IS>(u) ? 0 :
81  (std::get<IS>(lower) == std::get<IS>(o.lower) ? (lowerClosed & o.lowerClosed) :
82  (std::get<IS>(lower) > std::get<IS>(o.lower) ? lowerClosed : o.lowerClosed)))) ... };
83  (void)std::initializer_list<unsigned char>{ uc += ((b >> IS) & (std::get<IS>(lower) > std::get<IS>(u) || std::get<IS>(upper) < std::get<IS>(l) ? 0 :
84  (std::get<IS>(upper) == std::get<IS>(o.upper) ? (upperClosed & o.upperClosed) :
85  (std::get<IS>(upper) < std::get<IS>(o.upper) ? upperClosed : o.upperClosed)))) ... };
86  Point<T ...> l1(math::minnan(std::get<IS>(upper), std::get<IS>(l)) ...);
87  Point<T ...> u1(math::maxnan(std::get<IS>(lower), std::get<IS>(u)) ...);
88  return Interval<T ...>(l1, u1, lc, uc, (fixed | o.getFixed()) & lc & uc);
89  }

◆ isEmpty()

template<typename... T>
bool inet::math::Interval< T >::isEmpty ( ) const
inline

◆ isEmptyImpl()

template<typename... T>
template<size_t ... IS>
bool inet::math::Interval< T >::isEmptyImpl ( std::integer_sequence< size_t, IS... >  ) const
inlineprotected
100  {
101  unsigned char b = 1 << std::tuple_size<std::tuple<T ...>>::value >> 1;
102  bool result = false;
103  (void)std::initializer_list<bool>{ result |= ((fixed & (b >> IS)) ? false : std::get<IS>(lower) == std::get<IS>(upper)) ... };
104  return result;
105  }

◆ set()

template<typename... T>
template<typename X , int DIMENSION>
void inet::math::Interval< T >::set ( const Interval< X > &  ix)
inline
128  {
129  unsigned char s = std::tuple_size<std::tuple<T ...>>::value - DIMENSION - 1;
130  unsigned char b = 1 << std::tuple_size<std::tuple<T ...>>::value >> 1;
131  auto m = (b >> DIMENSION);
132  std::get<DIMENSION>(lower) = std::get<0>(ix.getLower());
133  std::get<DIMENSION>(upper) = std::get<0>(ix.getUpper());
134  lowerClosed = (lowerClosed & ~m) | (ix.getLowerClosed() << s);
135  upperClosed = (upperClosed & ~m) | (ix.getUpperClosed() << s);
136  fixed = (fixed & ~m) | (ix.getFixed() << s);
137  }

◆ str()

template<typename... T>
std::string inet::math::Interval< T >::str ( ) const
inline
179  {
180  std::stringstream os;
181  os << *this;
182  return os.str();
183  }

Member Data Documentation

◆ fixed

template<typename... T>
unsigned char inet::math::Interval< T >::fixed
protected

◆ lower

template<typename... T>
Point<T ...> inet::math::Interval< T >::lower
protected

◆ lowerClosed

template<typename... T>
unsigned char inet::math::Interval< T >::lowerClosed
protected

◆ upper

template<typename... T>
Point<T ...> inet::math::Interval< T >::upper
protected

◆ upperClosed

template<typename... T>
unsigned char inet::math::Interval< T >::upperClosed
protected

The documentation for this class was generated from the following file:
inet::units::units::T
compose< Wb, pow< m, -2 > > T
Definition: Units.h:951
inet::math::Interval::checkImpl
void checkImpl(std::integer_sequence< size_t, IS... >) const
Definition: Interval.h:37
inet::math::Interval::getVolumeImpl
double getVolumeImpl(std::integer_sequence< size_t, IS... >) const
Definition: Interval.h:92
inet::math::Interval::fixed
unsigned char fixed
Definition: Interval.h:33
inet::math::Interval::Interval
Interval(const Point< T ... > &lower, const Point< T ... > &upper, unsigned char lowerClosed, unsigned char upperClosed, unsigned char fixed)
Definition: Interval.h:108
inet::math::toDouble
double toDouble(const T v)
Definition: Point.h:28
inet::math::Interval::str
std::string str() const
Definition: Interval.h:179
inet::math::maxnan
const T maxnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::max and std::fmax.
Definition: INETMath.h:234
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::math::Interval::upper
Point< T ... > upper
Definition: Interval.h:30
inet::math::Interval::isEmptyImpl
bool isEmptyImpl(std::integer_sequence< size_t, IS... >) const
Definition: Interval.h:100
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::math::Interval::containsImpl
bool containsImpl(const Point< T ... > &p, std::integer_sequence< size_t, IS... >) const
Definition: Interval.h:63
inet::math::Interval::get
Interval< X > get() const
Definition: Interval.h:122
inet::math::Interval::lower
Point< T ... > lower
Definition: Interval.h:29
inet::math::minnan
const T minnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::min and std::fmin.
Definition: INETMath.h:216
inet::math::Interval::upperClosed
unsigned char upperClosed
Definition: Interval.h:32
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::math::Interval::intersectImpl
Interval< T ... > intersectImpl(const Interval< T ... > &o, std::integer_sequence< size_t, IS... >) const
Definition: Interval.h:72
inet::math::Interval::lowerClosed
unsigned char lowerClosed
Definition: Interval.h:31