MySQL 9.1.0
Source Code Documentation
distance_functor.h
Go to the documentation of this file.
1#ifndef SQL_GIS_DISTANCE_FUNCTOR_H_INCLUDED
2#define SQL_GIS_DISTANCE_FUNCTOR_H_INCLUDED
3
4// Copyright (c) 2017, 2024, Oracle and/or its affiliates.
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License, version 2.0,
8// as published by the Free Software Foundation.
9//
10// This program is designed to work with certain software (including
11// but not limited to OpenSSL) that is licensed under separate terms,
12// as designated in a particular file or component or in included license
13// documentation. The authors of MySQL hereby grant you an additional
14// permission to link the program and your derivative works with the
15// separately licensed software that they have either included with
16// the program or referenced in the documentation.
17//
18// This program is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License, version 2.0, for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this program; if not, write to the Free Software
25// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
27/// @file
28///
29/// This file declares the distance functor interface.
30///
31/// The functor is not intended for use directly by MySQL code. It should be
32/// used indirectly through the gis::distance() function.
33///
34/// @see gis::distance
35
36#include <memory> // std::unique_ptr
37
38#include <boost/geometry.hpp>
39
40#include "sql/gis/functor.h"
41#include "sql/gis/geometries.h"
42
43namespace gis {
44
45/// Distance functor that calls Boost.Geometry with the correct parameter types.
46///
47/// The functor throws exceptions and is therefore only intended used to
48/// implement distance or other geographic functions. It should not be used
49/// directly by other MySQL code.
50class Distance : public Functor<double> {
51 private:
52 std::unique_ptr<boost::geometry::strategy::distance::andoyer<
53 boost::geometry::srs::spheroid<double>>>
55 std::unique_ptr<boost::geometry::strategy::distance::geographic_cross_track<
56 boost::geometry::strategy::andoyer,
57 boost::geometry::srs::spheroid<double>, double>>
59
60 public:
61 Distance(double major, double minor);
62 double operator()(const Geometry *g1, const Geometry *g2) const override;
63 double eval(const Geometry *g1, const Geometry *g2) const;
64
65 //////////////////////////////////////////////////////////////////////////////
66
67 // distance(Cartesian_point, *)
68
69 double eval(const Cartesian_point *g1, const Cartesian_point *g2) const;
70 double eval(const Cartesian_point *g1, const Cartesian_linestring *g2) const;
71 double eval(const Cartesian_point *g1, const Cartesian_polygon *g2) const;
72 double eval(const Cartesian_point *g1,
73 const Cartesian_geometrycollection *g2) const;
74 double eval(const Cartesian_point *g1, const Cartesian_multipoint *g2) const;
75 double eval(const Cartesian_point *g1,
76 const Cartesian_multilinestring *g2) const;
77 double eval(const Cartesian_point *g1,
78 const Cartesian_multipolygon *g2) const;
79
80 //////////////////////////////////////////////////////////////////////////////
81
82 // distance(Cartesian_linestring, *)
83
84 double eval(const Cartesian_linestring *g1, const Cartesian_point *g2) const;
85 double eval(const Cartesian_linestring *g1,
86 const Cartesian_linestring *g2) const;
87 double eval(const Cartesian_linestring *g1,
88 const Cartesian_polygon *g2) const;
89 double eval(const Cartesian_linestring *g1,
90 const Cartesian_geometrycollection *g2) const;
91 double eval(const Cartesian_linestring *g1,
92 const Cartesian_multipoint *g2) const;
93 double eval(const Cartesian_linestring *g1,
94 const Cartesian_multilinestring *g2) const;
95 double eval(const Cartesian_linestring *g1,
96 const Cartesian_multipolygon *g2) const;
97
98 //////////////////////////////////////////////////////////////////////////////
99
100 // distance(Cartesian_polygon, *)
101
102 double eval(const Cartesian_polygon *g1, const Cartesian_point *g2) const;
103 double eval(const Cartesian_polygon *g1,
104 const Cartesian_linestring *g2) const;
105 double eval(const Cartesian_polygon *g1, const Cartesian_polygon *g2) const;
106 double eval(const Cartesian_polygon *g1,
107 const Cartesian_geometrycollection *g2) const;
108 double eval(const Cartesian_polygon *g1,
109 const Cartesian_multipoint *g2) const;
110 double eval(const Cartesian_polygon *g1,
111 const Cartesian_multilinestring *g2) const;
112 double eval(const Cartesian_polygon *g1,
113 const Cartesian_multipolygon *g2) const;
114
115 //////////////////////////////////////////////////////////////////////////////
116
117 // distance(Cartesian_geometrycollection, *)
118
119 double eval(const Cartesian_geometrycollection *g1, const Geometry *g2) const;
120
121 //////////////////////////////////////////////////////////////////////////////
122
123 // distance(Cartesian_multipoint, *)
124
125 double eval(const Cartesian_multipoint *g1, const Cartesian_point *g2) const;
126 double eval(const Cartesian_multipoint *g1,
127 const Cartesian_linestring *g2) const;
128 double eval(const Cartesian_multipoint *g1,
129 const Cartesian_polygon *g2) const;
130 double eval(const Cartesian_multipoint *g1,
131 const Cartesian_geometrycollection *g2) const;
132 double eval(const Cartesian_multipoint *g1,
133 const Cartesian_multipoint *g2) const;
134 double eval(const Cartesian_multipoint *g1,
135 const Cartesian_multilinestring *g2) const;
136 double eval(const Cartesian_multipoint *g1,
137 const Cartesian_multipolygon *g2) const;
138
139 //////////////////////////////////////////////////////////////////////////////
140
141 // distance(Cartesian_multilinestring, *)
142
143 double eval(const Cartesian_multilinestring *g1,
144 const Cartesian_point *g2) const;
145 double eval(const Cartesian_multilinestring *g1,
146 const Cartesian_linestring *g2) const;
147 double eval(const Cartesian_multilinestring *g1,
148 const Cartesian_polygon *g2) const;
149 double eval(const Cartesian_multilinestring *g1,
150 const Cartesian_geometrycollection *g2) const;
151 double eval(const Cartesian_multilinestring *g1,
152 const Cartesian_multipoint *g2) const;
153 double eval(const Cartesian_multilinestring *g1,
154 const Cartesian_multilinestring *g2) const;
155 double eval(const Cartesian_multilinestring *g1,
156 const Cartesian_multipolygon *g2) const;
157
158 //////////////////////////////////////////////////////////////////////////////
159
160 // distance(Cartesian_multipolygon, *)
161
162 double eval(const Cartesian_multipolygon *g1,
163 const Cartesian_point *g2) const;
164 double eval(const Cartesian_multipolygon *g1,
165 const Cartesian_linestring *g2) const;
166 double eval(const Cartesian_multipolygon *g1,
167 const Cartesian_polygon *g2) const;
168 double eval(const Cartesian_multipolygon *g1,
169 const Cartesian_geometrycollection *g2) const;
170 double eval(const Cartesian_multipolygon *g1,
171 const Cartesian_multipoint *g2) const;
172 double eval(const Cartesian_multipolygon *g1,
173 const Cartesian_multilinestring *g2) const;
174 double eval(const Cartesian_multipolygon *g1,
175 const Cartesian_multipolygon *g2) const;
176
177 //////////////////////////////////////////////////////////////////////////////
178
179 // distance(Geographic_point, *)
180
181 double eval(const Geographic_point *g1, const Geographic_point *g2) const;
182 double eval(const Geographic_point *g1,
183 const Geographic_linestring *g2) const;
184 double eval(const Geographic_point *g1, const Geographic_polygon *g2) const;
185 double eval(const Geographic_point *g1,
186 const Geographic_multipoint *g2) const;
187 double eval(const Geographic_point *g1,
188 const Geographic_multilinestring *g2) const;
189 double eval(const Geographic_point *g1,
190 const Geographic_multipolygon *g2) const;
191 double eval(const Geographic_point *g1,
192 const Geographic_geometrycollection *g2) const;
193
194 //////////////////////////////////////////////////////////////////////////////
195
196 // distance(Geographic_linestring, *)
197
198 double eval(const Geographic_linestring *g1,
199 const Geographic_point *g2) const;
200 double eval(const Geographic_linestring *g1,
201 const Geographic_linestring *g2) const;
202 double eval(const Geographic_linestring *g1,
203 const Geographic_polygon *g2) const;
204 double eval(const Geographic_linestring *g1,
205 const Geographic_multipoint *g2) const;
206 double eval(const Geographic_linestring *g1,
207 const Geographic_multilinestring *g2) const;
208 double eval(const Geographic_linestring *g1,
209 const Geographic_multipolygon *g2) const;
210 double eval(const Geographic_linestring *g1,
211 const Geographic_geometrycollection *g2) const;
212
213 //////////////////////////////////////////////////////////////////////////////
214
215 // distance(Geographic_polygon, *)
216
217 double eval(const Geographic_polygon *g1, const Geographic_point *g2) const;
218 double eval(const Geographic_polygon *g1,
219 const Geographic_linestring *g2) const;
220 double eval(const Geographic_polygon *g1, const Geographic_polygon *g2) const;
221 double eval(const Geographic_polygon *g1,
222 const Geographic_multipoint *g2) const;
223 double eval(const Geographic_polygon *g1,
224 const Geographic_multilinestring *g2) const;
225 double eval(const Geographic_polygon *g1,
226 const Geographic_multipolygon *g2) const;
227 double eval(const Geographic_polygon *g1,
228 const Geographic_geometrycollection *g2) const;
229
230 //////////////////////////////////////////////////////////////////////////////
231
232 // distance(Geographic_multipoint, *)
233
234 double eval(const Geographic_multipoint *g1,
235 const Geographic_point *g2) const;
236 double eval(const Geographic_multipoint *g1,
237 const Geographic_linestring *g2) const;
238 double eval(const Geographic_multipoint *g1,
239 const Geographic_polygon *g2) const;
240 double eval(const Geographic_multipoint *g1,
241 const Geographic_multipoint *g2) const;
242 double eval(const Geographic_multipoint *g1,
243 const Geographic_multilinestring *g2) const;
244 double eval(const Geographic_multipoint *g1,
245 const Geographic_multipolygon *g2) const;
246 double eval(const Geographic_multipoint *g1,
247 const Geographic_geometrycollection *g2) const;
248
249 //////////////////////////////////////////////////////////////////////////////
250
251 // distance(Geographic_multilinestring, *)
252
253 double eval(const Geographic_multilinestring *g1,
254 const Geographic_point *g2) const;
255 double eval(const Geographic_multilinestring *g1,
256 const Geographic_linestring *g2) const;
257 double eval(const Geographic_multilinestring *g1,
258 const Geographic_polygon *g2) const;
259 double eval(const Geographic_multilinestring *g1,
260 const Geographic_multipoint *g2) const;
261 double eval(const Geographic_multilinestring *g1,
262 const Geographic_multilinestring *g2) const;
263 double eval(const Geographic_multilinestring *g1,
264 const Geographic_multipolygon *g2) const;
265 double eval(const Geographic_multilinestring *g1,
266 const Geographic_geometrycollection *g2) const;
267
268 //////////////////////////////////////////////////////////////////////////////
269
270 // distance(Geographic_multipolygon, *)
271
272 double eval(const Geographic_multipolygon *g1,
273 const Geographic_point *g2) const;
274 double eval(const Geographic_multipolygon *g1,
275 const Geographic_linestring *g2) const;
276 double eval(const Geographic_multipolygon *g1,
277 const Geographic_polygon *g2) const;
278 double eval(const Geographic_multipolygon *g1,
279 const Geographic_multipoint *g2) const;
280 double eval(const Geographic_multipolygon *g1,
281 const Geographic_multilinestring *g2) const;
282 double eval(const Geographic_multipolygon *g1,
283 const Geographic_multipolygon *g2) const;
284 double eval(const Geographic_multipolygon *g1,
285 const Geographic_geometrycollection *g2) const;
286
287 //////////////////////////////////////////////////////////////////////////////
288
289 // distance(Geographic_geometrycollection, *)
290
291 double eval(const Geographic_geometrycollection *g1,
292 const Geometry *g2) const;
293};
294
295} // namespace gis
296
297#endif // SQL_GIS_DISTANCE_FUNCTOR_H_INCLUDED
A Cartesian 2d geometry collection.
Definition: geometries_cs.h:375
A Cartesian 2d linestring.
Definition: geometries_cs.h:71
A Cartesian 2d multilinestring.
Definition: geometries_cs.h:602
A Cartesian 2d multipoint.
Definition: geometries_cs.h:501
A Cartesian 2d multipolygon.
Definition: geometries_cs.h:720
A Cartesian 2d point.
Definition: geometries_cs.h:47
A Cartesian 2d polygon.
Definition: geometries_cs.h:269
Distance functor that calls Boost.Geometry with the correct parameter types.
Definition: distance_functor.h:50
std::unique_ptr< boost::geometry::strategy::distance::geographic_cross_track< boost::geometry::strategy::andoyer, boost::geometry::srs::spheroid< double >, double > > m_geographic_strategy_non_pp
Definition: distance_functor.h:58
std::unique_ptr< boost::geometry::strategy::distance::andoyer< boost::geometry::srs::spheroid< double > > > m_geographic_strategy_pp
Definition: distance_functor.h:54
double eval(const Geometry *g1, const Geometry *g2) const
Definition: distance_functor.cc:106
double operator()(const Geometry *g1, const Geometry *g2) const override
Definition: distance_functor.cc:102
Distance(double major, double minor)
Definition: distance_functor.cc:90
The base class of all functors that takes two geometry arguments.
Definition: functor.h:165
A geographic (ellipsoidal) 2d geometry collection.
Definition: geometries_cs.h:438
A geographic (ellipsoidal) 2d linestring.
Definition: geometries_cs.h:125
A geographic (ellipsoidal) 2d multilinestring.
Definition: geometries_cs.h:661
A geographic (ellipsoidal) 2d multipoint.
Definition: geometries_cs.h:552
A geographic (ellipsoidal) 2d multipolygon.
Definition: geometries_cs.h:774
A geographic (ellipsoidal) 2d point.
Definition: geometries_cs.h:58
A geographic (ellipsoidal) 2d polygon.
Definition: geometries_cs.h:322
Abstract superclass for all geometric objects.
Definition: geometries.h:100
This file contains the superclasses for GIS functors.
This file declares the geometry class hierarchy used by the server as the internal representation of ...
Definition: area.cc:47
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2440