1 // Boost.Geometry Index
3 // R-tree boxes validating visitor implementation
5 // Copyright (c) 2011-2015 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;
63 Box box_exp = rtree::elements_box<Box>(elements.begin(), elements.end(), m_tr);
66 result = m_is_root || geometry::equals(box_exp, m_box);
68 result = m_is_root || geometry::covered_by(box_exp, m_box);
71 void operator()(leaf const& n)
73 typedef typename rtree::elements_type<leaf>::type elements_type;
74 elements_type const& elements = rtree::elements(n);
79 if ( elements.empty() )
85 Box box_exp = rtree::values_box<Box>(elements.begin(), elements.end(), m_tr);
88 result = geometry::equals(box_exp, m_box);
90 result = geometry::covered_by(box_exp, m_box);
99 Translator const& m_tr;
105 } // namespace visitors
107 template <typename Rtree> inline
108 bool are_boxes_ok(Rtree const& tree, bool exact_match = true)
110 typedef utilities::view<Rtree> RTV;
113 visitors::are_boxes_ok<
114 typename RTV::value_type,
115 typename RTV::options_type,
116 typename RTV::translator_type,
117 typename RTV::box_type,
118 typename RTV::allocators_type
119 > v(rtv.translator(), exact_match);
121 rtv.apply_visitor(v);
126 }}}}}} // namespace boost::geometry::index::detail::rtree::utilities
128 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_BOXES_OK_HPP