GEOS 3.10.1
IsSimpleOp.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2001-2002 Vivid Solutions Inc.
7 * Copyright (C) 2009 Sandro Santilli <strk@kbt.io>
8 * Copyright (C) 2005-2006 Refractions Research Inc.
9 * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
10 *
11 * This is free software; you can redistribute and/or modify it under
12 * the terms of the GNU Lesser General Public Licence as published
13 * by the Free Software Foundation.
14 * See the COPYING file for more information.
15 *
16 **********************************************************************/
17
18#pragma once
19
20#include <memory>
21
22#include <geos/algorithm/LineIntersector.h>
23#include <geos/algorithm/BoundaryNodeRule.h>
24#include <geos/noding/SegmentIntersector.h>
25
26
27// Forward declarations
28namespace geos {
29namespace noding {
30class SegmentString;
31class BasicSegmentString;
32}
33namespace algorithm {
34class BoundaryNodeRule;
35}
36namespace geom {
37class LineString;
38class LinearRing;
39class MultiLineString;
40class MultiPoint;
41class Geometry;
42class Polygon;
43class GeometryCollection;
44}
45}
46
47
48namespace geos { // geos
49namespace operation { // geos.operation
50namespace valid { // geos.operation.valid
51
95class GEOS_DLL IsSimpleOp {
96
97private:
98
99 const geom::Geometry& inputGeom;
100 bool isClosedEndpointsInInterior = true;
101 bool isFindAllLocations = false;
102 bool isSimpleResult = false;
103 std::vector<geom::Coordinate> nonSimplePts;
104 bool computed = false;
105
106 void compute();
107
108 bool computeSimple(const geom::Geometry& geom);
109
110 bool isSimpleMultiPoint(const geom::MultiPoint& mp);
111
120 bool isSimplePolygonal(const geom::Geometry& geom);
121
129 bool isSimpleGeometryCollection(const geom::Geometry& geom);
130
131 bool isSimpleLinearGeometry(const geom::Geometry& geom);
132
133 static std::vector<std::unique_ptr<noding::SegmentString>>
134 extractSegmentStrings(const geom::Geometry& geom);
135
136
137 class NonSimpleIntersectionFinder : public noding::SegmentIntersector
138 {
139
140 private:
141
142 bool isClosedEndpointsInInterior;
143 bool isFindAll = false;
144
145 std::vector<geom::Coordinate>& intersectionPts;
147
148 // bool hasInteriorInt;
149 // bool hasInteriorVertexInt;
150 // bool hasEqualSegments;
151 // bool hasInteriorEndpointInt;
152
153 bool findIntersection(
154 noding::SegmentString* ss0, std::size_t segIndex0,
155 noding::SegmentString* ss1, std::size_t segIndex1,
156 const geom::Coordinate& p00, const geom::Coordinate& p01,
157 const geom::Coordinate& p10, const geom::Coordinate& p11);
158
168 bool isIntersectionEndpoint(
169 const noding::SegmentString* ss, std::size_t ssIndex,
170 const algorithm::LineIntersector& li, std::size_t liSegmentIndex) const;
171
180 std::size_t intersectionVertexIndex(
181 const algorithm::LineIntersector& li, std::size_t segmentIndex) const;
182
183 public:
184
185 NonSimpleIntersectionFinder(
186 bool p_isClosedEndpointsInInterior,
187 bool p_isFindAll,
188 std::vector<geom::Coordinate>& p_intersectionPts)
189 : isClosedEndpointsInInterior(p_isClosedEndpointsInInterior)
190 , isFindAll(p_isFindAll)
191 , intersectionPts(p_intersectionPts)
192 {};
193
199 bool hasIntersection() const;
200
201 void processIntersections(
202 noding::SegmentString* ss0, std::size_t segIndex0,
203 noding::SegmentString* ss1, std::size_t segIndex1) override;
204
205 bool isDone() const override;
206
207 }; // NonSimpleIntersectionFinder
208
209
210public:
211
212 IsSimpleOp(const geom::Geometry* geom)
213 : IsSimpleOp(*geom)
214 {};
215
222 : IsSimpleOp(geom, algorithm::BoundaryNodeRule::getBoundaryRuleMod2())
223 {};
224
231 IsSimpleOp(const geom::Geometry& geom, const algorithm::BoundaryNodeRule& p_boundaryNodeRule)
232 : inputGeom(geom)
233 , isClosedEndpointsInInterior(! p_boundaryNodeRule.isInBoundary(2))
234 , isFindAllLocations(false)
235 , computed(false)
236 {};
237
244 static bool isSimple(const geom::Geometry& geom);
245
246 static bool isSimple(const geom::Geometry* geom) {
247 if (!geom) return false;
248 return isSimple(*geom);
249 }
250
258
265 void setFindAllLocations(bool isFindAll);
266
272 bool isSimple();
273
283
289 const std::vector<geom::Coordinate>& getNonSimpleLocations();
290
291
292
293}; // IsSimpleOp
294
295
296} // namespace geos.operation.valid
297} // namespace geos.operation
298} // namespace geos
An interface for rules which determine whether node points which are in boundaries of lineal geometry...
Definition: BoundaryNodeRule.h:51
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:50
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Definition: MultiPoint.h:54
Processes possible intersections detected by a Noder.
Definition: noding/SegmentIntersector.h:48
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:46
Definition: IsSimpleOp.h:95
geom::Coordinate getNonSimpleLocation()
void setFindAllLocations(bool isFindAll)
IsSimpleOp(const geom::Geometry &geom)
Definition: IsSimpleOp.h:221
static bool isSimple(const geom::Geometry &geom)
geom::Coordinate getNonSimpleLocation(const geom::Geometry &geom)
const std::vector< geom::Coordinate > & getNonSimpleLocations()
IsSimpleOp(const geom::Geometry &geom, const algorithm::BoundaryNodeRule &p_boundaryNodeRule)
Definition: IsSimpleOp.h:231
Basic namespace for all GEOS functionalities.
Definition: geos.h:40