Coverage Report

Created: 2026-03-20 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/include/geos/geomgraph/EdgeIntersectionList.h
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7
 * Copyright (C) 2005-2006 Refractions Research Inc.
8
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9
 *
10
 * This is free software; you can redistribute and/or modify it under
11
 * the terms of the GNU Lesser General Public Licence as published
12
 * by the Free Software Foundation.
13
 * See the COPYING file for more information.
14
 *
15
 **********************************************************************
16
 *
17
 * Last port: geomgraph/EdgeIntersectionList.java r428 (JTS-1.12+)
18
 *
19
 **********************************************************************/
20
21
22
#pragma once
23
24
#include <geos/export.h>
25
#include <algorithm>
26
#include <vector>
27
#include <string>
28
29
#include <geos/geomgraph/EdgeIntersection.h> // for EdgeIntersectionLessThen
30
#include <geos/geom/Coordinate.h> // for CoordinateLessThan
31
32
#ifdef _MSC_VER
33
#pragma warning(push)
34
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35
#endif
36
37
// Forward declarations
38
namespace geos {
39
namespace geom {
40
class Coordinate;
41
}
42
namespace geomgraph {
43
class Edge;
44
}
45
}
46
47
namespace geos {
48
namespace geomgraph { // geos.geomgraph
49
50
51
/** \brief
52
 * A list of edge intersections along an Edge.
53
 *
54
 * Implements splitting an edge with intersections
55
 * into multiple resultant edges.
56
 */
57
class GEOS_DLL EdgeIntersectionList final {
58
public:
59
    // Instead of storing edge intersections in a set, as JTS does, we store them
60
    // in a vector and then sort the vector if needed before iterating among the
61
    // edges. This is much faster.
62
    using container = std::vector<EdgeIntersection>;
63
    using const_iterator = container::const_iterator;
64
65
private:
66
    mutable container nodeMap;
67
    mutable bool sorted;
68
69
public:
70
71
    const Edge* edge;
72
    EdgeIntersectionList(const Edge* edge);
73
0
    ~EdgeIntersectionList() = default;
74
75
    /*
76
     * Adds an intersection into the list, if it isn't already there.
77
     * The input segmentIndex and dist are expected to be normalized.
78
     * @return the EdgeIntersection found or added
79
     */
80
    void add(const geom::Coordinate& coord, std::size_t segmentIndex, double dist);
81
82
    const_iterator
83
    begin() const
84
0
    {
85
0
        if (!sorted) {
86
0
            std::sort(nodeMap.begin(), nodeMap.end());
87
0
            nodeMap.erase(std::unique(nodeMap.begin(), nodeMap.end()), nodeMap.end());
88
0
            sorted = true;
89
0
        }
90
91
0
        return nodeMap.begin();
92
0
    }
93
    const_iterator
94
    end() const
95
0
    {
96
0
        return nodeMap.end();
97
0
    }
98
99
    bool isEmpty() const;
100
    bool isIntersection(const geom::Coordinate& pt) const;
101
102
    /*
103
     * Adds entries for the first and last points of the edge to the list
104
     */
105
    void addEndpoints();
106
107
    /**
108
     * Creates new edges for all the edges that the intersections in this
109
     * list split the parent edge into.
110
     * Adds the edges to the input list (this is so a single list
111
     * can be used to accumulate all split edges for a Geometry).
112
     *
113
     * @param edgeList a list of EdgeIntersections
114
     */
115
    void addSplitEdges(std::vector<Edge*>* edgeList);
116
117
    Edge* createSplitEdge(const EdgeIntersection* ei0, const EdgeIntersection* ei1);
118
    std::string print() const;
119
};
120
121
std::ostream& operator<< (std::ostream&, const EdgeIntersectionList&);
122
123
} // namespace geos.geomgraph
124
} // namespace geos
125
126
#ifdef _MSC_VER
127
#pragma warning(pop)
128
#endif
129