GEOS  3.13.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
27 namespace geos {
28 namespace geom {
29 class Coordinate;
30 class Polygon;
31 class Envelope;
32 }
33 }
34 
41 
42 namespace geos {
43 namespace triangulate {
44 namespace polygon {
45 
46 
67 class GEOS_DLL PolygonEarClipper {
68 
69 private:
70 
71  // Members
72 
73  bool isFlatCornersSkipped = false;
74 
80  const CoordinateSequence& vertex;
81  std::vector<std::size_t> vertexNext;
82  std::size_t vertexSize;
83 
84  // first available vertex index
85  std::size_t vertexFirst;
86 
87  // indices for current corner
88  std::array<std::size_t, 3> cornerIndex;
89 
94  VertexSequencePackedRtree vertexCoordIndex;
95 
96  // Methods
97 
98  std::vector<std::size_t> createNextLinks(std::size_t size) const;
99 
100  bool isValidEar(std::size_t cornerIndex, const std::array<Coordinate, 3>& corner);
101 
114  std::size_t findIntersectingVertex(std::size_t cornerIndex, const std::array<Coordinate, 3>& corner) const;
115 
125  bool isValidEarScan(std::size_t cornerIndex, const std::array<Coordinate, 3>& corner) const;
126 
127  /* private */
128  static Envelope envelope(const std::array<Coordinate, 3>& corner);
129 
133  void removeCorner();
134 
135  bool isRemoved(std::size_t vertexIndex) const;
136 
137  void initCornerIndex();
138 
144  void fetchCorner(std::array<Coordinate, 3>& cornerVertex) const;
145 
149  void nextCorner(std::array<Coordinate, 3>& cornerVertex);
150 
158  std::size_t nextIndex(std::size_t index) const;
159 
160  bool isConvex(const std::array<Coordinate, 3>& pts) const;
161 
162  bool isFlat(const std::array<Coordinate, 3>& pts) const;
163 
169  bool isCornerInvalid(const std::array<Coordinate, 3>& pts) const;
170 
171 
172 public:
173 
180 
187  static void triangulate(const geom::CoordinateSequence& polyShell, TriList<Tri>& triListResult);
188 
205  void setSkipFlatCorners(bool p_isFlatCornersSkipped);
206 
207  void compute(TriList<Tri>& triList);
208 
209  std::unique_ptr<Polygon> toGeometry() const;
210 
211 
212 };
213 
214 
215 
216 } // namespace geos.triangulate.polygon
217 } // namespace geos.triangulate
218 } // 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:216
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Represents a linear polygon, which may include holes.
Definition: Polygon.h:60
Definition: VertexSequencePackedRtree.h:54
Definition: PolygonEarClipper.h:67
static void triangulate(const geom::CoordinateSequence &polyShell, TriList< Tri > &triListResult)
void setSkipFlatCorners(bool p_isFlatCornersSkipped)
PolygonEarClipper(const geom::CoordinateSequence &polyShell)
Definition: TriList.h:54
Definition: Tri.h:49
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25