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< long double > Class Reference

#include <Interval.h>

Inheritance diagram for Interval< long double >:
[legend]
Collaboration diagram for Interval< long double >:
[legend]

Public Member Functions

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

Static Public Member Functions

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

Protected Attributes

long double d_start
 Interval start. More...
 
long double d_end
 Interval end. More...
 

Private Member Functions

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

Detailed Description

Definition at line 253 of file Interval.h.

Constructor & Destructor Documentation

◆ Interval() [1/3]

Interval< long double >::Interval ( )
inlineprivate

Definition at line 254 of file Interval.h.

254 {}

◆ Interval() [2/3]

Interval< long double >::Interval ( long double  start,
long double  end 
)
inlineprivate

Definition at line 255 of file Interval.h.

◆ Interval() [3/3]

Interval< long double >::Interval ( const Interval< long double > &  other)
inlineprivate

Definition at line 256 of file Interval.h.

256 : IntervalBase<long double>(other) {}

Member Function Documentation

◆ contains() [1/2]

bool IntervalBase< long double >::contains ( const Interval< long double > &  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< long double >::contains ( long double  value) const
inlineinherited

Definition at line 59 of file Interval.h.

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

◆ end()

long double IntervalBase< long double >::end
inlineinherited

Definition at line 55 of file Interval.h.

55 { return d_end; }

◆ intersection()

static Interval<long double > IntervalBase< long double >::intersection ( const Interval< long double > &  first,
const Interval< long double > &  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< long double >::intersects ( const Interval< long double > &  other) const
inlineinherited

Definition at line 60 of file Interval.h.

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

◆ isValid()

bool Interval< long double >::isValid ( ) const
inlineprivate

Definition at line 258 of file Interval.h.

◆ merge()

static Interval<long double > IntervalBase< long double >::merge ( const Interval< long double > &  a,
const Interval< long double > &  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< long double >::mergeIntervalIntoList ( QList< Interval< long double > > *  list,
Interval< long double >  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<long double > > IntervalBase< long double >::operator- ( QList< Interval< long double > >  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< long double >::operator== ( const Interval< long double > &  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< long double >::restrictList ( QList< Interval< long double > > *  list,
Interval< long double >  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< long double >::setEnd ( long double  end)
inlineinherited

Definition at line 57 of file Interval.h.

57 { d_end = end; }

◆ setStart()

void IntervalBase< long double >::setStart ( long double  start)
inlineinherited

Definition at line 56 of file Interval.h.

56 { d_start = start; }

◆ size()

long double Interval< long double >::size ( ) const
inlineprivate

◆ split()

static QList< Interval<long double > > IntervalBase< long double >::split ( const Interval< long double > &  i,
long double  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()

long double IntervalBase< long double >::start
inlineinherited

Definition at line 54 of file Interval.h.

54 { return d_start; }

◆ subtract()

static QList< Interval<long double > > IntervalBase< long double >::subtract ( const Interval< long double > &  src_iv,
const Interval< long double > &  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< long double >::subtractIntervalFromList ( QList< Interval< long double > > *  list,
Interval< long double >  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< long double >::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< long double >::touches ( const Interval< long double > &  other) const
inlineprivatevirtual

Returns true if no gap is between two intervals.

Implements IntervalBase< long double >.

Definition at line 259 of file Interval.h.

259  {
260  return ( (other.end() == IntervalBase<long double>::d_start) ||
262  }

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

Here is the call graph for this function:

◆ translate()

void IntervalBase< long double >::translate ( long double  offset)
inlineinherited

Definition at line 69 of file Interval.h.

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

Member Data Documentation

◆ d_end

long double IntervalBase< long double >::d_end
protectedinherited

Interval end.

Definition at line 198 of file Interval.h.

◆ d_start

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