Esempio n. 1
0
void IntervalList::addIntervalList(const IntervalList& intervals)
{
  const QList<Interval> list = intervals.getList();

  QList<Interval>::const_iterator it = list.constBegin();

  for( ; it != list.constEnd(); ++it)
  {
    addInterval((*it));
  }
}
Esempio n. 2
0
IntervalList IntervalList::intersect(const IntervalList& a, const IntervalList& b)
{
  IntervalList output;

  const QList<Interval> aList = a.getList();
  const QList<Interval> bList = b.getList();

  QList<Interval>::const_iterator aIt = aList.constBegin();
  QList<Interval>::const_iterator bIt = bList.constBegin();

  QList<Interval>::const_iterator aItEnd = aList.constEnd();
  QList<Interval>::const_iterator bItEnd = bList.constEnd();

  bool a_open = false;
  bool b_open = false;

  int start = 0;
  int end = 0;

  // This looks atrocious, but is probably one of the quickest available methods
  // to find the intersections of two lists of Intervals.  An easier (but much 
  // less effecient way) would be to define Interval::intersect(Interval a, Interval b)
  // for the Interval class, and then use that method to intersect two lists.  

  // Plus, this is probably overkill anyway: who is going to spend time typing 
  // in an interval list big enough to slow a computer down?
  while(aIt != aItEnd && bIt != bItEnd)
  {
    if(!a_open && !b_open)
    {
      if((*aIt).start() < (*bIt).start())
      {
        a_open = true;
      } 
      else if((*aIt).start() > (*bIt).start())
      {
        b_open = true;
      }
      else
      {
        a_open = true;
        b_open = true;
        start = (*aIt).start();
      }
    }
    else if(a_open && !b_open)
    {
      if((*aIt).end() < (*bIt).start())
      {
        a_open = false;
        ++aIt;
      } 
      else if((*aIt).end() > (*bIt).start())
      {
        b_open = true;
        start = (*bIt).start();
      }
      else
      {
        a_open = false;
        b_open = true;
        start = (*aIt).end();
        end = (*bIt).start();
        Interval interval(start, end);
        output.addInterval(interval);
        ++aIt;
      }
    }
    else if(!a_open && b_open)
    {
      if((*bIt).end() < (*aIt).start())
      {
        b_open = false;
        ++bIt;
      } 
      else if((*aIt).end() > (*bIt).start())
      {
        a_open = true;
        start = (*aIt).start();
      }
      else
      {
        b_open = false;
        a_open = true;
        start = (*bIt).end();
        end = (*aIt).start();
        Interval interval(start, end);
        output.addInterval(interval);
        ++bIt;
      }
    }
    else
    {
      if((*aIt).end() < (*bIt).end())
      {
        a_open = false;
        end = (*aIt).end();
        Interval interval(start, end);
        output.addInterval(interval);
        ++aIt;
      } 
      else if((*aIt).end() > (*bIt).end())
      {
        b_open = false;
        end = (*bIt).end();
        Interval interval(start, end);
        output.addInterval(interval);
        ++bIt;
      }
      else
      {
        a_open = false;
        b_open = false;
        end = (*aIt).end();
        Interval interval(start, end);
        output.addInterval(interval);
        ++aIt;
        ++bIt;
      }
    }
  }

  return output;
}
Esempio n. 3
0
void IntervalList::setIntervalList(const IntervalList& intervals)
{
  m_list = QList<Interval>(intervals.getList());
}