1 /* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 #include "item_geofunc_internal.h"
24
25 // adaptors
26 #include <boost/range/adaptor/indexed.hpp>
27 #include <boost/range/adaptor/transformed.hpp>
28 #include <boost/range/adaptor/filtered.hpp>
29
30
31 struct Rtree_value_maker
32 {
33 typedef std::pair<BG_box, size_t> result_type;
34 template<typename T>
operator ()Rtree_value_maker35 result_type operator()(T const &v) const
36 {
37 BG_box box;
38 make_bg_box(v.value(), &box);
39 return result_type(box, v.index());
40 }
41 };
42
43
44 struct Is_rtree_box_valid
45 {
46 typedef std::pair<BG_box, size_t> Rtree_entry;
operator ()Is_rtree_box_valid47 bool operator()(Rtree_entry const& re) const
48 {
49 return is_box_valid(re.first);
50 }
51 };
52
53
54 void
make_rtree(const BG_geometry_collection::Geometry_list & gl,Rtree_index * rtree)55 make_rtree(const BG_geometry_collection::Geometry_list &gl,
56 Rtree_index *rtree)
57 {
58 Rtree_index temp_rtree(gl | boost::adaptors::indexed() |
59 boost::adaptors::transformed(Rtree_value_maker()) |
60 boost::adaptors::filtered(Is_rtree_box_valid()));
61
62 rtree->swap(temp_rtree);
63 }
64
65
66 /*
67 A functor to make an rtree value entry from an array element of
68 Boost.Geometry model type.
69 */
70 struct Rtree_value_maker_bggeom
71 {
72 typedef std::pair<BG_box, size_t> result_type;
73 template<typename T>
operator ()Rtree_value_maker_bggeom74 result_type operator()(T const &v) const
75 {
76 BG_box box = boost::geometry::return_envelope<BG_box>(v.value());
77 return result_type(box, v.index());
78 }
79 };
80
81
82 template <typename MultiGeometry>
83 void
make_rtree_bggeom(const MultiGeometry & mg,Rtree_index * rtree)84 make_rtree_bggeom(const MultiGeometry &mg,
85 Rtree_index *rtree)
86 {
87 Rtree_index temp_rtree(mg | boost::adaptors::indexed() |
88 boost::adaptors::
89 transformed(Rtree_value_maker_bggeom()) |
90 boost::adaptors::filtered(Is_rtree_box_valid()));
91
92 rtree->swap(temp_rtree);
93 }
94
95
96 // Explicit template instantiation
97 template
98 void make_rtree_bggeom<Gis_multi_line_string>(const Gis_multi_line_string&,
99 Rtree_index*);
100 template
101 void make_rtree_bggeom<Gis_multi_point>(const Gis_multi_point&,
102 Rtree_index*);
103
104 template
105 void make_rtree_bggeom<Gis_multi_polygon>(const Gis_multi_polygon&,
106 Rtree_index *);
107