GEOS 3.15.0dev
OverlayEdge.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/edgegraph/HalfEdge.h>
18#include <geos/geom/CoordinateSequence.h>
19#include <geos/geom/Location.h>
20#include <geos/operation/overlayng/OverlayEdge.h>
21#include <geos/operation/overlayng/OverlayLabel.h>
22#include <geos/export.h>
23
24#include <memory>
25
26// Forward declarations
27namespace geos {
28namespace geom {
29class Coordinate;
30class CoordinateSequence;
31}
32namespace operation {
33namespace overlayng {
34class OverlayEdgeRing;
35class MaximalEdgeRing;
36}
37}
38}
39
40namespace geos { // geos.
41namespace operation { // geos.operation
42namespace overlayng { // geos.operation.overlayng
43
47class GEOS_DLL OverlayEdge : public edgegraph::HalfEdge {
49 using CoordinateXY = geos::geom::CoordinateXY;
50 using CoordinateXYZM = geos::geom::CoordinateXYZM;
53
54private:
55
56 // Members
57 std::shared_ptr<const CoordinateSequence> pts;
63 bool direction;
64 CoordinateXY dirPt;
65 OverlayLabel* label;
66 bool m_isInResultArea;
67 bool m_isInResultLine;
68 bool m_isVisited;
69 OverlayEdge* nextResultEdge;
70 const OverlayEdgeRing* edgeRing;
71 const MaximalEdgeRing* maxEdgeRing;
72 OverlayEdge* nextResultMaxEdge;
73
74 void markVisited()
75 {
76 m_isVisited = true;
77 };
78
79
80public:
81
82 OverlayEdge(const CoordinateXYZM& p_orig, const CoordinateXY& p_dirPt,
83 bool p_direction, OverlayLabel* p_label,
84 const std::shared_ptr<const CoordinateSequence>& p_pts)
85 : HalfEdge(p_orig)
86 , pts(p_pts)
87 , direction(p_direction)
88 , dirPt(p_dirPt)
89 , label(p_label)
90 , m_isInResultArea(false)
91 , m_isInResultLine(false)
92 , m_isVisited(false)
93 , nextResultEdge(nullptr)
94 , edgeRing(nullptr)
95 , maxEdgeRing(nullptr)
96 , nextResultMaxEdge(nullptr)
97 {}
98
99 ~OverlayEdge() override {};
100
101 bool isForward() const
102 {
103 return direction;
104 };
105
106 const CoordinateXY& directionPt() const override
107 {
108 return dirPt;
109 };
110
111 OverlayLabel* getLabel() const
112 {
113 return label;
114 };
115
116 Location getLocation(uint8_t index, int position) const
117 {
118 return label->getLocation(index, position, direction);
119 };
120
121 const CoordinateXYZM& getCoordinate() const
122 {
123 return orig();
124 };
125
126 const CoordinateSequence* getCoordinatesRO() const
127 {
128 return pts.get();
129 };
130
131 std::shared_ptr<const CoordinateSequence> getCoordinatesOriented() const;
132
143
144 OverlayEdge* symOE() const
145 {
146 return static_cast<OverlayEdge*>(sym());
147 };
148
149 OverlayEdge* oNextOE() const
150 {
151 return static_cast<OverlayEdge*>(oNext());
152 };
153
154 bool isInResultArea() const
155 {
156 return m_isInResultArea;
157 };
158
159 bool isInResultAreaBoth() const
160 {
161 return m_isInResultArea && symOE()->m_isInResultArea;
162 };
163
164 bool isInResultEither() const
165 {
166 return isInResult() || symOE()->isInResult();
167 };
168
169 void unmarkFromResultAreaBoth()
170 {
171 m_isInResultArea = false;
172 symOE()->m_isInResultArea = false;
173 };
174
175 void markInResultArea()
176 {
177 m_isInResultArea = true;
178 };
179
180 void markInResultAreaBoth()
181 {
182 m_isInResultArea = true;
183 symOE()->m_isInResultArea = true;
184 };
185
186 bool isInResultLine() const
187 {
188 return m_isInResultLine;
189 };
190
191 void markInResultLine()
192 {
193 m_isInResultLine = true;
194 symOE()->m_isInResultLine = true;
195 };
196
197 bool isInResult() const
198 {
199 return m_isInResultArea || m_isInResultLine;
200 };
201
202 void setNextResult(OverlayEdge* e)
203 {
204 // Assert: e.orig() == this.dest();
205 nextResultEdge = e;
206 };
207
208 OverlayEdge* nextResult() const
209 {
210 return nextResultEdge;
211 };
212
213 bool isResultLinked() const
214 {
215 return nextResultEdge != nullptr;
216 };
217
218 void setNextResultMax(OverlayEdge* e)
219 {
220 // Assert: e.orig() == this.dest();
221 nextResultMaxEdge = e;
222 };
223
224 OverlayEdge* nextResultMax() const
225 {
226 return nextResultMaxEdge;
227 };
228
229 bool isResultMaxLinked() const
230 {
231 return nextResultMaxEdge != nullptr;
232 };
233
234 bool isVisited() const
235 {
236 return m_isVisited;
237 };
238
239 void markVisitedBoth()
240 {
241 markVisited();
242 symOE()->markVisited();
243 };
244
245 void setEdgeRing(const OverlayEdgeRing* p_edgeRing)
246 {
247 edgeRing = p_edgeRing;
248 };
249
250 const OverlayEdgeRing* getEdgeRing() const
251 {
252 return edgeRing;
253 };
254
255 const MaximalEdgeRing* getEdgeRingMax() const
256 {
257 return maxEdgeRing;
258 };
259
260 void setEdgeRingMax(const MaximalEdgeRing* p_maximalEdgeRing)
261 {
262 maxEdgeRing = p_maximalEdgeRing;
263 };
264
265 friend std::ostream& operator<<(std::ostream& os, const OverlayEdge& oe);
266 std::string resultSymbol() const;
267
268};
269
270
271} // namespace geos.operation.overlayng
272} // namespace geos.operation
273} // namespace geos
Definition HalfEdge.h:56
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
Definition OverlayEdge.h:47
void addCoordinates(CoordinateSequence *coords) const
const CoordinateXY & directionPt() const override
Definition OverlayEdge.h:106
Definition OverlayLabel.h:86
Location getLocation(uint8_t index) const
Definition OverlayLabel.h:370
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
Basic namespace for all GEOS functionalities.
Definition geos.h:38