GEOS 3.16.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 <map>
25
26// Forward declarations
27namespace geos {
28namespace geom {
29class LinearRing;
30}
31}
32
33namespace geos { // geos.
34namespace operation { // geos.operation
35namespace valid { // geos.operation.valid
36
37class GEOS_DLL PolygonRing {
38 using CoordinateXY = geos::geom::CoordinateXY;
39 using LinearRing = geos::geom::LinearRing;
40
41private:
42
43 int id = -1;
44 PolygonRing* shell = nullptr;
45 const LinearRing* ring = nullptr;
46
51 PolygonRing* touchSetRoot = nullptr;
52
65 std::map<int, PolygonRingTouch> touches;
66
71 std::vector<PolygonRingSelfNode> selfNodes;
72
73 /* METHODS */
74
83 bool isOnlyTouch(const PolygonRing* polyRing, const CoordinateXY& pt) const;
84
93 const CoordinateXY* findHoleCycleLocation();
94
95 static void init(PolygonRing* root, std::stack<PolygonRingTouch*>& touchStack);
96
105 static const CoordinateXY* scanForHoleCycle(const PolygonRingTouch* currentTouch,
106 PolygonRing* root,
107 std::stack<PolygonRingTouch*>& touchStack);
108
109
110 bool isInTouchSet() const
111 {
112 return touchSetRoot != nullptr;
113 };
114
115 void setTouchSetRoot(PolygonRing* polyRing)
116 {
117 touchSetRoot = polyRing;
118 };
119
120 PolygonRing* getTouchSetRoot() const
121 {
122 return touchSetRoot;
123 };
124
125 bool hasTouches() const
126 {
127 return ! touches.empty();
128 };
129
130 std::vector<PolygonRingTouch*> getTouches() const;
131
132 void addTouch(PolygonRing* polyRing, const CoordinateXY& pt);
133
134
135public:
136
143 PolygonRing(const LinearRing* p_ring, int p_index, PolygonRing* p_shell)
144 : id(p_index)
145 , shell(p_shell)
146 , ring(p_ring)
147 {};
148
153 PolygonRing(const LinearRing* p_ring)
154 : PolygonRing(p_ring, -1, this)
155 {};
156
163 static bool isShell(const PolygonRing* polyRing);
164
174 static bool addTouch(PolygonRing* ring0, PolygonRing* ring1, const CoordinateXY& pt);
175
185 static const CoordinateXY* findHoleCycleLocation(const std::vector<PolygonRing*>& polyRings);
186
196 static const CoordinateXY* findInteriorSelfNode(const std::vector<PolygonRing*>& polyRings);
197
198 bool isSamePolygon(const PolygonRing* polyRing) const
199 {
200 return shell == polyRing->shell;
201 };
202
203 bool isShell() const
204 {
205 return shell == this;
206 };
207
208 void addSelfTouch(const CoordinateXY& origin,
209 const CoordinateXY* e00, const CoordinateXY* e01,
210 const CoordinateXY* e10, const CoordinateXY* e11);
211
218 const CoordinateXY* findInteriorSelfNode() const;
219
220
221};
222
223
224
225} // namespace geos.operation.valid
226} // namespace geos.operation
227} // namespace geos
228
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:38