MySQL  8.0.28
Source Code Documentation
within_functor.h
Go to the documentation of this file.
1 #ifndef SQL_GIS_WITHIN_FUNCTOR_H_INCLUDED
2 #define SQL_GIS_WITHIN_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 within functor interface.
29 ///
30 /// The functor is not intended for use directly by MySQL code. It should be
31 /// used indirectly through the gis::within() function.
32 ///
33 /// @see gis::within
34 
35 #include <boost/geometry.hpp>
36 
37 #include "sql/gis/box.h"
38 #include "sql/gis/functor.h"
39 #include "sql/gis/geometries.h"
41 
42 namespace gis {
43 
44 /// Within 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 within or other geographic functions. It should not be used
48 /// directly by other MySQL code.
49 class Within : public Functor<bool> {
50  private:
51  /// Semi-major axis of ellipsoid.
52  double m_semi_major;
53  /// Semi-minor axis of ellipsoid.
54  double m_semi_minor;
55  /// Strategy used for P/L and P/A.
56  boost::geometry::strategy::within::geographic_winding<Geographic_point>
58  /// Strategy used for L/L, L/A and A/A.
59  boost::geometry::strategy::intersection::geographic_segments<>
61 
62  public:
63  /// Creates a new Within functor.
64  ///
65  /// @param semi_major Semi-major axis of ellipsoid.
66  /// @param semi_minor Semi-minor axis of ellipsoid.
67  Within(double semi_major, double semi_minor);
68  bool operator()(const Geometry *g1, const Geometry *g2) const override;
69  bool operator()(const Box *b1, const Box *b2) const;
70  bool eval(const Geometry *g1, const Geometry *g2) const;
71 
72  //////////////////////////////////////////////////////////////////////////////
73 
74  // within(Cartesian_point, *)
75 
76  bool eval(const Cartesian_point *g1, const Cartesian_point *g2) const;
77  bool eval(const Cartesian_point *g1, const Cartesian_linestring *g2) const;
78  bool eval(const Cartesian_point *g1, const Cartesian_polygon *g2) const;
79  bool eval(const Cartesian_point *g1,
80  const Cartesian_geometrycollection *g2) const;
81  bool eval(const Cartesian_point *g1, const Cartesian_multipoint *g2) const;
82  bool eval(const Cartesian_point *g1,
83  const Cartesian_multilinestring *g2) const;
84  bool eval(const Cartesian_point *g1, const Cartesian_multipolygon *g2) const;
85 
86  //////////////////////////////////////////////////////////////////////////////
87 
88  // within(Cartesian_linestring, *)
89 
90  bool eval(const Cartesian_linestring *g1, const Cartesian_point *g2) const;
91  bool eval(const Cartesian_linestring *g1,
92  const Cartesian_linestring *g2) const;
93  bool eval(const Cartesian_linestring *g1, const Cartesian_polygon *g2) const;
94  bool eval(const Cartesian_linestring *g1,
95  const Cartesian_geometrycollection *g2) const;
96  bool eval(const Cartesian_linestring *g1,
97  const Cartesian_multipoint *g2) const;
98  bool eval(const Cartesian_linestring *g1,
99  const Cartesian_multilinestring *g2) const;
100  bool eval(const Cartesian_linestring *g1,
101  const Cartesian_multipolygon *g2) const;
102 
103  //////////////////////////////////////////////////////////////////////////////
104 
105  // within(Cartesian_polygon, *)
106 
107  bool eval(const Cartesian_polygon *g1, const Cartesian_point *g2) const;
108  bool eval(const Cartesian_polygon *g1, const Cartesian_linestring *g2) const;
109  bool eval(const Cartesian_polygon *g1, const Cartesian_polygon *g2) const;
110  bool eval(const Cartesian_polygon *g1,
111  const Cartesian_geometrycollection *g2) const;
112  bool eval(const Cartesian_polygon *g1, const Cartesian_multipoint *g2) const;
113  bool eval(const Cartesian_polygon *g1,
114  const Cartesian_multilinestring *g2) const;
115  bool eval(const Cartesian_polygon *g1,
116  const Cartesian_multipolygon *g2) const;
117 
118  //////////////////////////////////////////////////////////////////////////////
119 
120  // within(Cartesian_geometrycollection, *)
121 
122  bool eval(const Cartesian_geometrycollection *g1,
123  const Cartesian_point *g2) const;
124  bool eval(const Cartesian_geometrycollection *g1,
125  const Cartesian_linestring *g2) const;
126  bool eval(const Cartesian_geometrycollection *g1,
127  const Cartesian_polygon *g2) const;
128  bool eval(const Cartesian_geometrycollection *g1,
129  const Cartesian_geometrycollection *g2) const;
130  bool eval(const Cartesian_geometrycollection *g1,
131  const Cartesian_multipoint *g2) const;
132  bool eval(const Cartesian_geometrycollection *g1,
133  const Cartesian_multilinestring *g2) const;
134  bool eval(const Cartesian_geometrycollection *g1,
135  const Cartesian_multipolygon *g2) const;
136 
137  //////////////////////////////////////////////////////////////////////////////
138 
139  // within(Cartesian_multipoint, *)
140 
141  bool eval(const Cartesian_multipoint *g1, const Cartesian_point *g2) const;
142  bool eval(const Cartesian_multipoint *g1,
143  const Cartesian_linestring *g2) const;
144  bool eval(const Cartesian_multipoint *g1, const Cartesian_polygon *g2) const;
145  bool eval(const Cartesian_multipoint *g1,
146  const Cartesian_geometrycollection *g2) const;
147  bool eval(const Cartesian_multipoint *g1,
148  const Cartesian_multipoint *g2) const;
149  bool eval(const Cartesian_multipoint *g1,
150  const Cartesian_multilinestring *g2) const;
151  bool eval(const Cartesian_multipoint *g1,
152  const Cartesian_multipolygon *g2) const;
153 
154  //////////////////////////////////////////////////////////////////////////////
155 
156  // within(Cartesian_multilinestring, *)
157 
158  bool eval(const Cartesian_multilinestring *g1,
159  const Cartesian_point *g2) const;
160  bool eval(const Cartesian_multilinestring *g1,
161  const Cartesian_linestring *g2) const;
162  bool eval(const Cartesian_multilinestring *g1,
163  const Cartesian_polygon *g2) const;
164  bool eval(const Cartesian_multilinestring *g1,
165  const Cartesian_geometrycollection *g2) const;
166  bool eval(const Cartesian_multilinestring *g1,
167  const Cartesian_multipoint *g2) const;
168  bool eval(const Cartesian_multilinestring *g1,
169  const Cartesian_multilinestring *g2) const;
170  bool eval(const Cartesian_multilinestring *g1,
171  const Cartesian_multipolygon *g2) const;
172 
173  //////////////////////////////////////////////////////////////////////////////
174 
175  // within(Cartesian_multipolygon, *)
176 
177  bool eval(const Cartesian_multipolygon *g1, const Cartesian_point *g2) const;
178  bool eval(const Cartesian_multipolygon *g1,
179  const Cartesian_linestring *g2) const;
180  bool eval(const Cartesian_multipolygon *g1,
181  const Cartesian_polygon *g2) const;
182  bool eval(const Cartesian_multipolygon *g1,
183  const Cartesian_geometrycollection *g2) const;
184  bool eval(const Cartesian_multipolygon *g1,
185  const Cartesian_multipoint *g2) const;
186  bool eval(const Cartesian_multipolygon *g1,
187  const Cartesian_multilinestring *g2) const;
188  bool eval(const Cartesian_multipolygon *g1,
189  const Cartesian_multipolygon *g2) const;
190 
191  //////////////////////////////////////////////////////////////////////////////
192 
193  // within(Geographic_point, *)
194 
195  bool eval(const Geographic_point *g1, const Geographic_point *g2) const;
196  bool eval(const Geographic_point *g1, const Geographic_linestring *g2) const;
197  bool eval(const Geographic_point *g1, const Geographic_polygon *g2) const;
198  bool eval(const Geographic_point *g1,
199  const Geographic_geometrycollection *g2) const;
200  bool eval(const Geographic_point *g1, const Geographic_multipoint *g2) const;
201  bool eval(const Geographic_point *g1,
202  const Geographic_multilinestring *g2) const;
203  bool eval(const Geographic_point *g1,
204  const Geographic_multipolygon *g2) const;
205 
206  //////////////////////////////////////////////////////////////////////////////
207 
208  // within(Geographic_linestring, *)
209 
210  bool eval(const Geographic_linestring *g1, const Geographic_point *g2) const;
211  bool eval(const Geographic_linestring *g1,
212  const Geographic_linestring *g2) const;
213  bool eval(const Geographic_linestring *g1,
214  const Geographic_polygon *g2) const;
215  bool eval(const Geographic_linestring *g1,
216  const Geographic_geometrycollection *g2) const;
217  bool eval(const Geographic_linestring *g1,
218  const Geographic_multipoint *g2) const;
219  bool eval(const Geographic_linestring *g1,
220  const Geographic_multilinestring *g2) const;
221  bool eval(const Geographic_linestring *g1,
222  const Geographic_multipolygon *g2) const;
223 
224  //////////////////////////////////////////////////////////////////////////////
225 
226  // within(Geographic_polygon, *)
227 
228  bool eval(const Geographic_polygon *g1, const Geographic_point *g2) const;
229  bool eval(const Geographic_polygon *g1,
230  const Geographic_linestring *g2) const;
231  bool eval(const Geographic_polygon *g1, const Geographic_polygon *g2) const;
232  bool eval(const Geographic_polygon *g1,
233  const Geographic_geometrycollection *g2) const;
234  bool eval(const Geographic_polygon *g1,
235  const Geographic_multipoint *g2) const;
236  bool eval(const Geographic_polygon *g1,
237  const Geographic_multilinestring *g2) const;
238  bool eval(const Geographic_polygon *g1,
239  const Geographic_multipolygon *g2) const;
240 
241  //////////////////////////////////////////////////////////////////////////////
242 
243  // within(Geographic_geometrycollection, *)
244 
245  bool eval(const Geographic_geometrycollection *g1,
246  const Geographic_point *g2) const;
247  bool eval(const Geographic_geometrycollection *g1,
248  const Geographic_linestring *g2) const;
249  bool eval(const Geographic_geometrycollection *g1,
250  const Geographic_polygon *g2) const;
251  bool eval(const Geographic_geometrycollection *g1,
252  const Geographic_geometrycollection *g2) const;
253  bool eval(const Geographic_geometrycollection *g1,
254  const Geographic_multipoint *g2) const;
255  bool eval(const Geographic_geometrycollection *g1,
256  const Geographic_multilinestring *g2) const;
257  bool eval(const Geographic_geometrycollection *g1,
258  const Geographic_multipolygon *g2) const;
259 
260  //////////////////////////////////////////////////////////////////////////////
261 
262  // within(Geographic_multipoint, *)
263 
264  bool eval(const Geographic_multipoint *g1, const Geographic_point *g2) const;
265  bool eval(const Geographic_multipoint *g1,
266  const Geographic_linestring *g2) const;
267  bool eval(const Geographic_multipoint *g1,
268  const Geographic_polygon *g2) const;
269  bool eval(const Geographic_multipoint *g1,
270  const Geographic_geometrycollection *g2) const;
271  bool eval(const Geographic_multipoint *g1,
272  const Geographic_multipoint *g2) const;
273  bool eval(const Geographic_multipoint *g1,
274  const Geographic_multilinestring *g2) const;
275  bool eval(const Geographic_multipoint *g1,
276  const Geographic_multipolygon *g2) const;
277 
278  //////////////////////////////////////////////////////////////////////////////
279 
280  // within(Geographic_multilinestring, *)
281 
282  bool eval(const Geographic_multilinestring *g1,
283  const Geographic_point *g2) const;
284  bool eval(const Geographic_multilinestring *g1,
285  const Geographic_linestring *g2) const;
286  bool eval(const Geographic_multilinestring *g1,
287  const Geographic_polygon *g2) const;
288  bool eval(const Geographic_multilinestring *g1,
289  const Geographic_geometrycollection *g2) const;
290  bool eval(const Geographic_multilinestring *g1,
291  const Geographic_multipoint *g2) const;
292  bool eval(const Geographic_multilinestring *g1,
293  const Geographic_multilinestring *g2) const;
294  bool eval(const Geographic_multilinestring *g1,
295  const Geographic_multipolygon *g2) const;
296 
297  //////////////////////////////////////////////////////////////////////////////
298 
299  // within(Geographic_multipolygon, *)
300 
301  bool eval(const Geographic_multipolygon *g1,
302  const Geographic_point *g2) const;
303  bool eval(const Geographic_multipolygon *g1,
304  const Geographic_linestring *g2) const;
305  bool eval(const Geographic_multipolygon *g1,
306  const Geographic_polygon *g2) const;
307  bool eval(const Geographic_multipolygon *g1,
308  const Geographic_geometrycollection *g2) const;
309  bool eval(const Geographic_multipolygon *g1,
310  const Geographic_multipoint *g2) const;
311  bool eval(const Geographic_multipolygon *g1,
312  const Geographic_multilinestring *g2) const;
313  bool eval(const Geographic_multipolygon *g1,
314  const Geographic_multipolygon *g2) const;
315 
316  //////////////////////////////////////////////////////////////////////////////
317 
318  // within(Box, Box)
319 
320  bool eval(const Cartesian_box *b1, const Cartesian_box *b2) const;
321  bool eval(const Geographic_box *b1, const Geographic_box *b2) const;
322 };
323 
324 } // namespace gis
325 
326 #endif // SQL_GIS_WITHIN_FUNCTOR_H_INCLUDED
This file declares the Box class.
A 2d box with sides parallel to the coordinate system grid.
Definition: box.h:40
A Cartesian 2d box.
Definition: box.h:69
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
The base class of all functors that takes two geometry arguments.
Definition: functor.h:164
A Geographic 2d box.
Definition: box.h:102
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
Within functor that calls Boost.Geometry with the correct parameter types.
Definition: within_functor.h:49
double m_semi_major
Semi-major axis of ellipsoid.
Definition: within_functor.h:52
double m_semi_minor
Semi-minor axis of ellipsoid.
Definition: within_functor.h:54
Within(double semi_major, double semi_minor)
Creates a new Within functor.
Definition: within.cc:52
bool eval(const Geometry *g1, const Geometry *g2) const
Definition: within.cc:79
boost::geometry::strategy::intersection::geographic_segments m_geographic_ll_la_aa_strategy
Strategy used for L/L, L/A and A/A.
Definition: within_functor.h:60
bool operator()(const Geometry *g1, const Geometry *g2) const override
Definition: within.cc:60
boost::geometry::strategy::within::geographic_winding< Geographic_point > m_geographic_pl_pa_strategy
Strategy used for P/L and P/A.
Definition: within_functor.h:57
This file contains the superclasses for GIS functors.
This file declares the geometry class hierarchy used by the server as the internal representation of ...
This file contains Boost.Geometry type traits declarations for Cartesian and geographic geometries.
Definition: area.cc:46