Example #1
0
  explicit BufferReader(ReaderT const & reader, uint64_t offset = 0)
  {
    uint64_t const rSize = reader.Size();
    ASSERT_LESS_OR_EQUAL(offset, rSize, (offset, rSize));

    InitBuffer(static_cast<size_t>(rSize - offset));
    reader.Read(offset, m_data.get(), m_size);
  }
Example #2
0
  BufferReader(BufferReader const & src, uint64_t pos, uint64_t size)
    : m_data(src.m_data)
  {
    ASSERT_LESS_OR_EQUAL(pos + size, src.Size(), (pos, size));

    m_offset = static_cast<size_t>(src.m_offset + pos);
    m_size = static_cast<size_t>(size);
  }
Example #3
0
void cut_path_intervals::operator()(m2::PointD const & pt)
{
  if (m_hasPrevPt)
  {
    double const segLen = pt.Length(m_prev);

    for (; m_pos != m_intervals->size(); m_pos += 2)
    {
      double const start = (*m_intervals)[m_pos];
      if (start >= m_length + segLen)
        break;

      m2::PointD const dir = (pt - m_prev) / segLen;

      if (start >= m_length)
      {
        m_points.push_back(PathInfo(start));
        push_point(m_prev + dir * (start - m_length));
      }

      double const end = (*m_intervals)[m_pos+1];
      if (end >= m_length + segLen)
      {
        push_point(pt);
        break;
      }

      if (end < m_length + segLen)
      {
        push_point(m_prev + dir * (end - m_length));
#ifdef DEBUG
        double const len = m_points.back().GetLength();
        ASSERT_LESS_OR_EQUAL ( fabs(len - (end - start)), 1.0E-4, (len, end - start) );
#endif
      }
    }

    m_prev = pt;
    m_length += segLen;
  }
  else
  {
    m_hasPrevPt = true;
    m_prev = pt;
  }
}
Example #4
0
 inline void Read(uint64_t pos, void * p, size_t size) const
 {
   ASSERT_LESS_OR_EQUAL(pos + size, Size(), (pos, size));
   memcpy(p, m_data.get() + static_cast<size_t>(pos) + m_offset, size);
 }
Example #5
0
 void Read(uint64_t pos, void * p, size_t size) const
 {
   ASSERT_LESS_OR_EQUAL ( pos + size, m_size, (pos, size) );
   m_p->Read(pos + m_pos, p, size);
 }
Example #6
0
 SubReaderWrapper(ReaderT * p, uint64_t pos, uint64_t size)
   : m_p(p), m_pos(pos), m_size(size)
 {
   ASSERT_LESS_OR_EQUAL ( pos + size, m_p->Size(), (pos, size) );
 }
Example #7
0
inline void CoverRect(double minX, double minY,
                      double maxX, double maxY,
                      size_t cells_count, int maxDepth,
                      vector<CellIdT> & cells)
{
  if (minX < BoundsT::minX) minX = BoundsT::minX;
  if (minY < BoundsT::minY) minY = BoundsT::minY;
  if (maxX > BoundsT::maxX) maxX = BoundsT::maxX;
  if (maxY > BoundsT::maxY) maxY = BoundsT::maxY;

  if (minX >= maxX || minY >= maxY)
    return;

  CellIdT commonCell =
      CellIdConverter<BoundsT, CellIdT>::Cover2PointsWithCell(minX, minY, maxX, maxY);

  vector<CellIdT> result;

  queue<CellIdT> cellQueue;
  cellQueue.push(commonCell);

  maxDepth -= 1;

  while (!cellQueue.empty() && cellQueue.size() + result.size() < cells_count)
  {
    CellIdT id = cellQueue.front();
    cellQueue.pop();

    while (id.Level() > maxDepth)
      id = id.Parent();

    if (id.Level() == maxDepth)
    {
      result.push_back(id);
      break;
    }

    vector<CellIdT> children;
    SplitRectCell<BoundsT>(id, minX, minY, maxX, maxY, children);

    // Children shouldn't be empty, but if it is, ignore this cellid in release.
    ASSERT(!children.empty(), (id, minX, minY, maxX, maxY));
    if (children.empty())
    {
      result.push_back(id);
      continue;
    }

    if (cellQueue.size() + result.size() + children.size() <= cells_count)
    {
      for (size_t i = 0; i < children.size(); ++i)
        cellQueue.push(children[i]);
    }
    else
      result.push_back(id);
  }

  for (; !cellQueue.empty(); cellQueue.pop())
    result.push_back(cellQueue.front());

  for (size_t i = 0; i < result.size(); ++i)
  {
    CellIdT id = result[i];
    while (id.Level() < maxDepth)
    {
      vector<CellIdT> children;
      SplitRectCell<BoundsT>(id, minX, minY, maxX, maxY, children);
      if (children.size() == 1)
        id = children[0];
      else
        break;
    }
    result[i] = id;
  }

  ASSERT_LESS_OR_EQUAL(result.size(), cells_count, (minX, minY, maxX, maxY));
  cells.insert(cells.end(), result.begin(), result.end());
}