MySQL  8.0.26
Source Code Documentation
box.h
Go to the documentation of this file.
1 #ifndef SQL_GIS_BOX_H_INCLUDED
2 #define SQL_GIS_BOX_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 Box class.
29 ///
30 /// @see box_cs.h
31 
32 #include "sql/gis/geometries.h"
33 #include "sql/gis/geometries_cs.h"
34 
35 namespace gis {
36 
37 /// A 2d box with sides parallel to the coordinate system grid.
38 ///
39 /// Used by computations on minimum bounding boxes (MBRs).
40 class Box {
41  public:
42  Box() = default;
43  Box(const Box &) = default;
44  Box(Box &&) = default;
45  Box &operator=(const Box &) = default;
46  Box &operator=(Box &&) = default;
47 
48  virtual ~Box() = default;
49 
50  /// Gets the coordinate system.
51  ///
52  /// @return The coordiante system type.
53  virtual Coordinate_system coordinate_system() const = 0;
54 
55  /// Returns the minimum corner.
56  ///
57  /// @return The minimum corner.
58  virtual Point const &min_corner() const = 0;
59  virtual Point &min_corner() = 0;
60 
61  /// Returns the maximum corner.
62  ///
63  /// @return The maximum corner.
64  virtual Point const &max_corner() const = 0;
65  virtual Point &max_corner() = 0;
66 };
67 
68 /// A Cartesian 2d box.
69 class Cartesian_box : public Box {
70  private:
71  /// The corner with minimum X and Y values.
73  /// The corner with maximum X and Y values.
75 
76  public:
77  Cartesian_box() = default;
82  }
83 
84  /// Returns the minimum corner.
85  ///
86  /// @return The minimum corner.
87  Cartesian_point const &min_corner() const override { return m_min_corner; }
88  Cartesian_point &min_corner() override { return m_min_corner; }
89 
90  /// Returns the maximum corner.
91  ///
92  /// @return The maximum corner.
93  Cartesian_point const &max_corner() const override { return m_max_corner; }
94  Cartesian_point &max_corner() override { return m_max_corner; }
95 };
96 
97 /// A Geographic 2d box.
98 ///
99 /// Unlike polygons, the sides of the box are not the shortest distance between
100 /// the endpoints. A box side will follow the latitude line, while a linestring
101 /// (or polygon segment) between the same points won't.
102 class Geographic_box : public Box {
103  private:
104  /// The corner with minimum X and Y values.
106  /// The corner with maximum X and Y values.
108 
109  public:
110  Geographic_box() = default;
115  }
116 
117  /// Returns the minimum corner.
118  ///
119  /// @return The minimum corner.
120  Geographic_point const &min_corner() const override { return m_min_corner; }
121  Geographic_point &min_corner() override { return m_min_corner; }
122 
123  /// Returns the maximum corner.
124  ///
125  /// @return The maximum corner.
126  Geographic_point const &max_corner() const override { return m_max_corner; }
127  Geographic_point &max_corner() override { return m_max_corner; }
128 };
129 
130 } // namespace gis
131 
132 #endif // SQL_GIS_BOX_H_INCLUDED
A 2d box with sides parallel to the coordinate system grid.
Definition: box.h:40
virtual Point & max_corner()=0
virtual ~Box()=default
virtual Point const & min_corner() const =0
Returns the minimum corner.
virtual Point & min_corner()=0
Box(const Box &)=default
Box(Box &&)=default
virtual Coordinate_system coordinate_system() const =0
Gets the coordinate system.
Box & operator=(const Box &)=default
Box & operator=(Box &&)=default
virtual Point const & max_corner() const =0
Returns the maximum corner.
Box()=default
A Cartesian 2d box.
Definition: box.h:69
Cartesian_point & max_corner() override
Definition: box.h:94
Cartesian_point const & max_corner() const override
Returns the maximum corner.
Definition: box.h:93
Cartesian_box(Cartesian_point &&min_corner, Cartesian_point &&max_corner)
Definition: box.h:78
Cartesian_point & min_corner() override
Definition: box.h:88
Cartesian_point m_max_corner
The corner with maximum X and Y values.
Definition: box.h:74
Coordinate_system coordinate_system() const override
Gets the coordinate system.
Definition: box.h:80
Cartesian_box()=default
Cartesian_point const & min_corner() const override
Returns the minimum corner.
Definition: box.h:87
Cartesian_point m_min_corner
The corner with minimum X and Y values.
Definition: box.h:72
A Cartesian 2d point.
Definition: geometries_cs.h:46
A Geographic 2d box.
Definition: box.h:102
Geographic_box(Geographic_point &&min_corner, Geographic_point &&max_corner)
Definition: box.h:111
Geographic_point const & min_corner() const override
Returns the minimum corner.
Definition: box.h:120
Geographic_point & min_corner() override
Definition: box.h:121
Geographic_point m_min_corner
The corner with minimum X and Y values.
Definition: box.h:105
Geographic_point const & max_corner() const override
Returns the maximum corner.
Definition: box.h:126
Geographic_point & max_corner() override
Definition: box.h:127
Geographic_box()=default
Coordinate_system coordinate_system() const override
Gets the coordinate system.
Definition: box.h:113
Geographic_point m_max_corner
The corner with maximum X and Y values.
Definition: box.h:107
A geographic (ellipsoidal) 2d point.
Definition: geometries_cs.h:57
A 2d point.
Definition: geometries.h:149
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.
Definition: area.cc:46
Coordinate_system
Types of coordinate systems.
Definition: geometries.h:68
@ kCartesian
A Cartesian plane with the same unit in both directions.
@ kGeographic
An ellipsoidal system with longitude and latitude coordinates, both in the same unit.