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