scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

IntervalBase< T > Class Template Referenceabstract

#include <Interval.h>

Collaboration diagram for IntervalBase< T >:
[legend]

Public Member Functions

 IntervalBase ()
 
 IntervalBase (const IntervalBase< T > &other)
 
 IntervalBase (T start, T end)
 
virtual ~IntervalBase ()
 
start () const
 
end () const
 
void setStart (T start)
 
void setEnd (T end)
 
bool contains (const Interval< T > &other) const
 
bool contains (T value) const
 
bool intersects (const Interval< T > &other) const
 
void translate (T offset)
 
bool operator== (const Interval< T > &other) const
 
Interval< T > & operator= (const Interval< T > &other)
 
virtual bool touches (const Interval< T > &other) const =0
 Returns true if no gap is between two intervals. More...
 
QList< Interval< T > > operator- (QList< Interval< T > > subtrahend)
 
QString toString () const
 Return a string in the format '[start,end]'. More...
 

Static Public Member Functions

static Interval< T > intersection (const Interval< T > &first, const Interval< T > &second)
 Return the intersection of two intervals. More...
 
static Interval< T > merge (const Interval< T > &a, const Interval< T > &b)
 Merge two intervals that touch or intersect. More...
 
static QList< Interval< T > > subtract (const Interval< T > &src_iv, const Interval< T > &minus_iv)
 Subtract an interval from another. More...
 
static QList< Interval< T > > split (const Interval< T > &i, T before)
 Split an interval into two. More...
 
static void mergeIntervalIntoList (QList< Interval< T > > *list, Interval< T > i)
 Merge an interval into a list. More...
 
static void restrictList (QList< Interval< T > > *list, Interval< T > i)
 Restrict all intervals in the list to their intersection with a given interval. More...
 
static void subtractIntervalFromList (QList< Interval< T > > *list, Interval< T > i)
 Subtract an interval from all intervals in the list. More...
 

Protected Attributes

d_start
 Interval start. More...
 
d_end
 Interval end. More...
 

Detailed Description

template<class T>
class IntervalBase< T >

Definition at line 41 of file Interval.h.

Constructor & Destructor Documentation

◆ IntervalBase() [1/3]

template<class T >
IntervalBase< T >::IntervalBase ( )
inline

Definition at line 44 of file Interval.h.

44 : d_start(-1), d_end(-1){}

◆ IntervalBase() [2/3]

template<class T >
IntervalBase< T >::IntervalBase ( const IntervalBase< T > &  other)
inline

Definition at line 45 of file Interval.h.

45  {
46  d_start = other.start();
47  d_end = other.end();
48  }

◆ IntervalBase() [3/3]

template<class T >
IntervalBase< T >::IntervalBase ( start,
end 
)
inline

Definition at line 49 of file Interval.h.

49  {
50  d_start = start;
51  d_end = end;
52  }

◆ ~IntervalBase()

template<class T >
virtual IntervalBase< T >::~IntervalBase ( )
inlinevirtual

Definition at line 53 of file Interval.h.

53 {}

Member Function Documentation

◆ contains() [1/2]

template<class T >
bool IntervalBase< T >::contains ( const Interval< T > &  other) const
inline

Definition at line 58 of file Interval.h.

58 { return ( d_start <= other.start() && d_end >= other.end() ); }

Referenced by IntervalBase< long double >::intersects().

Here is the caller graph for this function:

◆ contains() [2/2]

template<class T >
bool IntervalBase< T >::contains ( value) const
inline

Definition at line 59 of file Interval.h.

59 { return ( d_start <= value && d_end >= value ); }

◆ end()

template<class T >
T IntervalBase< T >::end ( ) const
inline

Definition at line 55 of file Interval.h.

55 { return d_end; }

Referenced by IntervalBase< long double >::IntervalBase(), IntervalBase< long double >::setEnd(), Interval< double >::touches(), Interval< float >::touches(), and Interval< long double >::touches().

Here is the caller graph for this function:

◆ intersection()

template<class T >
static Interval<T> IntervalBase< T >::intersection ( const Interval< T > &  first,
const Interval< T > &  second 
)
inlinestatic

Return the intersection of two intervals.

This function returns an invalid interval if the two intervals do not intersect.

Definition at line 65 of file Interval.h.

66  {
67  return Interval<T>( qMax(first.start(), second.start()), qMin(first.end(), second.end()) );
68  }

