/src/geos/src/geom/prep/BasicPreparedGeometry.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: geom/prep/BasicPreparedGeometry.java rev. 1.5 (JTS-1.10) |
16 | | * |
17 | | **********************************************************************/ |
18 | | |
19 | | |
20 | | #include <geos/geom/prep/BasicPreparedGeometry.h> |
21 | | #include <geos/geom/Coordinate.h> |
22 | | #include <geos/geom/IntersectionMatrix.h> |
23 | | #include <geos/algorithm/PointLocator.h> |
24 | | #include <geos/geom/util/ComponentCoordinateExtracter.h> |
25 | | #include <geos/operation/distance/DistanceOp.h> |
26 | | |
27 | | #include "geos/util.h" |
28 | | |
29 | | namespace geos { |
30 | | namespace geom { // geos.geom |
31 | | namespace prep { // geos.geom.prep |
32 | | |
33 | | /* * |
34 | | * protected: * |
35 | | * */ |
36 | | |
37 | | void |
38 | | BasicPreparedGeometry::setGeometry(const geom::Geometry* geom) |
39 | 0 | { |
40 | 0 | baseGeom = geom; |
41 | 0 | geom::util::ComponentCoordinateExtracter::getCoordinates(*baseGeom, representativePts); |
42 | 0 | } |
43 | | |
44 | | bool |
45 | | BasicPreparedGeometry::envelopesIntersect(const geom::Geometry* g) const |
46 | 0 | { |
47 | 0 | if (g->getGeometryTypeId() == GEOS_POINT) { |
48 | 0 | auto pt = g->getCoordinate(); |
49 | 0 | if (pt == nullptr) { |
50 | 0 | return false; |
51 | 0 | } |
52 | 0 | return baseGeom->getEnvelopeInternal()->intersects(*pt); |
53 | 0 | } |
54 | | |
55 | 0 | return baseGeom->getEnvelopeInternal()->intersects(g->getEnvelopeInternal()); |
56 | 0 | } |
57 | | |
58 | | bool |
59 | | BasicPreparedGeometry::envelopeCovers(const geom::Geometry* g) const |
60 | 0 | { |
61 | 0 | if (g->getGeometryTypeId() == GEOS_POINT) { |
62 | 0 | auto pt = g->getCoordinate(); |
63 | 0 | if (pt == nullptr) { |
64 | 0 | return false; |
65 | 0 | } |
66 | 0 | return baseGeom->getEnvelopeInternal()->covers(pt); |
67 | 0 | } |
68 | | |
69 | 0 | return baseGeom->getEnvelopeInternal()->covers(g->getEnvelopeInternal()); |
70 | 0 | } |
71 | | |
72 | | /* |
73 | | * public: |
74 | | */ |
75 | | BasicPreparedGeometry::BasicPreparedGeometry(const Geometry* geom) |
76 | 0 | { |
77 | 0 | setGeometry(geom); |
78 | 0 | } |
79 | | |
80 | | bool |
81 | | BasicPreparedGeometry::isAnyTargetComponentInTest(const geom::Geometry* testGeom) const |
82 | 0 | { |
83 | 0 | algorithm::PointLocator locator; |
84 | |
|
85 | 0 | for(const auto& c : representativePts) { |
86 | 0 | if(locator.intersects(*c, testGeom)) { |
87 | 0 | return true; |
88 | 0 | } |
89 | 0 | } |
90 | 0 | return false; |
91 | 0 | } |
92 | | |
93 | | bool |
94 | | BasicPreparedGeometry::within(const geom::Geometry* g) const |
95 | 0 | { |
96 | 0 | return getRelateNG().within(g); |
97 | 0 | } |
98 | | |
99 | | bool |
100 | | BasicPreparedGeometry::contains(const geom::Geometry* g) const |
101 | 0 | { |
102 | 0 | return getRelateNG().contains(g); |
103 | 0 | } |
104 | | |
105 | | bool |
106 | | BasicPreparedGeometry::containsProperly(const geom::Geometry* g) const |
107 | 0 | { |
108 | 0 | return getRelateNG().relate(g, "T**FF*FF*"); |
109 | 0 | } |
110 | | |
111 | | bool |
112 | | BasicPreparedGeometry::coveredBy(const geom::Geometry* g) const |
113 | 0 | { |
114 | 0 | return getRelateNG().coveredBy(g); |
115 | 0 | } |
116 | | |
117 | | bool |
118 | | BasicPreparedGeometry::covers(const geom::Geometry* g) const |
119 | 0 | { |
120 | 0 | return getRelateNG().covers(g); |
121 | 0 | } |
122 | | |
123 | | bool |
124 | | BasicPreparedGeometry::crosses(const geom::Geometry* g) const |
125 | 0 | { |
126 | 0 | return getRelateNG().crosses(g); |
127 | 0 | } |
128 | | |
129 | | bool |
130 | | BasicPreparedGeometry::disjoint(const geom::Geometry* g) const |
131 | 0 | { |
132 | 0 | return getRelateNG().disjoint(g); |
133 | 0 | } |
134 | | |
135 | | bool |
136 | | BasicPreparedGeometry::intersects(const geom::Geometry* g) const |
137 | 0 | { |
138 | 0 | return getRelateNG().intersects(g); |
139 | 0 | } |
140 | | |
141 | | bool |
142 | | BasicPreparedGeometry::overlaps(const geom::Geometry* g) const |
143 | 0 | { |
144 | 0 | return getRelateNG().overlaps(g); |
145 | 0 | } |
146 | | |
147 | | bool |
148 | | BasicPreparedGeometry::touches(const geom::Geometry* g) const |
149 | 0 | { |
150 | 0 | return getRelateNG().touches(g); |
151 | 0 | } |
152 | | |
153 | | bool |
154 | | BasicPreparedGeometry::relate(const geom::Geometry* g, const std::string& pat) const |
155 | 0 | { |
156 | 0 | return getRelateNG().relate(g, pat); |
157 | 0 | } |
158 | | |
159 | | std::unique_ptr<IntersectionMatrix> |
160 | | BasicPreparedGeometry::relate(const geom::Geometry* g) const |
161 | 0 | { |
162 | 0 | return getRelateNG().relate(g); |
163 | 0 | } |
164 | | |
165 | | |
166 | | std::unique_ptr<geom::CoordinateSequence> |
167 | | BasicPreparedGeometry::nearestPoints(const geom::Geometry* g) const |
168 | 0 | { |
169 | 0 | operation::distance::DistanceOp dist(baseGeom, g); |
170 | 0 | return dist.nearestPoints(); |
171 | 0 | } |
172 | | |
173 | | double |
174 | | BasicPreparedGeometry::distance(const geom::Geometry* g) const |
175 | 0 | { |
176 | 0 | std::unique_ptr<geom::CoordinateSequence> coords = nearestPoints(g); |
177 | 0 | if ( ! coords ) return DoubleInfinity; |
178 | 0 | return coords->getAt(0).distance( coords->getAt(1) ); |
179 | 0 | } |
180 | | |
181 | | bool |
182 | | BasicPreparedGeometry::isWithinDistance(const geom::Geometry* g, double dist) const |
183 | 0 | { |
184 | 0 | return baseGeom->isWithinDistance(g, dist); |
185 | 0 | } |
186 | | |
187 | | std::string |
188 | | BasicPreparedGeometry::toString() |
189 | 0 | { |
190 | 0 | return baseGeom->toString(); |
191 | 0 | } |
192 | | |
193 | | } // namespace geos.geom.prep |
194 | | } // namespace geos.geom |
195 | | } // namespace geos |