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)  

Interval< float > Class Reference

#include <Interval.h>

Inheritance diagram for Interval< float >:
[legend]
Collaboration diagram for Interval< float >:
[legend]

Public Member Functions

float start () const
 
float end () const
 
void setStart (float start)
 
void setEnd (float end)
 
bool contains (const Interval< float > &other) const
 
bool contains (float value) const
 
bool intersects (const Interval< float > &other) const
 
void translate (float offset)
 
bool operator== (const Interval< float > &other) const
 
QList< Interval< float > > operator- (QList< Interval< float > > subtrahend)
 
QString toString () const
 Return a string in the format '[start,end]'. More...
 

Static Public Member Functions

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

Protected Attributes

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

Private Member Functions

 Interval ()
 
 Interval (float start, float end)
 
 Interval (const Interval< float > &other)
 
float size () const
 
bool isValid () const
 
bool touches (const Interval< float > &other) const
 Returns true if no gap is between two intervals. More...
 

Detailed Description

Definition at line 229 of file Interval.h.

Constructor & Destructor Documentation

◆ Interval() [1/3]

Interval< float >::Interval ( )
inlineprivate

Definition at line 230 of file Interval.h.

230 {}

◆ Interval() [2/3]

Interval< float >::Interval ( float  start,
float  end 
)
inlineprivate

Definition at line 231 of file Interval.h.

◆ Interval() [3/3]

Interval< float >::Interval ( const Interval< float > &  other)
inlineprivate

Definition at line 232 of file Interval.h.

232 : IntervalBase<float>(other) {}

Member Function Documentation

◆ contains() [1/2]

bool IntervalBase< float >::contains ( const Interval< float > &  other) const
inlineinherited

Definition at line 58 of file Interval.h.

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

◆ contains() [2/2]

bool IntervalBase< float >::contains ( float  value) const
inlineinherited

Definition at line 59 of file Interval.h.

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

◆ end()

float IntervalBase< float >::end
inlineinherited

Definition at line 55 of file Interval.h.

55 { return d_end; }

◆ intersection()

static Interval<float > IntervalBase< float >::intersection ( const Interval< float > &  first,
const Interval< float > &  second 
)
inlinestaticinherited

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  }

◆ intersects()

bool IntervalBase< float >::intersects ( const Interval< float > &  other) const
inlineinherited

Definition at line 60 of file Interval.h.

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

◆ isValid()

bool Interval< float >::isValid ( ) const
inlineprivate

Definition at line 234 of file Interval.h.

◆ merge()

static Interval<float > IntervalBase< float >::merge ( const Interval< float > &  a,
const Interval< float > &  b 
)
inlinestaticinherited

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  }

◆ mergeIntervalIntoList()

static void IntervalBase< float >::mergeIntervalIntoList ( QList< Interval< float > > *  list,
Interval< float >  i 
)
inlinestaticinherited

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  }

◆ operator-()

QList< Interval<float > > IntervalBase< float >::operator- ( QList< Interval< float > >  subtrahend)
inlineinherited

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==()

bool IntervalBase< float >::operator== ( const Interval< float > &  other) const
inlineinherited

Definition at line 70 of file Interval.h.

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

◆ restrictList()

static void IntervalBase< float >::restrictList ( QList< Interval< float > > *  list,
Interval< float >  i 
)
inlinestaticinherited

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()

void IntervalBase< float >::setEnd ( float  end)
inlineinherited

Definition at line 57 of file Interval.h.

57 { d_end = end; }

◆ setStart()

void IntervalBase< float >::setStart ( float  start)
inlineinherited

Definition at line 56 of file Interval.h.

56 { d_start = start; }

◆ size()

float Interval< float >::size ( ) const
inlineprivate

Definition at line 233 of file Interval.h.

◆ split()

static QList< Interval<float > > IntervalBase< float >::split ( const Interval< float > &  i,
float  before 
)
inlinestaticinherited

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()

float IntervalBase< float >::start
inlineinherited

Definition at line 54 of file Interval.h.

54 { return d_start; }

◆ subtract()

static QList< Interval<float > > IntervalBase< float >::subtract ( const Interval< float > &  src_iv,
const Interval< float > &  minus_iv 
)
inlinestaticinherited

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  }

◆ subtractIntervalFromList()

static void IntervalBase< float >::subtractIntervalFromList ( QList< Interval< float > > *  list,
Interval< float >  i 
)
inlinestaticinherited

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()

QString IntervalBase< float >::toString
inlineinherited

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()

bool Interval< float >::touches ( const Interval< float > &  other) const
inlineprivatevirtual

Returns true if no gap is between two intervals.

Implements IntervalBase< float >.

Definition at line 235 of file Interval.h.

235  {
236  return ( (other.end() == IntervalBase<float>::d_start) ||
237  (other.start() == IntervalBase<float>::d_end) );
238  }

References IntervalBase< T >::end(), and IntervalBase< T >::start().

Here is the call graph for this function:

◆ translate()

void IntervalBase< float >::translate ( float  offset)
inlineinherited

Definition at line 69 of file Interval.h.

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

Member Data Documentation

◆ d_end

float IntervalBase< float >::d_end
protectedinherited

Interval end.

Definition at line 198 of file Interval.h.

◆ d_start

float IntervalBase< float >::d_start
protectedinherited

Interval start.

Definition at line 196 of file Interval.h.


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