GEOS 3.11.1
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;
31}
32namespace operation {
33namespace overlayng {
34class OverlayEdgeRing;
35class MaximalEdgeRing;
36}
37}
38}
39
44
45namespace geos { // geos.
46namespace operation { // geos.operation
47namespace overlayng { // geos.operation.overlayng
48
52class GEOS_DLL OverlayEdge : public edgegraph::HalfEdge {
53
54private:
55
56 // Members
57 const CoordinateSequence* pts;
63 bool direction;
64 Coordinate 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 // takes ownershiph of CoordinateSequence
83 OverlayEdge(const Coordinate& p_orig, const Coordinate& p_dirPt,
84 bool p_direction, OverlayLabel* p_label,
85 const CoordinateSequence* p_pts)
86 : HalfEdge(p_orig)
87 , pts(p_pts)
88 , direction(p_direction)
89 , dirPt(p_dirPt)
90 , label(p_label)
91 , m_isInResultArea(false)
92 , m_isInResultLine(false)
93 , m_isVisited(false)
94 , nextResultEdge(nullptr)
95 , edgeRing(nullptr)
96 , maxEdgeRing(nullptr)
97 , nextResultMaxEdge(nullptr)
98 {}
99
100 ~OverlayEdge() override {};
101
102 bool isForward() const
103 {
104 return direction;
105 };
106
107 const Coordinate& directionPt() const override
108 {
109 return dirPt;
110 };
111
112 OverlayLabel* getLabel() const
113 {
114 return label;
115 };
116
117 Location getLocation(uint8_t index, int position) const
118 {
119 return label->getLocation(index, position, direction);
120 };
121
122 const Coordinate& getCoordinate() const
123 {
124 return orig();
125 };
126
127 const CoordinateSequence* getCoordinatesRO() const
128 {
129 return pts;
130 };
131
132 std::unique_ptr<CoordinateSequence> getCoordinates()
133 {
134 // return a copy of pts
135 return pts->clone();
136 };
137
138 std::unique_ptr<CoordinateSequence> getCoordinatesOriented();
139
150
151 OverlayEdge* symOE() const
152 {
153 return static_cast<OverlayEdge*>(sym());
154 };
155
156 OverlayEdge* oNextOE() const
157 {
158 return static_cast<OverlayEdge*>(oNext());
159 };
160
161 bool isInResultArea() const
162 {
163 return m_isInResultArea;
164 };
165
166 bool isInResultAreaBoth() const
167 {
168 return m_isInResultArea && symOE()->m_isInResultArea;
169 };
170
171 bool isInResultEither() const
172 {
173 return isInResult() || symOE()->isInResult();
174 };
175
176 void unmarkFromResultAreaBoth()
177 {
178 m_isInResultArea = false;
179 symOE()->m_isInResultArea = false;
180 };
181
182 void markInResultArea()
183 {
184 m_isInResultArea = true;
185 };
186
187 void markInResultAreaBoth()
188 {
189 m_isInResultArea = true;
190 symOE()->m_isInResultArea = true;
191 };
192
193 bool isInResultLine() const
194 {
195 return m_isInResultLine;
196 };
197
198 void markInResultLine()
199 {
200 m_isInResultLine = true;
201 symOE()->m_isInResultLine = true;
202 };
203
204 bool isInResult() const
205 {
206 return m_isInResultArea || m_isInResultLine;
207 };
208
209 void setNextResult(OverlayEdge* e)
210 {
211 // Assert: e.orig() == this.dest();
212 nextResultEdge = e;
213 };
214
215 OverlayEdge* nextResult() const
216 {
217 return nextResultEdge;
218 };
219
220 bool isResultLinked() const
221 {
222 return nextResultEdge != nullptr;
223 };
224
225 void setNextResultMax(OverlayEdge* e)
226 {
227 // Assert: e.orig() == this.dest();
228 nextResultMaxEdge = e;
229 };
230
231 OverlayEdge* nextResultMax() const
232 {
233 return nextResultMaxEdge;
234 };
235
236 bool isResultMaxLinked() const
237 {
238 return nextResultMaxEdge != nullptr;
239 };
240
241 bool isVisited() const
242 {
243 return m_isVisited;
244 };
245
246 void markVisitedBoth()
247 {
248 markVisited();
249 symOE()->markVisited();
250 };
251
252 void setEdgeRing(const OverlayEdgeRing* p_edgeRing)
253 {
254 edgeRing = p_edgeRing;
255 };
256
257 const OverlayEdgeRing* getEdgeRing() const
258 {
259 return edgeRing;
260 };
261
262 const MaximalEdgeRing* getEdgeRingMax() const
263 {
264 return maxEdgeRing;
265 };
266
267 void setEdgeRingMax(const MaximalEdgeRing* p_maximalEdgeRing)
268 {
269 maxEdgeRing = p_maximalEdgeRing;
270 };
271
272 friend std::ostream& operator<<(std::ostream& os, const OverlayEdge& oe);
273 std::string resultSymbol() const;
274
275};
276
277
278} // namespace geos.operation.overlayng
279} // namespace geos.operation
280} // namespace geos
Definition: HalfEdge.h:63
The default implementation of CoordinateSequence.
Definition: CoordinateArraySequence.h:35
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
virtual std::unique_ptr< CoordinateSequence > clone() const =0
Returns a deep copy of this collection.
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Definition: OverlayEdge.h:52
const Coordinate & directionPt() const override
Definition: OverlayEdge.h:107
void addCoordinates(CoordinateArraySequence *coords) const
Definition: OverlayLabel.h:87
Location getLocation(uint8_t index) const
Definition: OverlayLabel.h:369
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:39