Exemplo n.º 1
0
vector<m2::SharedSpline> ClipSplineByRect(m2::RectD const & rect, m2::SharedSpline const & spline)
{
  vector<m2::SharedSpline> result;

  vector<m2::PointD> const & path = spline->GetPath();
  if (path.size() < 2)
    return result;

  m2::RectD splineRect;
  for (m2::PointD const & p : path)
    splineRect.Add(p);

  // Check for spline is inside.
  if (rect.IsRectInside(splineRect))
  {
    result.push_back(spline);
    return result;
  }

  // Check for spline is outside.
  if (!rect.IsIntersect(splineRect))
    return result;

  // Divide spline into parts.
  result.reserve(2);
  m2::PointD p1, p2;
  int code1 = 0;
  int code2 = 0;
  m2::SharedSpline s;
  s.Reset(new m2::Spline(path.size()));

  for (size_t i = 0; i < path.size() - 1; i++)
  {
    p1 = path[i];
    p2 = path[i + 1];
    if (m2::Intersect(rect, p1, p2, code1, code2))
    {
      if ((p1 - p2).IsAlmostZero())
        continue;

      if (s.IsNull())
        s.Reset(new m2::Spline(path.size() - i));

      s->AddPoint(p1);
      if (code2 != 0 || i + 2 == path.size())
      {
        s->AddPoint(p2);
        result.push_back(s);
        s.Reset(nullptr);
      }
    }
  }
  return result;
}
Exemplo n.º 2
0
vector<TCountryId> CountryInfoGetter::GetRegionsCountryIdByRect(m2::RectD const & rect) const
{
  size_t constexpr kAverageSize = 10;

  vector<TCountryId> result;
  result.reserve(kAverageSize);
  for (size_t id = 0; id < m_countries.size(); ++id)
  {
    if (rect.IsRectInside(m_countries[id].m_rect) ||
        (rect.IsIntersect(m_countries[id].m_rect) && IsIntersectedByRegionImpl(id, rect)))
    {
      result.push_back(m_countries[id].m_countryId);
    }
  }
  return result;
}