MySQL  8.0.28
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, 2021, 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 also distributed 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 included with MySQL.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License, version 2.0, for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25 
26 /// @file
27 ///
28 /// This file declares the distance functor interface.
29 ///
30 /// The functor is not intended for use directly by MySQL code. It should be
31 /// used indirectly through the gis::distance() function.
32 ///
33 /// @see gis::distance
34 
35 #include <memory> // std::unique_ptr
36 
37 #include <boost/geometry.hpp>
38 
39 #include "sql/gis/functor.h"
40 #include "sql/gis/geometries.h"
41 
42 namespace gis {
43 
44 /// Distance functor that calls Boost.Geometry with the correct parameter types.
45 ///
46 /// The functor throws exceptions and is therefore only intended used to
47 /// implement distance or other geographic functions. It should not be used
48 /// directly by other MySQL code.
49 class Distance : public Functor<double> {
50  private:
51  std::unique_ptr<boost::geometry::strategy::distance::andoyer<
52  boost::geometry::srs::spheroid<double>>>
54  std::unique_ptr<boost::geometry::strategy::distance::geographic_cross_track<
55  boost::geometry::strategy::andoyer,
56  boost::geometry::srs::spheroid<double>, double>>
58 
59  public:
60  Distance(double major, double minor);
61  double operator()(const Geometry *g1, const Geometry *g2) const override;
62  double eval(const Geometry *g1, const Geometry *g2) const;
63 
64  //////////////////////////////////////////////////////////////////////////////
65 
66  // distance(Cartesian_point, *)
67 
68  double eval(const Cartesian_point *g1, const Cartesian_point *g2) const;
69  double eval(const Cartesian_point *g1, const Cartesian_linestring *g2) const;
70  double eval(const Cartesian_point *g1, const Cartesian_polygon *g2) const;
71  double eval(const Cartesian_point *g1,
72  const Cartesian_geometrycollection *g2) const;
73  double eval(const Cartesian_point *g1, const Cartesian_multipoint *g2) const;
74  double eval(const Cartesian_point *g1,
75  const Cartesian_multilinestring *g2) const;
76  double eval(const Cartesian_point *g1,
77  const Cartesian_multipolygon *g2) const;
78 
79  //////////////////////////////////////////////////////////////////////////////
80 
81  // distance(Cartesian_linestring, *)
82 
83  double eval(const Cartesian_linestring *g1, const Cartesian_point *g2) const;
84  double eval(const Cartesian_linestring *g1,
85  const Cartesian_linestring *g2) const;
86  double eval(const Cartesian_linestring *g1,
87  const Cartesian_polygon *g2) const;
88  double eval(const Cartesian_linestring *g1,
89  const Cartesian_geometrycollection *g2) const;
90  double eval(const Cartesian_linestring *g1,
91  const Cartesian_multipoint *g2) const;
92  double eval(const Cartesian_linestring *g1,
93  const Cartesian_multilinestring *g2) const;
94  double eval(const Cartesian_linestring *g1,
95  const Cartesian_multipolygon *g2) const;
96 
97  //////////////////////////////////////////////////////////////////////////////
98 
99  // distance(Cartesian_polygon, *)
100 
101  double eval(const Cartesian_polygon *g1, const Cartesian_point *g2) const;
102  double eval(const Cartesian_polygon *g1,
103  const Cartesian_linestring *g2) const;
104  double eval(const Cartesian_polygon *g1, const Cartesian_polygon *g2) const;
105  double eval(const Cartesian_polygon *g1,
106  const Cartesian_geometrycollection *g2) const;
107  double eval(const Cartesian_polygon *g1,
108  const Cartesian_multipoint *g2) const;
109  double eval(const Cartesian_polygon *g1,
110  const Cartesian_multilinestring *g2) const;
111  double eval(const Cartesian_polygon *g1,
112  const Cartesian_multipolygon *g2) const;
113 
114  //////////////////////////////////////////////////////////////////////////////
115 
116  // distance(Cartesian_geometrycollection, *)
117 
118  double eval(const Cartesian_geometrycollection *g1, const Geometry *g2) const;
119 
120  //////////////////////////////////////////////////////////////////////////////
121 
122  // distance(Cartesian_multipoint, *)
123 
124  double eval(const Cartesian_multipoint *g1, const Cartesian_point *g2) const;
125  double eval(const Cartesian_multipoint *g1,
126  const Cartesian_linestring *g2) const;
127  double eval(const Cartesian_multipoint *g1,
128  const Cartesian_polygon *g2) const;
129  double eval(const Cartesian_multipoint *g1,
130  const Cartesian_geometrycollection *g2) const;
131  double eval(const Cartesian_multipoint *g1,
132  const Cartesian_multipoint *g2) const;
133  double eval(const Cartesian_multipoint *g1,
134  const Cartesian_multilinestring *g2) const;
135  double eval(const Cartesian_multipoint *g1,
136  const Cartesian_multipolygon *g2) const;
137 
138  //////////////////////////////////////////////////////////////////////////////
139 
140  // distance(Cartesian_multilinestring, *)
141 
142  double eval(const Cartesian_multilinestring *g1,
143  const Cartesian_point *g2) const;
144  double eval(const Cartesian_multilinestring *g1,
145  const Cartesian_linestring *g2) const;
146  double eval(const Cartesian_multilinestring *g1,
147  const Cartesian_polygon *g2) const;
148  double eval(const Cartesian_multilinestring *g1,
149  const Cartesian_geometrycollection *g2) const;
150  double eval(const Cartesian_multilinestring *g1,
151  const Cartesian_multipoint *g2) const;
152  double eval(const Cartesian_multilinestring *g1,
153  const Cartesian_multilinestring *g2) const;
154  double eval(const Cartesian_multilinestring *g1,
155  const Cartesian_multipolygon *g2) const;
156 
157  //////////////////////////////////////////////////////////////////////////////
158 
159  // distance(Cartesian_multipolygon, *)
160 
161  double eval(const Cartesian_multipolygon *g1,
162  const Cartesian_point *g2) const;
163  double eval(const Cartesian_multipolygon *g1,
164  const Cartesian_linestring *g2) const;
165  double eval(const Cartesian_multipolygon *g1,
166  const Cartesian_polygon *g2) const;
167  double eval(const Cartesian_multipolygon *g1,
168  const Cartesian_geometrycollection *g2) const;
169  double eval(const Cartesian_multipolygon *g1,
170  const Cartesian_multipoint *g2) const;
171  double eval(const Cartesian_multipolygon *g1,
172  const Cartesian_multilinestring *g2) const;
173  double eval(const Cartesian_multipolygon *g1,
174  const Cartesian_multipolygon *g2) const;
175 
176  //////////////////////////////////////////////////////////////////////////////
177 
178  // distance(Geographic_point, *)
179 
180  double eval(const Geographic_point *g1, const Geographic_point *g2) const;
181  double eval(const Geographic_point *g1,
182  const Geographic_linestring *g2) const;
183  double eval(const Geographic_point *g1, const Geographic_polygon *g2) const;
184  double eval(const Geographic_point *g1,
185  const Geographic_multipoint *g2) const;
186  double eval(const Geographic_point *g1,
187  const Geographic_multilinestring *g2) const;
188  double eval(const Geographic_point *g1,
189  const Geographic_multipolygon *g2) const;
190  double eval(const Geographic_point *g1,
191  const Geographic_geometrycollection *g2) const;
192 
193  //////////////////////////////////////////////////////////////////////////////
194 
195  // distance(Geographic_linestring, *)
196 
197  double eval(const Geographic_linestring *g1,
198  const Geographic_point *g2) const;
199  double eval(const Geographic_linestring *g1,
200  const Geographic_linestring *g2) const;
201  double eval(const Geographic_linestring *g1,
202  const Geographic_polygon *g2) const;
203  double eval(const Geographic_linestring *g1,
204  const Geographic_multipoint *g2) const;
205  double eval(const Geographic_linestring *g1,
206  const Geographic_multilinestring *g2) const;
207  double eval(const Geographic_linestring *g1,
208  const Geographic_multipolygon *g2) const;
209  double eval(const Geographic_linestring *g1,
210  const Geographic_geometrycollection *g2) const;
211 
212  //////////////////////////////////////////////////////////////////////////////
213 
214  // distance(Geographic_polygon, *)
215 
216  double eval(const Geographic_polygon *g1, const Geographic_point *g2) const;
217  double eval(const Geographic_polygon *g1,
218  const Geographic_linestring *g2) const;
219  double eval(const Geographic_polygon *g1, const Geographic_polygon *g2) const;
220  double eval(const Geographic_polygon *g1,
221  const Geographic_multipoint *g2) const;
222  double eval(const Geographic_polygon *g1,
223  const Geographic_multilinestring *g2) const;
224  double eval(const Geographic_polygon *g1,
225  const Geographic_multipolygon *g2) const;
226  double eval(const Geographic_polygon *g1,
227  const Geographic_geometrycollection *g2) const;
228 
229  //////////////////////////////////////////////////////////////////////////////
230 
231  // distance(Geographic_multipoint, *)
232 
233  double eval(const Geographic_multipoint *g1,
234  const Geographic_point *g2) const;
235  double eval(const Geographic_multipoint *g1,
236  const Geographic_linestring *g2) const;
237  double eval(const Geographic_multipoint *g1,
238  const Geographic_polygon *g2) const;
239  double eval(const Geographic_multipoint *g1,
240  const Geographic_multipoint *g2) const;
241  double eval(const Geographic_multipoint *g1,
242  const Geographic_multilinestring *g2) const;
243  double eval(const Geographic_multipoint *g1,
244  const Geographic_multipolygon *g2) const;
245  double eval(const Geographic_multipoint *g1,
246  const Geographic_geometrycollection *g2) const;
247 
248  //////////////////////////////////////////////////////////////////////////////
249 
250  // distance(Geographic_multilinestring, *)
251 
252  double eval(const Geographic_multilinestring *g1,
253  const Geographic_point *g2) const;
254  double eval(const Geographic_multilinestring *g1,
255  const Geographic_linestring *g2) const;
256  double eval(const Geographic_multilinestring *g1,
257  const Geographic_polygon *g2) const;
258  double eval(const Geographic_multilinestring *g1,
259  const Geographic_multipoint *g2) const;
260  double eval(const Geographic_multilinestring *g1,
261  const Geographic_multilinestring *g2) const;
262  double eval(const Geographic_multilinestring *g1,
263  const Geographic_multipolygon *g2) const;
264  double eval(const Geographic_multilinestring *g1,
265  const Geographic_geometrycollection *g2) const;
266 
267  //////////////////////////////////////////////////////////////////////////////
268 
269  // distance(Geographic_multipolygon, *)
270 
271  double eval(const Geographic_multipolygon *g1,
272  const Geographic_point *g2) const;
273  double eval(const Geographic_multipolygon *g1,
274  const Geographic_linestring *g2) const;
275  double eval(const Geographic_multipolygon *g1,
276  const Geographic_polygon *g2) const;
277  double eval(const Geographic_multipolygon *g1,
278  const Geographic_multipoint *g2) const;
279  double eval(const Geographic_multipolygon *g1,
280  const Geographic_multilinestring *g2) const;
281  double eval(const Geographic_multipolygon *g1,
282  const Geographic_multipolygon *g2) const;
283  double eval(const Geographic_multipolygon *g1,
284  const Geographic_geometrycollection *g2) const;
285 
286  //////////////////////////////////////////////////////////////////////////////
287 
288  // distance(Geographic_geometrycollection, *)
289 
290  double eval(const Geographic_geometrycollection *g1,
291  const Geometry *g2) const;
292 };
293 
294 } // namespace gis
295 
296 #endif // SQL_GIS_DISTANCE_FUNCTOR_H_INCLUDED
A Cartesian 2d geometry collection.
Definition: geometries_cs.h:374
A Cartesian 2d linestring.
Definition: geometries_cs.h:70
A Cartesian 2d multilinestring.
Definition: geometries_cs.h:601
A Cartesian 2d multipoint.
Definition: geometries_cs.h:500
A Cartesian 2d multipolygon.
Definition: geometries_cs.h:719
A Cartesian 2d point.
Definition: geometries_cs.h:46
A Cartesian 2d polygon.
Definition: geometries_cs.h:268
Distance functor that calls Boost.Geometry with the correct parameter types.
Definition: distance_functor.h:49
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:57
std::unique_ptr< boost::geometry::strategy::distance::andoyer< boost::geometry::srs::spheroid< double > > > m_geographic_strategy_pp
Definition: distance_functor.h:53
double eval(const Geometry *g1, const Geometry *g2) const
Definition: distance_functor.cc:105
double operator()(const Geometry *g1, const Geometry *g2) const override
Definition: distance_functor.cc:101
Distance(double major, double minor)
Definition: distance_functor.cc:89
The base class of all functors that takes two geometry arguments.
Definition: functor.h:164
A geographic (ellipsoidal) 2d geometry collection.
Definition: geometries_cs.h:437
A geographic (ellipsoidal) 2d linestring.
Definition: geometries_cs.h:124
A geographic (ellipsoidal) 2d multilinestring.
Definition: geometries_cs.h:660
A geographic (ellipsoidal) 2d multipoint.
Definition: geometries_cs.h:551
A geographic (ellipsoidal) 2d multipolygon.
Definition: geometries_cs.h:773
A geographic (ellipsoidal) 2d point.
Definition: geometries_cs.h:57
A geographic (ellipsoidal) 2d polygon.
Definition: geometries_cs.h:321
Abstract superclass for all geometric objects.
Definition: geometries.h:99
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:46
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:2430