/src/geos/src/operation/valid/RepeatedPointTester.cpp
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2001-2002 Vivid Solutions Inc. |
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 | | * Last port: operation/valid/RepeatedPointTester.java rev. 1.8 (JTS-1.10) |
16 | | * |
17 | | **********************************************************************/ |
18 | | |
19 | | #include <geos/operation/valid/RepeatedPointTester.h> |
20 | | #include <geos/util/UnsupportedOperationException.h> |
21 | | #include <geos/geom/CoordinateSequence.h> |
22 | | #include <geos/geom/Geometry.h> |
23 | | #include <geos/geom/Point.h> |
24 | | #include <geos/geom/LineString.h> |
25 | | #include <geos/geom/LinearRing.h> |
26 | | #include <geos/geom/Polygon.h> |
27 | | #include <geos/geom/MultiPoint.h> |
28 | | #include <geos/geom/MultiPolygon.h> |
29 | | #include <geos/geom/MultiLineString.h> |
30 | | #include <geos/geom/GeometryCollection.h> |
31 | | |
32 | | #include <typeinfo> |
33 | | |
34 | | using namespace geos::geom; |
35 | | |
36 | | namespace geos { |
37 | | namespace operation { // geos.operation |
38 | | namespace valid { // geos.operation.valid |
39 | | |
40 | | CoordinateXY& |
41 | | RepeatedPointTester::getCoordinate() |
42 | 0 | { |
43 | 0 | return repeatedCoord; |
44 | 0 | } |
45 | | |
46 | | bool |
47 | | RepeatedPointTester::hasRepeatedPoint(const Geometry* g) |
48 | 0 | { |
49 | 0 | if(g->isEmpty()) { |
50 | 0 | return false; |
51 | 0 | } |
52 | | |
53 | 0 | if(dynamic_cast<const Point*>(g)) { |
54 | 0 | return false; |
55 | 0 | } |
56 | 0 | if(dynamic_cast<const MultiPoint*>(g)) { |
57 | 0 | return false; |
58 | 0 | } |
59 | | |
60 | | // LineString also handles LinearRings |
61 | 0 | if(const LineString* x = dynamic_cast<const LineString*>(g)) { |
62 | 0 | return hasRepeatedPoint(x->getCoordinatesRO()); |
63 | 0 | } |
64 | | |
65 | 0 | if(const Polygon* x = dynamic_cast<const Polygon*>(g)) { |
66 | 0 | return hasRepeatedPoint(x); |
67 | 0 | } |
68 | | |
69 | 0 | if(const MultiPolygon* x = dynamic_cast<const MultiPolygon*>(g)) { |
70 | 0 | return hasRepeatedPoint(x); |
71 | 0 | } |
72 | | |
73 | 0 | if(const MultiLineString* x = dynamic_cast<const MultiLineString*>(g)) { |
74 | 0 | return hasRepeatedPoint(x); |
75 | 0 | } |
76 | | |
77 | 0 | if(const GeometryCollection* x = dynamic_cast<const GeometryCollection*>(g)) { |
78 | 0 | return hasRepeatedPoint(x); |
79 | 0 | } |
80 | | |
81 | 0 | throw util::UnsupportedOperationException(typeid(*g).name()); |
82 | 0 | } |
83 | | |
84 | | bool |
85 | | RepeatedPointTester::hasRepeatedPoint(const CoordinateSequence* coord) |
86 | 0 | { |
87 | 0 | auto npts = coord->getSize(); |
88 | 0 | for(std::size_t i = 1; i < npts; ++i) { |
89 | 0 | if(coord->getAt(i - 1) == coord->getAt(i)) { |
90 | 0 | repeatedCoord = coord->getAt(i); |
91 | 0 | return true; |
92 | 0 | } |
93 | 0 | } |
94 | 0 | return false; |
95 | 0 | } |
96 | | |
97 | | bool |
98 | | RepeatedPointTester::hasRepeatedPoint(const Polygon* p) |
99 | 0 | { |
100 | 0 | if(hasRepeatedPoint(p->getExteriorRing()->getCoordinatesRO())) { |
101 | 0 | return true; |
102 | 0 | } |
103 | | |
104 | 0 | for(std::size_t i = 0, n = p->getNumInteriorRing(); i < n; ++i) { |
105 | 0 | if(hasRepeatedPoint(p->getInteriorRingN(i)->getCoordinatesRO())) { |
106 | 0 | return true; |
107 | 0 | } |
108 | 0 | } |
109 | 0 | return false; |
110 | 0 | } |
111 | | |
112 | | bool |
113 | | RepeatedPointTester::hasRepeatedPoint(const GeometryCollection* gc) |
114 | 0 | { |
115 | 0 | for(std::size_t i = 0, n = gc->getNumGeometries(); i < n; ++i) { |
116 | 0 | const Geometry* g = gc->getGeometryN(i); |
117 | 0 | if(hasRepeatedPoint(g)) { |
118 | 0 | return true; |
119 | 0 | } |
120 | 0 | } |
121 | 0 | return false; |
122 | 0 | } |
123 | | |
124 | | bool |
125 | | RepeatedPointTester::hasRepeatedPoint(const MultiPolygon* gc) |
126 | 0 | { |
127 | 0 | for(std::size_t i = 0, n = gc->getNumGeometries(); i < n; ++i) { |
128 | 0 | const Polygon* g = gc->getGeometryN(i); |
129 | 0 | if(hasRepeatedPoint(g)) { |
130 | 0 | return true; |
131 | 0 | } |
132 | 0 | } |
133 | 0 | return false; |
134 | 0 | } |
135 | | |
136 | | bool |
137 | | RepeatedPointTester::hasRepeatedPoint(const MultiLineString* gc) |
138 | 0 | { |
139 | 0 | for(std::size_t i = 0, n = gc->getNumGeometries(); i < n; ++i) { |
140 | 0 | const LineString* g = gc->getGeometryN(i); |
141 | 0 | if(hasRepeatedPoint(g)) { |
142 | 0 | return true; |
143 | 0 | } |
144 | 0 | } |
145 | 0 | return false; |
146 | 0 | } |
147 | | |
148 | | } // namespace geos.operation.valid |
149 | | } // namespace geos.operation |
150 | | } // namespace geos |
151 | | |