1 // Boost.Geometry Index
3 // R-tree boxes validating visitor implementation
5 // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_BOXES_OK_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_BOXES_OK_HPP
14 #include <boost/geometry/algorithms/equals.hpp>
15 #include <boost/geometry/index/detail/rtree/node/node.hpp>
17 namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
21 template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
23 : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
25 typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
26 typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
29 are_boxes_ok(Translator const& tr, bool exact_match)
30 : result(false), m_tr(tr), m_is_root(true), m_exact_match(exact_match)
33 void operator()(internal_node const& n)
35 typedef typename rtree::elements_type<internal_node>::type elements_type;
36 elements_type const& elements = rtree::elements(n);
44 Box box_bckup = m_box;
45 bool is_root_bckup = m_is_root;
49 for ( typename elements_type::const_iterator it = elements.begin();
50 it != elements.end() ; ++it)
54 rtree::apply_visitor(*this, *it->second);
56 if ( result == false )
61 m_is_root = is_root_bckup;
64 geometry::convert(elements.front().first, box_exp);
65 for( typename elements_type::const_iterator it = elements.begin() + 1;
66 it != elements.end() ; ++it)
68 geometry::expand(box_exp, it->first);
72 result = m_is_root || geometry::equals(box_exp, m_box);
74 result = m_is_root || geometry::covered_by(box_exp, m_box);
77 void operator()(leaf const& n)
79 typedef typename rtree::elements_type<leaf>::type elements_type;
80 elements_type const& elements = rtree::elements(n);
85 if ( elements.empty() )
93 index::detail::return_ref_or_bounds(m_tr(elements.front())),
95 for(typename elements_type::const_iterator it = elements.begin() + 1;
96 it != elements.end() ; ++it)
98 geometry::expand(box_exp, m_tr(*it));
102 result = geometry::equals(box_exp, m_box);
104 result = geometry::covered_by(box_exp, m_box);
113 Translator const& m_tr;
119 } // namespace visitors
121 template <typename Rtree> inline
122 bool are_boxes_ok(Rtree const& tree, bool exact_match = true)
124 typedef utilities::view<Rtree> RTV;
127 visitors::are_boxes_ok<
128 typename RTV::value_type,
129 typename RTV::options_type,
130 typename RTV::translator_type,
131 typename RTV::box_type,
132 typename RTV::allocators_type
133 > v(rtv.translator(), exact_match);
135 rtv.apply_visitor(v);
140 }}}}}} // namespace boost::geometry::index::detail::rtree::utilities
142 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_BOXES_OK_HPP