GEOS  3.13.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
27 namespace geos {
28 namespace geom {
29 class Coordinate;
30 class CoordinateSequence;
31 }
32 namespace operation {
33 namespace overlayng {
34 class OverlayEdgeRing;
35 class MaximalEdgeRing;
36 }
37 }
38 }
39 
41 using geos::geom::CoordinateXYZM;
44 
45 namespace geos { // geos.
46 namespace operation { // geos.operation
47 namespace overlayng { // geos.operation.overlayng
48 
52 class GEOS_DLL OverlayEdge : public edgegraph::HalfEdge {
53 
54 private:
55 
56  // Members
57  const CoordinateSequence* pts;
63  bool direction;
64  CoordinateXYZM 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 
80 public:
81 
82  OverlayEdge(const CoordinateXYZM& p_orig, const CoordinateXYZM& p_dirPt,
83  bool p_direction, OverlayLabel* p_label,
84  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 CoordinateXYZM& 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;
129  };
130 
131  std::unique_ptr<CoordinateSequence> getCoordinates()
132  {
133  // return a copy of pts
134  return pts->clone();
135  };
136 
137  std::unique_ptr<CoordinateSequence> getCoordinatesOriented();
138 
148  void addCoordinates(CoordinateSequence* coords) const;
149 
150  OverlayEdge* symOE() const
151  {
152  return static_cast<OverlayEdge*>(sym());
153  };
154 
155  OverlayEdge* oNextOE() const
156  {
157  return static_cast<OverlayEdge*>(oNext());
158  };
159 
160  bool isInResultArea() const
161  {
162  return m_isInResultArea;
163  };
164 
165  bool isInResultAreaBoth() const
166  {
167  return m_isInResultArea && symOE()->m_isInResultArea;
168  };
169 
170  bool isInResultEither() const
171  {
172  return isInResult() || symOE()->isInResult();
173  };
174 
175  void unmarkFromResultAreaBoth()
176  {
177  m_isInResultArea = false;
178  symOE()->m_isInResultArea = false;
179  };
180 
181  void markInResultArea()
182  {
183  m_isInResultArea = true;
184  };
185 
186  void markInResultAreaBoth()
187  {
188  m_isInResultArea = true;
189  symOE()->m_isInResultArea = true;
190  };
191 
192  bool isInResultLine() const
193  {
194  return m_isInResultLine;
195  };
196 
197  void markInResultLine()
198  {
199  m_isInResultLine = true;
200  symOE()->m_isInResultLine = true;
201  };
202 
203  bool isInResult() const
204  {
205  return m_isInResultArea || m_isInResultLine;
206  };
207 
208  void setNextResult(OverlayEdge* e)
209  {
210  // Assert: e.orig() == this.dest();
211  nextResultEdge = e;
212  };
213 
214  OverlayEdge* nextResult() const
215  {
216  return nextResultEdge;
217  };
218 
219  bool isResultLinked() const
220  {
221  return nextResultEdge != nullptr;
222  };
223 
224  void setNextResultMax(OverlayEdge* e)
225  {
226  // Assert: e.orig() == this.dest();
227  nextResultMaxEdge = e;
228  };
229 
230  OverlayEdge* nextResultMax() const
231  {
232  return nextResultMaxEdge;
233  };
234 
235  bool isResultMaxLinked() const
236  {
237  return nextResultMaxEdge != nullptr;
238  };
239 
240  bool isVisited() const
241  {
242  return m_isVisited;
243  };
244 
245  void markVisitedBoth()
246  {
247  markVisited();
248  symOE()->markVisited();
249  };
250 
251  void setEdgeRing(const OverlayEdgeRing* p_edgeRing)
252  {
253  edgeRing = p_edgeRing;
254  };
255 
256  const OverlayEdgeRing* getEdgeRing() const
257  {
258  return edgeRing;
259  };
260 
261  const MaximalEdgeRing* getEdgeRingMax() const
262  {
263  return maxEdgeRing;
264  };
265 
266  void setEdgeRingMax(const MaximalEdgeRing* p_maximalEdgeRing)
267  {
268  maxEdgeRing = p_maximalEdgeRing;
269  };
270 
271  friend std::ostream& operator<<(std::ostream& os, const OverlayEdge& oe);
272  std::string resultSymbol() const;
273 
274 };
275 
276 
277 } // namespace geos.operation.overlayng
278 } // namespace geos.operation
279 } // 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:216
Definition: OverlayEdge.h:52
const CoordinateXYZM & directionPt() const override
Definition: OverlayEdge.h:106
void addCoordinates(CoordinateSequence *coords) const
Definition: OverlayLabel.h:89
Location getLocation(uint8_t index) const
Definition: OverlayLabel.h:371
std::unique_ptr< CoordinateSequence > clone() const
Returns a heap-allocated deep copy of this CoordinateSequence.
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:32
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25