MySQL 9.0.0
Source Code Documentation
ring_flip_visitor.h
Go to the documentation of this file.
1#ifndef SQL_GIS_RING_FLIP_VISITOR_H_INCLUDED
2#define SQL_GIS_RING_FLIP_VISITOR_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#include <boost/geometry.hpp>
28#include <memory> // std::unique_ptr
29
30#include "sql/dd/types/spatial_reference_system.h" // dd::Spatial_reference_system
34
35namespace gis {
36
37/// A visitor that flips polygon rings so that exterior rings are in a
38/// counter-clockwise direction and interior rings in a clockwise direction.
39///
40/// Invalid polygon rings are not guaranteed to be flipped to the correct
41/// direction.
43 private:
44 /// Strategy used for geographic SRSs.
45 std::unique_ptr<boost::geometry::strategy::area::geographic<>>
47 /// Whether the geometry is invalid. That happens either if the ellipsoid of
48 /// a geographic SRS is invalid or if we encounter a ring with unknown
49 /// direction.
51
52 public:
53 /// Construct a new ring flip visitor.
54 ///
55 /// @param[in] semi_major The semi-major axis of the ellipsoid.
56 /// @param[in] semi_minor The semi-minor axis of the ellipsoid.
57 Ring_flip_visitor(double semi_major, double semi_minor) {
58 try {
60 new boost::geometry::strategy::area::geographic<>(
61 boost::geometry::srs::spheroid<double>(semi_major, semi_minor)));
62 m_invalid = false;
63 } catch (...) {
64 // Spheroid construction may fail if the axes are invalid.
65 m_invalid = true;
66 }
67 }
68
69 /// Check if anything wrong has been detected, either an invalid ellipsoid or
70 /// a ring with an unknown direction.
71 ///
72 /// Polygon rings which direction can't be determined are invalid. This is the
73 /// only way this visitor detects invalid rings. Other invalid rings, e.g.,
74 /// rings crossing themselves, are not necessarily detected.
75 ///
76 /// @retval true Invalid SRS ellipsoid or invalid polygon ring.
77 /// @retval false No invalid rings detected, but the geometry may still be
78 /// invalid.
79 bool invalid() const { return m_invalid; }
80
82 bool visit_enter(Polygon *py) override;
83 bool visit_enter(Multipolygon *py) override;
84
85 bool visit_enter(Multipoint *) override {
86 return true; // Don't descend into each point.
87 }
88
89 bool visit_enter(Multilinestring *) override {
90 return true; // Don't descend into each linestring.
91 }
92};
93
94} // namespace gis
95
96#endif // SQL_GIS_RING_FLIP_VISITOR_H_INCLUDED
A collection of linestrings.
Definition: geometries.h:523
A collection of points.
Definition: geometries.h:484
A collection of polygons.
Definition: geometries.h:564
A visitor that implements the entire interface and does nothing.
Definition: geometry_visitor.h:122
bool visit_enter(Geometry *) override
Enters a compound geometry.
Definition: geometry_visitor.h:124
A polygon consisting of an outer ring and zero or more interior rings defining holes in the polygon.
Definition: geometries.h:349
A visitor that flips polygon rings so that exterior rings are in a counter-clockwise direction and in...
Definition: ring_flip_visitor.h:42
bool visit_enter(Polygon *py) override
Definition: ring_flip_visitor.cc:34
bool visit_enter(Multilinestring *) override
Definition: ring_flip_visitor.h:89
std::unique_ptr< boost::geometry::strategy::area::geographic<> > m_geographic_strategy
Strategy used for geographic SRSs.
Definition: ring_flip_visitor.h:46
bool visit_enter(Multipoint *) override
Definition: ring_flip_visitor.h:85
bool m_invalid
Whether the geometry is invalid.
Definition: ring_flip_visitor.h:50
bool invalid() const
Check if anything wrong has been detected, either an invalid ellipsoid or a ring with an unknown dire...
Definition: ring_flip_visitor.h:79
Ring_flip_visitor(double semi_major, double semi_minor)
Construct a new ring flip visitor.
Definition: ring_flip_visitor.h:57
This file declares the coordinate system specific subclasses of the geometry class hierarchy.
This file contains Boost.Geometry type traits declarations for Cartesian and geographic geometries.
The geometries implement a hierarchical visitor pattern.
Definition: area.cc:47