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 CoordinateXYZM = geos::geom::CoordinateXYZM;
52
53private:
54
55 // Members
56 std::shared_ptr<const CoordinateSequence> pts;
62 bool direction;
63 CoordinateXYZM dirPt;
64 OverlayLabel* label;
65 bool m_isInResultArea;
66 bool m_isInResultLine;
67 bool m_isVisited;
68 OverlayEdge* nextResultEdge;
69 const OverlayEdgeRing* edgeRing;
70 const MaximalEdgeRing* maxEdgeRing;
71 OverlayEdge* nextResultMaxEdge;
72
73 void markVisited()
74 {
75 m_isVisited = true;
76 };
77
78
79public:
80
81 OverlayEdge(const CoordinateXYZM& p_orig, const CoordinateXYZM& p_dirPt,
82 bool p_direction, OverlayLabel* p_label,
83 const std::shared_ptr<const CoordinateSequence>& p_pts)
84 : HalfEdge(p_orig)
85 , pts(p_pts)
86 , direction(p_direction)
87 , dirPt(p_dirPt)
88 , label(p_label)
89 , m_isInResultArea(false)
90 , m_isInResultLine(false)
91 , m_isVisited(false)
92 , nextResultEdge(nullptr)
93 , edgeRing(nullptr)
94 , maxEdgeRing(nullptr)
95 , nextResultMaxEdge(nullptr)
96 {}
97
98 ~OverlayEdge() override {};
99
100 bool isForward() const
101 {
102 return direction;
103 };
104
105 const CoordinateXYZM& directionPt() const override
106 {
107 return dirPt;
108 };
109
110 OverlayLabel* getLabel() const
111 {
112 return label;
113 };
114
115 Location getLocation(uint8_t index, int position) const
116 {
117 return label->getLocation(index, position, direction);
118 };
119
120 const CoordinateXYZM& getCoordinate() const
121 {
122 return orig();
123 };
124
125 const CoordinateSequence* getCoordinatesRO() const
126 {
127 return pts.get();
128 };
129
130 std::shared_ptr<const CoordinateSequence> getCoordinatesOriented() const;
131
142
143 OverlayEdge* symOE() const
144 {
145 return static_cast<OverlayEdge*>(sym());
146 };
147
148 OverlayEdge* oNextOE() const
149 {
150 return static_cast<OverlayEdge*>(oNext());
151 };
152
153 bool isInResultArea() const
154 {
155 return m_isInResultArea;
156 };
157
158 bool isInResultAreaBoth() const
159 {
160 return m_isInResultArea && symOE()->m_isInResultArea;
161 };
162
163 bool isInResultEither() const
164 {
165 return isInResult() || symOE()->isInResult();
166 };
167
168 void unmarkFromResultAreaBoth()
169 {
170 m_isInResultArea = false;
171 symOE()->m_isInResultArea = false;
172 };
173
174 void markInResultArea()
175 {
176 m_isInResultArea = true;
177 };
178
179 void markInResultAreaBoth()
180 {
181 m_isInResultArea = true;
182 symOE()->m_isInResultArea = true;
183 };
184
185 bool isInResultLine() const
186 {
187 return m_isInResultLine;
188 };
189
190 void markInResultLine()
191 {
192 m_isInResultLine = true;
193 symOE()->m_isInResultLine = true;
194 };
195
196 bool isInResult() const
197 {
198 return m_isInResultArea || m_isInResultLine;
199 };
200
201 void setNextResult(OverlayEdge* e)
202 {
203 // Assert: e.orig() == this.dest();
204 nextResultEdge = e;
205 };
206
207 OverlayEdge* nextResult() const
208 {
209 return nextResultEdge;
210 };
211
212 bool isResultLinked() const
213 {
214 return nextResultEdge != nullptr;
215 };
216
217 void setNextResultMax(OverlayEdge* e)
218 {
219 // Assert: e.orig() == this.dest();
220 nextResultMaxEdge = e;
221 };
222
223 OverlayEdge* nextResultMax() const
224 {
225 return nextResultMaxEdge;
226 };
227
228 bool isResultMaxLinked() const
229 {
230 return nextResultMaxEdge != nullptr;
231 };
232
233 bool isVisited() const
234 {
235 return m_isVisited;
236 };
237
238 void markVisitedBoth()
239 {
240 markVisited();
241 symOE()->markVisited();
242 };
243
244 void setEdgeRing(const OverlayEdgeRing* p_edgeRing)
245 {
246 edgeRing = p_edgeRing;
247 };
248
249 const OverlayEdgeRing* getEdgeRing() const
250 {
251 return edgeRing;
252 };
253
254 const MaximalEdgeRing* getEdgeRingMax() const
255 {
256 return maxEdgeRing;
257 };
258
259 void setEdgeRingMax(const MaximalEdgeRing* p_maximalEdgeRing)
260 {
261 maxEdgeRing = p_maximalEdgeRing;
262 };
263
264 friend std::ostream& operator<<(std::ostream& os, const OverlayEdge& oe);
265 std::string resultSymbol() const;
266
267};
268
269
270} // namespace geos.operation.overlayng
271} // namespace geos.operation
272} // 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:217
Definition OverlayEdge.h:47
const CoordinateXYZM & directionPt() const override
Definition OverlayEdge.h:105
void addCoordinates(CoordinateSequence *coords) const
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