GEOS 3.14.0dev
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
38class GEOS_DLL PolygonRing {
39 using CoordinateXY = geos::geom::CoordinateXY;
40 using LinearRing = geos::geom::LinearRing;
41
42private:
43
44 int id = -1;
45 PolygonRing* shell = nullptr;
46 const LinearRing* ring = nullptr;
47
52 PolygonRing* touchSetRoot = nullptr;
53
66 std::map<int, PolygonRingTouch> touches;
67
72 std::vector<PolygonRingSelfNode> selfNodes;
73
74 /* METHODS */
75
84 bool isOnlyTouch(const PolygonRing* polyRing, const CoordinateXY& pt) const;
85
94 const CoordinateXY* findHoleCycleLocation();
95
96 void init(PolygonRing* root, std::stack<PolygonRingTouch*>& touchStack);
97
106 const CoordinateXY* scanForHoleCycle(PolygonRingTouch* currentTouch,
107 PolygonRing* root,
108 std::stack<PolygonRingTouch*>& touchStack);
109
110
111 bool isInTouchSet() const
112 {
113 return touchSetRoot != nullptr;
114 };
115
116 void setTouchSetRoot(PolygonRing* polyRing)
117 {
118 touchSetRoot = polyRing;
119 };
120
121 PolygonRing* getTouchSetRoot() const
122 {
123 return touchSetRoot;
124 };
125
126 bool hasTouches() const
127 {
128 return ! touches.empty();
129 };
130
131 std::vector<PolygonRingTouch*> getTouches() const;
132
133 void addTouch(PolygonRing* polyRing, const CoordinateXY& pt);
134
135
136public:
137
144 PolygonRing(const LinearRing* p_ring, int p_index, PolygonRing* p_shell)
145 : id(p_index)
146 , shell(p_shell)
147 , ring(p_ring)
148 {};
149
154 PolygonRing(const LinearRing* p_ring)
155 : PolygonRing(p_ring, -1, this)
156 {};
157
164 static bool isShell(const PolygonRing* polyRing);
165
175 static bool addTouch(PolygonRing* ring0, PolygonRing* ring1, const CoordinateXY& pt);
176
186 static const CoordinateXY* findHoleCycleLocation(std::vector<PolygonRing*> polyRings);
187
197 static const CoordinateXY* findInteriorSelfNode(std::vector<PolygonRing*> polyRings);
198
199 bool isSamePolygon(const PolygonRing* polyRing) const
200 {
201 return shell == polyRing->shell;
202 };
203
204 bool isShell() const
205 {
206 return shell == this;
207 };
208
209 void addSelfTouch(const CoordinateXY& origin,
210 const CoordinateXY* e00, const CoordinateXY* e01,
211 const CoordinateXY* e10, const CoordinateXY* e11);
212
219 const CoordinateXY* findInteriorSelfNode();
220
221
222};
223
224
225
226} // namespace geos.operation.valid
227} // namespace geos.operation
228} // namespace geos
229
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