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