Referenced by IntervalBase< long double >::restrictList().

Here is the caller graph for this function:

◆ intersects()

template<class T >
bool IntervalBase< T >::intersects ( const Interval< T > &  other) const
inline

Definition at line 60 of file Interval.h.

60 { return ( contains(other.start()) || contains(other.end()) ); }

◆ merge()

template<class T >
static Interval<T> IntervalBase< T >::merge ( const Interval< T > &  a,
const Interval< T > &  b 
)
inlinestatic

Merge two intervals that touch or intersect.

Definition at line 79 of file Interval.h.

79  {
80  if( !(a.intersects(b) || a.touches(b)) )
81  return a;
82  return Interval<T>( qMin(a.start(), b.start()), qMax(a.end(), b.end()) );
83  }

Referenced by IntervalBase< long double >::mergeIntervalIntoList().

Here is the caller graph for this function:

◆ mergeIntervalIntoList()

template<class T >
static void IntervalBase< T >::mergeIntervalIntoList ( QList< Interval< T > > *  list,
Interval< T >  i 
)
inlinestatic

Merge an interval into a list.

Definition at line 126 of file Interval.h.

126  {
127  for(int c=0; c<list->size(); c++)
128  {
129  if( list->at(c).touches(i) || list->at(c).intersects(i) )
130  {
131  Interval<T> result = merge(list->takeAt(c), i);
132  mergeIntervalIntoList(list, result);
133  return;
134  }
135  }
136  list->append(i);
137  }

Referenced by IntervalBase< long double >::mergeIntervalIntoList().

Here is the caller graph for this function:

◆ operator-()

template<class T >
QList< Interval<T> > IntervalBase< T >::operator- ( QList< Interval< T > >  subtrahend)
inline

Definition at line 174 of file Interval.h.

174  {
175  QList< Interval<T> > *tmp1, *tmp2;
176  tmp1 = new QList< Interval<T> >();
177  *tmp1 << *static_cast< Interval<T>* >(this);
178  foreach(Interval<T> i, subtrahend) {
179  tmp2 = new QList< Interval<T> >();
180  foreach(Interval<T> j, *tmp1)
181  *tmp2 << subtract(j, i);
182  delete tmp1;
183  tmp1 = tmp2;
184  }
185  QList< Interval<T> > result = *tmp1;
186  delete tmp1;
187  return result;
188  }

◆ operator=()

template<class T >
Interval<T>& IntervalBase< T >::operator= ( const Interval< T > &  other)
inline

Definition at line 71 of file Interval.h.

71  {
72  d_start = other.start();
73  d_end = other.end();
74  return *this;
75  }

◆ operator==()

template<class T >
bool IntervalBase< T >::operator== ( const Interval< T > &  other) const
inline

Definition at line 70 of file Interval.h.

70 { return ( d_start == other.start() && d_end == other.end() ); }

◆ restrictList()

template<class T >
static void IntervalBase< T >::restrictList ( QList< Interval< T > > *  list,
Interval< T >  i 
)
inlinestatic

Restrict all intervals in the list to their intersection with a given interval.

Remark: This may decrease the list size.

Definition at line 142 of file Interval.h.

143  {
144  Interval<T> temp;
145  for(int c=0; c<list->size(); c++)
146  {
147  temp = intersection(list->at(c), i);
148  if(!temp.isValid())
149  list->removeAt(c--);
150  else
151  list->replace(c, temp);
152  }
153 
154  }

◆ setEnd()

template<class T >
void IntervalBase< T >::setEnd ( end)
inline

Definition at line 57 of file Interval.h.

57 { d_end = end; }

◆ setStart()

template<class T >
void IntervalBase< T >::setStart ( start)
inline

Definition at line 56 of file Interval.h.

56 { d_start = start; }

◆ split()

template<class T >
static QList< Interval<T> > IntervalBase< T >::split ( const Interval< T > &  i,
before 
)
inlinestatic

Split an interval into two.

Definition at line 104 of file Interval.h.

104  {
105  QList< Interval<T> > list;
106  if( before < i.start() || before > i.end() )
107  {
108  list.append(i);
109  }
110  else
111  {
112  Interval<T> left(i.start(), before-1);
113  Interval<T> right(before, i.end());
114  if(left.isValid())
115  list.append(left);
116  if(right.isValid())
117  list.append(right);
118  }
119  return list;
120  }

◆ start()

template<class T >
T IntervalBase< T >::start ( ) const
inline

