GEOS 3.14.0dev
EdgeIntersectionList.h
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
38namespace geos {
39namespace geom {
40class Coordinate;
41}
42namespace geomgraph {
43class Edge;
44}
45}
46
47namespace geos {
48namespace geomgraph { // geos.geomgraph
49
50
57class GEOS_DLL EdgeIntersectionList final {
58public:
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
65private:
66 mutable container nodeMap;
67 mutable bool sorted;
68
69public:
70
71 const Edge* edge;
72 EdgeIntersectionList(const Edge* edge);
73 ~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 {
85 if (!sorted) {
86 std::sort(nodeMap.begin(), nodeMap.end());
87 nodeMap.erase(std::unique(nodeMap.begin(), nodeMap.end()), nodeMap.end());
88 sorted = true;
89 }
90
91 return nodeMap.begin();
92 }
93 const_iterator
94 end() const
95 {
96 return nodeMap.end();
97 }
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
115 void addSplitEdges(std::vector<Edge*>* edgeList);
116
117 Edge* createSplitEdge(const EdgeIntersection* ei0, const EdgeIntersection* ei1);
118 std::string print() const;
119};
120
121std::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
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
A list of edge intersections along an Edge.
Definition EdgeIntersectionList.h:57
void addSplitEdges(std::vector< Edge * > *edgeList)
Represents a point on an edge which intersects with another edge.
Definition EdgeIntersection.h:42
Definition geomgraph/Edge.h:63
Basic namespace for all GEOS functionalities.
Definition geos.h:39