GEOS 3.14.0dev
PolygonHoleJoiner.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2023 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/geom/Coordinate.h>
18#include <geos/geom/CoordinateSequence.h>
19#include <geos/algorithm/LineIntersector.h>
20#include <geos/noding/SegmentIntersector.h>
21#include <geos/noding/BasicSegmentString.h>
22#include <geos/noding/SegmentSetMutualIntersector.h>
23#include <geos/constants.h>
24
25#include <set>
26#include <limits>
27
28// Forward declarations
29namespace geos {
30namespace geom {
31class Envelope;
32class Geometry;
33class LinearRing;
34class Polygon;
35}
36namespace noding {
37}
38}
39
40namespace geos {
41namespace triangulate {
42namespace polygon {
43
44
45
62class GEOS_DLL PolygonHoleJoiner {
69
70private:
71
72 // Members
73
74 const Polygon* inputPolygon;
75
76 //-- normalized, sorted and noded polygon rings
77 std::unique_ptr<CoordinateSequence> shellRing;
78 std::vector<std::unique_ptr<CoordinateSequence>> holeRings;
79
80 //-- indicates whether a hole should be testing for touching
81 std::vector<bool> isHoleTouchingHint;
82
83 CoordinateSequence joinedRing;
84
85 // a sorted and searchable version of the joinedRing
86 std::set<Coordinate> joinedPts;
87
88 std::unique_ptr<SegmentSetMutualIntersector> boundaryIntersector;
89
90 // holding place for some BasicSegmentStrings
91 std::vector<std::unique_ptr<BasicSegmentString>> polySegStringStore;
92
93
94 // Classes
95 class InteriorIntersectionDetector;
96 friend class PolygonHoleJoiner::InteriorIntersectionDetector;
97
98
99 void extractOrientedRings(const Polygon* polygon);
100 static std::unique_ptr<CoordinateSequence> extractOrientedRing(const LinearRing* ring, bool isCW);
101 void nodeRings();
102 void joinHoles();
103
104 void joinHole(std::size_t index, const CoordinateSequence& holeCoords);
105
113 bool joinTouchingHole(const CoordinateSequence& holeCoords);
114
124 std::size_t findHoleTouchIndex(const CoordinateSequence& holeCoords);
125
131 void joinNonTouchingHole(
132 const CoordinateSequence& holeCoords);
133
134 const Coordinate& findJoinableVertex(
135 const Coordinate& holeJoinCoord);
136
147 std::size_t findJoinIndex(
148 const Coordinate& joinCoord,
149 const Coordinate& holeJoinCoord);
150
160 static bool isLineInterior(
161 const CoordinateSequence& ring,
162 std::size_t ringIndex,
163 const Coordinate& linePt);
164
165 static std::size_t prev(std::size_t i, std::size_t size);
166 static std::size_t next(std::size_t i, std::size_t size);
167
180 void addJoinedHole(
181 std::size_t joinIndex,
182 const CoordinateSequence& holeCoords,
183 std::size_t holeJoinIndex);
184
195 std::vector<Coordinate> createHoleSection(
196 const CoordinateSequence& holeCoords,
197 std::size_t holeJoinIndex,
198 const Coordinate& joinPt);
199
206 static std::vector<const LinearRing*> sortHoles(
207 const Polygon* poly);
208
209 static std::size_t findLowestLeftVertexIndex(
210 const CoordinateSequence& holeCoords);
211
220 bool intersectsBoundary(
221 const Coordinate& p0,
222 const Coordinate& p1);
223
224 std::unique_ptr<SegmentSetMutualIntersector> createBoundaryIntersector();
225
226
227public:
228
229 PolygonHoleJoiner(const Polygon* p_inputPolygon)
230 : inputPolygon(p_inputPolygon)
231 , boundaryIntersector(nullptr)
232 {};
233
241 static std::unique_ptr<Polygon> joinAsPolygon(
242 const Polygon* p_inputPolygon);
243
251 static std::unique_ptr<CoordinateSequence> join(
252 const Polygon* p_inputPolygon);
253
259 std::unique_ptr<CoordinateSequence> compute();
260
261};
262
263
264} // namespace geos.triangulate.polygon
265} // namespace geos.triangulate
266} // namespace geos
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
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Represents a list of contiguous line segments, and supports noding the segments.
Definition BasicSegmentString.h:44
An intersector for the red-blue intersection problem.
Definition SegmentSetMutualIntersector.h:36
Definition PolygonHoleJoiner.h:62
static std::unique_ptr< CoordinateSequence > join(const Polygon *p_inputPolygon)
static std::unique_ptr< Polygon > joinAsPolygon(const Polygon *p_inputPolygon)
std::unique_ptr< CoordinateSequence > compute()
Basic namespace for all GEOS functionalities.
Definition geos.h:39