Definition at line 54 of file Interval.h.

54 { return d_start; }

Referenced by IntervalBase< long double >::IntervalBase(), IntervalBase< long double >::setStart(), Interval< double >::touches(), Interval< float >::touches(), and Interval< long double >::touches().

Here is the caller graph for this function:

◆ subtract()

template<class T >
static QList< Interval<T> > IntervalBase< T >::subtract ( const Interval< T > &  src_iv,
const Interval< T > &  minus_iv 
)
inlinestatic

Subtract an interval from another.

Definition at line 85 of file Interval.h.

85  {
86  QList< Interval<T> > list;
87  if( (src_iv == minus_iv) || (minus_iv.contains(src_iv)) )
88  return list;
89 
90  if( !src_iv.intersects(minus_iv) )
91  list.append(src_iv);
92  else if( src_iv.end() <= minus_iv.end() )
93  list.append( Interval<T>(src_iv.start(), minus_iv.start()-1) );
94  else if( src_iv.start() >= minus_iv.start() )
95  list.append( Interval<T>(minus_iv.end()+1, src_iv.end()) );
96  else {
97  list.append( Interval<T>(src_iv.start(), minus_iv.start()-1) );
98  list.append( Interval<T>(minus_iv.end()+1, src_iv.end()) );
99  }
100 
101  return list;
102  }

Referenced by IntervalBase< long double >::operator-(), and IntervalBase< long double >::subtractIntervalFromList().

Here is the caller graph for this function:

◆ subtractIntervalFromList()

template<class T >
static void IntervalBase< T >::subtractIntervalFromList ( QList< Interval< T > > *  list,
Interval< T >  i 
)
inlinestatic

Subtract an interval from all intervals in the list.

Remark: This may increase or decrease the list size.

Definition at line 159 of file Interval.h.

159  {
160  QList< Interval<T> > temp_list;
161  for(int c=0; c<list->size(); c++)
162  {
163  temp_list = subtract(list->at(c), i);
164  if(temp_list.isEmpty())
165  list->removeAt(c--);
166  else
167  {
168  list->replace(c, temp_list.at(0));
169  if(temp_list.size()>1)
170  list->insert(c, temp_list.at(1));
171  }
172  }
173  }

◆ toString()

template<class T >
QString IntervalBase< T >::toString ( ) const
inline

Return a string in the format '[start,end]'.

Definition at line 190 of file Interval.h.

190  {
191  return "[" + QString::number(d_start) + "," + QString::number(d_end) + "]";
192  }

◆ touches()

template<class T >
virtual bool IntervalBase< T >::touches ( const Interval< T > &  other) const
pure virtual

Returns true if no gap is between two intervals.

Implemented in Interval< long double >, Interval< float >, and Interval< double >.

◆ translate()

template<class T >
void IntervalBase< T >::translate ( offset)
inline

Definition at line 69 of file Interval.h.

69 { d_start += offset; d_end += offset; }

Member Data Documentation

◆ d_end

◆ d_start


The documentation for this class was generated from the following file:
Interval::touches
bool touches(const Interval< T > &other) const
Definition: Interval.h:223
IntervalBase::merge
static Interval< T > merge(const Interval< T > &a, const Interval< T > &b)
Merge two intervals that touch or intersect.
Definition: Interval.h:79
IntervalBase::intersection
static Interval< T > intersection(const Interval< T > &first, const Interval< T > &second)
Return the intersection of two intervals.
Definition: Interval.h:65
Interval::isValid
bool isValid() const
Definition: Interval.h:219
IntervalBase::start
T start() const
Definition: Interval.h:54
IntervalBase::mergeIntervalIntoList
static void mergeIntervalIntoList(QList< Interval< T > > *list, Interval< T > i)
Merge an interval into a list.
Definition: Interval.h:126
IntervalBase::d_start
T d_start
Interval start.
Definition: Interval.h:196
IntervalBase::subtract
static QList< Interval< T > > subtract(const Interval< T > &src_iv, const Interval< T > &minus_iv)
Subtract an interval from another.
Definition: Interval.h:85
IntervalBase::contains
bool contains(const Interval< T > &other) const
Definition: Interval.h:58
IntervalBase::d_end
T d_end
Interval end.
Definition: Interval.h:198
IntervalBase::end
T end() const
Definition: Interval.h:55
Interval
Auxiliary class for interval based data.
Definition: Interval.h:211