1 #ifndef SQL_GIS_MBR_UTILS_H_INCLUDED
2 #define SQL_GIS_MBR_UTILS_H_INCLUDED
3 
4 // Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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"
35 #include "sql/gis/geometries_cs.h"
36 
37 namespace dd {
38 class Spatial_reference_system;
39 }  // namespace dd
40 
41 namespace gis {
42 
43 /// Checks if two MBRs are equal.
44 ///
45 /// Empty boxes are considered equal.
46 ///
47 /// @param[in] mbr1 First MBR.
48 /// @param[in] mbr2 Second MBR.
49 /// @retval true The MBRs are equal.
50 /// @retval false The MBRs are not equal.
51 bool mbrs_are_equal(Box const &mbr1, Box const &mbr2);
52 
53 /// Checks if an MBR is empty.
54 ///
55 /// By default, BG box coordinates are NaN. If a geometry is empty, its box will
56 /// have all NaN coordinates.
57 ///
58 /// @param[in] mbr MBR to check.
59 /// @retval true The MBR is empty.
60 /// @retval false The MBR is not empty.
61 bool mbr_is_empty(Box const &mbr);
62 
63 /// Checks if an MBR represents a point.
64 ///
65 /// Boxes around points collapse so that min_corner == max_corner.
66 ///
67 /// @param[in] mbr MBR to check.
68 /// @retval true The MBR is a point.
69 /// @retval false The MBR is not a point.
70 bool mbr_is_point(Box const &mbr);
71 
72 /// Checks if an MBR represents a line.
73 ///
74 /// Boxes around vertical and horizontal lines collapse so that either the
75 /// minimum and maximum X coordinate or Y coordinate are equal.
76 ///
77 /// @param[in] mbr MBR to check.
78 /// @retval true The MBR is a line.
79 /// @retval false The MBR is not a line.
80 bool mbr_is_line(Box const &mbr);
81 
82 /// Computes the envelope of a geometry.
83 ///
84 /// The result may be a collapsed MBR.
85 ///
86 /// @param[in] g The geometry.
87 /// @param[in] srs The spatial reference system of the geometry.
88 /// @param[out] mbr The envelope.
89 void box_envelope(const Geometry *g, const dd::Spatial_reference_system *srs,
90                   Box *mbr);
91 
92 }  // namespace gis
93 
94 #endif  // SQL_GIS_MBR_UTILS_H_INCLUDED
95