GEOS 3.14.0dev
PolygonEarClipper.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 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/index/VertexSequencePackedRtree.h>
18#include <geos/triangulate/tri/TriList.h>
19#include <geos/triangulate/tri/Tri.h>
20#include <geos/constants.h>
21
22#include <array>
23#include <memory>
24#include <limits>
25
26// Forward declarations
27namespace geos {
28namespace geom {
29class Coordinate;
30class Polygon;
31class Envelope;
32}
33}
34
35namespace geos {
36namespace triangulate {
37namespace polygon {
38
39
60class GEOS_DLL PolygonEarClipper {
66 template<typename TriType>
69
70private:
71
72 // Members
73
74 bool isFlatCornersSkipped = false;
75
81 const CoordinateSequence& vertex;
82 std::vector<std::size_t> vertexNext;
83 std::size_t vertexSize;
84
85 // first available vertex index
86 std::size_t vertexFirst;
87
88 // indices for current corner
89 std::array<std::size_t, 3> cornerIndex;
90
95 VertexSequencePackedRtree vertexCoordIndex;
96
97 // Methods
98
99 std::vector<std::size_t> createNextLinks(std::size_t size) const;
100
101 bool isValidEar(std::size_t cornerIndex, const std::array<Coordinate, 3>& corner);
102
115 std::size_t findIntersectingVertex(std::size_t cornerIndex, const std::array<Coordinate, 3>& corner) const;
116
126 bool isValidEarScan(std::size_t cornerIndex, const std::array<Coordinate, 3>& corner) const;
127
128 /* private */
129 static Envelope envelope(const std::array<Coordinate, 3>& corner);
130
134 void removeCorner();
135
136 bool isRemoved(std::size_t vertexIndex) const;
137
138 void initCornerIndex();
139
145 void fetchCorner(std::array<Coordinate, 3>& cornerVertex) const;
146
150 void nextCorner(std::array<Coordinate, 3>& cornerVertex);
151
159 std::size_t nextIndex(std::size_t index) const;
160
161 bool isConvex(const std::array<Coordinate, 3>& pts) const;
162
163 bool isFlat(const std::array<Coordinate, 3>& pts) const;
164
170 bool isCornerInvalid(const std::array<Coordinate, 3>& pts) const;
171
172
173public:
174
181
188 static void triangulate(const geom::CoordinateSequence& polyShell, TriList<Tri>& triListResult);
189
206 void setSkipFlatCorners(bool p_isFlatCornersSkipped);
207
208 void compute(TriList<Tri>& triList);
209
210 std::unique_ptr<Polygon> toGeometry() const;
211
212
213};
214
215
216
217} // namespace geos.triangulate.polygon
218} // namespace geos.triangulate
219} // 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
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Definition VertexSequencePackedRtree.h:49
Definition PolygonEarClipper.h:60
static void triangulate(const geom::CoordinateSequence &polyShell, TriList< Tri > &triListResult)
void setSkipFlatCorners(bool p_isFlatCornersSkipped)
PolygonEarClipper(const geom::CoordinateSequence &polyShell)
Definition TriList.h:50
Definition Tri.h:45
Basic namespace for all GEOS functionalities.
Definition geos.h:39