GEOS 3.13.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 LinearRing;
31}
32}
33
34namespace geos { // geos.
35namespace operation { // geos.operation
36namespace valid { // geos.operation.valid
37
38using geos::geom::CoordinateXY;
40
41
42class GEOS_DLL PolygonRing {
43
44private:
45
46 int id = -1;
47 PolygonRing* shell = nullptr;
48 const LinearRing* ring = nullptr;
49
54 PolygonRing* touchSetRoot = nullptr;
55
68 std::map<int, PolygonRingTouch> touches;
69
74 std::vector<PolygonRingSelfNode> selfNodes;
75
76 /* METHODS */
77
86 bool isOnlyTouch(const PolygonRing* polyRing, const CoordinateXY& pt) const;
87
96 const CoordinateXY* findHoleCycleLocation();
97
98 void init(PolygonRing* root, std::stack<PolygonRingTouch*>& touchStack);
99
108 const CoordinateXY* scanForHoleCycle(PolygonRingTouch* currentTouch,
109 PolygonRing* root,
110 std::stack<PolygonRingTouch*>& touchStack);
111
112
113 bool isInTouchSet() const
114 {
115 return touchSetRoot != nullptr;
116 };
117
118 void setTouchSetRoot(PolygonRing* polyRing)
119 {
120 touchSetRoot = polyRing;
121 };
122
123 PolygonRing* getTouchSetRoot() const
124 {
125 return touchSetRoot;
126 };
127
128 bool hasTouches() const
129 {
130 return ! touches.empty();
131 };
132
133 std::vector<PolygonRingTouch*> getTouches() const;
134
135 void addTouch(PolygonRing* polyRing, const CoordinateXY& pt);
136
137
138public:
139
146 PolygonRing(const LinearRing* p_ring, int p_index, PolygonRing* p_shell)
147 : id(p_index)
148 , shell(p_shell)
149 , ring(p_ring)
150 {};
151
156 PolygonRing(const LinearRing* p_ring)
157 : PolygonRing(p_ring, -1, this)
158 {};
159
166 static bool isShell(const PolygonRing* polyRing);
167
177 static bool addTouch(PolygonRing* ring0, PolygonRing* ring1, const CoordinateXY& pt);
178
188 static const CoordinateXY* findHoleCycleLocation(std::vector<PolygonRing*> polyRings);
189
199 static const CoordinateXY* findInteriorSelfNode(std::vector<PolygonRing*> polyRings);
200
201 bool isSamePolygon(const PolygonRing* polyRing) const
202 {
203 return shell == polyRing->shell;
204 };
205
206 bool isShell() const
207 {
208 return shell == this;
209 };
210
211 void addSelfTouch(const CoordinateXY& origin,
212 const CoordinateXY* e00, const CoordinateXY* e01,
213 const CoordinateXY* e10, const CoordinateXY* e11);
214
221 const CoordinateXY* findInteriorSelfNode();
222
223
224};
225
226
227
228} // namespace geos.operation.valid
229} // namespace geos.operation
230} // namespace geos
231
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Basic namespace for all GEOS functionalities.
Definition geos.h:39