GEOS 3.11.1
PolygonRing.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
7 * Copyright (C) 2021 Martin Davis
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************/
15
16#pragma once
17
18#include <geos/operation/valid/PolygonRingTouch.h>
19#include <geos/operation/valid/PolygonRingSelfNode.h>
20
21#include <geos/export.h>
22
23
24#include <memory>
25#include <map>
26
27// Forward declarations
28namespace geos {
29namespace geom {
30class Coordinate;
31class LinearRing;
32}
33}
34
35namespace geos { // geos.
36namespace operation { // geos.operation
37namespace valid { // geos.operation.valid
38
41
42
43class GEOS_DLL PolygonRing {
44
45private:
46
47 int id = -1;
48 PolygonRing* shell = nullptr;
49 const LinearRing* ring = nullptr;
50
55 PolygonRing* touchSetRoot = nullptr;
56
69 std::map<int, PolygonRingTouch> touches;
70
75 std::vector<PolygonRingSelfNode> selfNodes;
76
77 /* METHODS */
78
87 bool isOnlyTouch(const PolygonRing* polyRing, const Coordinate& pt) const;
88
97 const Coordinate* findHoleCycleLocation();
98
99 void init(PolygonRing* root, std::stack<PolygonRingTouch*>& touchStack);
100
109 const Coordinate* scanForHoleCycle(PolygonRingTouch* currentTouch,
110 PolygonRing* root,
111 std::stack<PolygonRingTouch*>& touchStack);
112
113
114 bool isInTouchSet() const
115 {
116 return touchSetRoot != nullptr;
117 };
118
119 void setTouchSetRoot(PolygonRing* polyRing)
120 {
121 touchSetRoot = polyRing;
122 };
123
124 PolygonRing* getTouchSetRoot() const
125 {
126 return touchSetRoot;
127 };
128
129 bool hasTouches() const
130 {
131 return ! touches.empty();
132 };
133
134 std::vector<PolygonRingTouch*> getTouches() const;
135
136 void addTouch(PolygonRing* polyRing, const Coordinate& pt);
137
138
139public:
140
147 PolygonRing(const LinearRing* p_ring, int p_index, PolygonRing* p_shell)
148 : id(p_index)
149 , shell(p_shell)
150 , ring(p_ring)
151 {};
152
157 PolygonRing(const LinearRing* p_ring)
158 : PolygonRing(p_ring, -1, this)
159 {};
160
167 static bool isShell(const PolygonRing* polyRing);
168
178 static bool addTouch(PolygonRing* ring0, PolygonRing* ring1, const Coordinate& pt);
179
189 static const Coordinate* findHoleCycleLocation(std::vector<PolygonRing*> polyRings);
190
200 static const Coordinate* findInteriorSelfNode(std::vector<PolygonRing*> polyRings);
201
202 bool isSamePolygon(const PolygonRing* polyRing) const
203 {
204 return shell == polyRing->shell;
205 };
206
207 bool isShell() const
208 {
209 return shell == this;
210 };
211
212 void addSelfTouch(const Coordinate& origin,
213 const Coordinate* e00, const Coordinate* e01,
214 const Coordinate* e10, const Coordinate* e11);
215
222 const Coordinate* findInteriorSelfNode();
223
224
225};
226
227
228
229} // namespace geos.operation.valid
230} // namespace geos.operation
231} // namespace geos
232
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Basic namespace for all GEOS functionalities.
Definition: geos.h:39