MySQL 8.3.0
Source Code Documentation
mbr_utils.h
Go to the documentation of this file.
1#ifndef SQL_GIS_MBR_UTILS_H_INCLUDED
2#define SQL_GIS_MBR_UTILS_H_INCLUDED
3
4// Copyright (c) 2017, 2023, 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 interface of various utility functions for
29/// geometrycollections. The functions may throw exceptions.
30
31#include <boost/geometry.hpp>
32
33#include "sql/gis/box.h"
34#include "sql/gis/geometries.h"
36
37class Item;
38class THD;
39
40namespace dd {
41class Spatial_reference_system;
42} // namespace dd
43
44namespace gis {
45
46/// Checks if two MBRs are equal.
47///
48/// Empty boxes are considered equal.
49///
50/// @param[in] mbr1 First MBR.
51/// @param[in] mbr2 Second MBR.
52/// @retval true The MBRs are equal.
53/// @retval false The MBRs are not equal.
54bool mbrs_are_equal(Box const &mbr1, Box const &mbr2);
55
56/// Checks if an MBR is empty.
57///
58/// By default, BG box coordinates are NaN. If a geometry is empty, its box will
59/// have all NaN coordinates.
60///
61/// @param[in] mbr MBR to check.
62/// @retval true The MBR is empty.
63/// @retval false The MBR is not empty.
64bool mbr_is_empty(Box const &mbr);
65
66/// Checks if an MBR represents a point.
67///
68/// Boxes around points collapse so that min_corner == max_corner.
69///
70/// @param[in] mbr MBR to check.
71/// @retval true The MBR is a point.
72/// @retval false The MBR is not a point.
73bool mbr_is_point(Box const &mbr);
74
75/// Checks if an MBR represents a line.
76///
77/// Boxes around vertical and horizontal lines collapse so that either the
78/// minimum and maximum X coordinate or Y coordinate are equal.
79///
80/// @param[in] mbr MBR to check.
81/// @retval true The MBR is a line.
82/// @retval false The MBR is not a line.
83bool mbr_is_line(Box const &mbr);
84
85/// Computes the envelope of a geometry.
86///
87/// The result may be a collapsed MBR.
88///
89/// @param[in] g The geometry.
90/// @param[in] srs The spatial reference system of the geometry.
91/// @param[out] mbr The envelope.
92void box_envelope(const Geometry *g, const dd::Spatial_reference_system *srs,
93 Box *mbr);
94
95/// Parse the input geometry, computes and returns the MBR
96///
97/// @param[in] thd The thread
98/// @param[in] knn_query_item The input geometry
99/// @param[out] coordinates The coordinates of the MBR
100///
101/// @return false if succeed, true in case of an error
102bool knn_query_to_mbr(THD *thd, Item *knn_query_item, double (&coordinates)[5]);
103
104} // namespace gis
105
106#endif // SQL_GIS_MBR_UTILS_H_INCLUDED
This file declares the Box class.
Definition: spatial.h:212
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: spatial_reference_system.h:52
This file declares the geometry class hierarchy used by the server as the internal representation of ...
This file declares the coordinate system specific subclasses of the geometry class hierarchy.
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Definition: area.cc:46
bool mbr_is_line(Box const &mbr)
Checks if an MBR represents a line.
Definition: mbr_utils.cc:72
bool knn_query_to_mbr(THD *thd, Item *knn_query_item, double(&coordinates)[5])
Parse the input geometry, computes and returns the MBR.
Definition: mbr_utils.cc:283
bool mbr_is_point(Box const &mbr)
Checks if an MBR represents a point.
Definition: mbr_utils.cc:67
bool mbrs_are_equal(Box const &mbr1, Box const &mbr2)
Checks if two MBRs are equal.
Definition: mbr_utils.cc:48
bool mbr_is_empty(Box const &mbr)
Checks if an MBR is empty.
Definition: mbr_utils.cc:62
void box_envelope(const Geometry *g, const dd::Spatial_reference_system *srs, Box *mbr)
Computes the envelope of a geometry.
Definition: mbr_utils.cc:269