Example #1
0
void Sweep::SweepPoints(SweepContext& tcx)
{
  for (int i = 1; i < tcx.point_count(); i++) {
    Point& point = *tcx.GetPoint(i);
    Node* node = &PointEvent(tcx, point);
    for (unsigned int i = 0; i < point.edge_list.size(); i++) {
      EdgeEvent(tcx, point.edge_list[i], node);
    }
  }
}
Example #2
0
  static void Match(std::vector<PointIdPair> const & points, std::vector<RectIdPair> const & rects,
                    RequestType requestType, Fn && fn)
  {
    std::vector<Event> events;
    events.reserve(points.size() + 2 * rects.size());

    for (auto const & p : points)
      events.emplace_back(PointEvent(p.m_point.x, p.m_id), p.m_point.y);

    std::vector<SegmentTree::Segment> segments;
    segments.reserve(rects.size());

    for (auto const & r : rects)
    {
      SegmentTree::Segment const segment(r.m_rect.minX(), r.m_rect.maxX(), r.m_id);

      segments.push_back(segment);
      events.emplace_back(Event::TYPE_SEGMENT_START, segment, r.m_rect.minY());
      events.emplace_back(Event::TYPE_SEGMENT_END, segment, r.m_rect.maxY());
    }

    std::sort(segments.begin(), segments.end());
    SegmentTree tree(segments);

    std::sort(events.begin(), events.end());
    for (auto const & e : events)
    {
      switch (e.m_type)
      {
      case Event::TYPE_SEGMENT_START: tree.Add(e.m_segment); break;
      case Event::TYPE_POINT:
      {
        auto const segmentFn = [&](SegmentTree::Segment const & segment) {
          fn(e.m_point.m_id, segment.m_id);
        };
        switch (requestType)
        {
        case RequestType::Any: tree.FindAny(e.m_point.m_x, segmentFn); break;
        case RequestType::All: tree.FindAll(e.m_point.m_x, segmentFn); break;
        }
      }
      break;
      case Event::TYPE_SEGMENT_END: tree.Erase(e.m_segment); break;
      }
    }
  }