Exemplo n.º 1
0
                /**
                 * Find duplicate segments (ie same start and end point) in the
                 * list and remove them. This will always remove pairs of the
                 * same segment. So if there are three, for instance, two will
                 * be removed and one will be left.
                 */
                uint32_t erase_duplicate_segments(osmium::area::ProblemReporter* problem_reporter) {
                    uint32_t duplicate_segments = 0;

                    while (true) {
                        auto it = std::adjacent_find(m_segments.begin(), m_segments.end());
                        if (it == m_segments.end()) {
                            break;
                        }
                        if (m_debug) {
                            std::cerr << "  erase duplicate segment: " << *it << "\n";
                        }

                        // Only count and report duplicate segments if they
                        // belong to the same way or if they don't both have
                        // the role "inner". Those cases are definitely wrong.
                        // If the duplicate segments belong to different
                        // "inner" ways, they could be touching inner rings
                        // which are perfectly okay. Note that for this check
                        // the role has to be correct in the member data.
                        if (it->way() == std::next(it)->way() || !it->role_inner() || !std::next(it)->role_inner()) {
                            ++duplicate_segments;
                            if (problem_reporter) {
                                problem_reporter->report_duplicate_segment(it->first(), it->second());
                            }
                        }
                        m_segments.erase(it, it+2);
                    }

                    return duplicate_segments;
                }
Exemplo n.º 2
0
                /**
                 * Find intersection between segments.
                 *
                 * @param problem_reporter Any intersections found are reported to this object.
                 * @returns true if there are intersections.
                 */
                bool find_intersections(osmium::area::ProblemReporter* problem_reporter) const {
                    if (m_segments.empty()) {
                        return false;
                    }

                    bool found_intersections = false;

                    for (auto it1 = m_segments.begin(); it1 != m_segments.end()-1; ++it1) {
                        const NodeRefSegment& s1 = *it1;
                        for (auto it2 = it1+1; it2 != m_segments.end(); ++it2) {
                            const NodeRefSegment& s2 = *it2;

                            assert(s1 != s2); // erase_duplicate_segments() should have made sure of that

                            if (outside_x_range(s2, s1)) {
                                break;
                            }

                            if (y_range_overlap(s1, s2)) {
                                osmium::Location intersection = calculate_intersection(s1, s2);
                                if (intersection) {
                                    found_intersections = true;
                                    if (m_debug) {
                                        std::cerr << "  segments " << s1 << " and " << s2 << " intersecting at " << intersection << "\n";
                                    }
                                    if (problem_reporter) {
                                        problem_reporter->report_intersection(s1.way()->id(), s1.first().location(), s1.second().location(), s2.way()->id(), s2.first().location(), s2.second().location(), intersection);
                                    }
                                }
                            }
                        }
                    }

                    return found_intersections;
                }
Exemplo n.º 3
0
 /**
  * Find duplicate segments (ie same start and end point) in the
  * list and remove them. This will always remove pairs of the same
  * segment. So if there are three, for instance, two will be
  * removed and one will be left.
  */
 void erase_duplicate_segments() {
     while (true) {
         auto it = std::adjacent_find(m_segments.begin(), m_segments.end());
         if (it == m_segments.end()) {
             return;
         }
         if (m_debug) {
             std::cerr << "  erase duplicate segment: " << *it << "\n";
         }
         m_segments.erase(it, it+2);
     }
 }
Exemplo n.º 4
0
 /// Sort the list of segments.
 void sort() {
     std::sort(m_segments.begin(), m_segments.end());
 }
Exemplo n.º 5
0
 const_iterator begin() const noexcept {
     return m_segments.begin();
 }
Exemplo n.º 6
0
 iterator begin() noexcept {
     return m_segments.begin();
 }