|
| 1 | +// Boost.Geometry Index |
| 2 | +// Unit Test |
| 3 | + |
| 4 | +// Copyright (c) 2025 Adam Wulkiewicz, Lodz, Poland. |
| 5 | + |
| 6 | +// Use, modification and distribution is subject to the Boost Software License, |
| 7 | +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 9 | + |
| 10 | +#include <vector> |
| 11 | + |
| 12 | +#define BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_PREDICATES |
| 13 | + |
| 14 | +#include <geometry_index_test_common.hpp> |
| 15 | + |
| 16 | +#include <boost/geometry/geometries/register/point.hpp> |
| 17 | +#include <boost/geometry/geometries/register/box.hpp> |
| 18 | +#include <boost/geometry/geometries/register/segment.hpp> |
| 19 | + |
| 20 | +struct point { double x, y; }; |
| 21 | +struct box { point mi, ma; }; |
| 22 | +struct segment { point first, second; }; |
| 23 | + |
| 24 | +BOOST_GEOMETRY_REGISTER_POINT_2D(point, double, cs::undefined, x, y) |
| 25 | +BOOST_GEOMETRY_REGISTER_BOX(box, point, mi, ma) |
| 26 | +BOOST_GEOMETRY_REGISTER_SEGMENT(segment, point, first, second) |
| 27 | + |
| 28 | +template <typename QueryValue, typename Rtree> |
| 29 | +constexpr bool is_bp_or_bb_v = (bg::util::is_box<QueryValue>::value |
| 30 | + && bg::util::is_point<typename Rtree::value_type>::value) |
| 31 | + || (bg::util::is_box<QueryValue>::value |
| 32 | + && bg::util::is_box<typename Rtree::value_type>::value); |
| 33 | + |
| 34 | +template <typename QueryValue, typename Rtree> |
| 35 | +constexpr bool is_pb_or_bb_v = (bg::util::is_point<QueryValue>::value |
| 36 | + && bg::util::is_box<typename Rtree::value_type>::value) |
| 37 | + || (bg::util::is_box<QueryValue>::value |
| 38 | + && bg::util::is_box<typename Rtree::value_type>::value); |
| 39 | + |
| 40 | +template <typename QueryValue, typename Rtree> |
| 41 | +constexpr bool is_pp_or_bb_v = (bg::util::is_point<QueryValue>::value |
| 42 | + && bg::util::is_point<typename Rtree::value_type>::value) |
| 43 | + || (bg::util::is_box<QueryValue>::value |
| 44 | + && bg::util::is_box<typename Rtree::value_type>::value); |
| 45 | + |
| 46 | +template |
| 47 | +< |
| 48 | + typename QueryValue, typename Rtree, |
| 49 | + std::enable_if_t<is_bp_or_bb_v<QueryValue, Rtree>, int> = 0 |
| 50 | +> |
| 51 | +void test_queries_bp_bb(Rtree const& rtree) |
| 52 | +{ |
| 53 | + // These predicates use algorithms that are not implemented for |
| 54 | + // some geometry combinations |
| 55 | + std::vector<typename Rtree::value_type> values; |
| 56 | + rtree.query(bgi::covered_by(QueryValue{}), std::back_inserter(values)); |
| 57 | + rtree.query(bgi::disjoint(QueryValue{}), std::back_inserter(values)); |
| 58 | + rtree.query(bgi::within(QueryValue{}), std::back_inserter(values)); |
| 59 | +} |
| 60 | + |
| 61 | +template |
| 62 | +< |
| 63 | + typename QueryValue, typename Rtree, |
| 64 | + std::enable_if_t<(!is_bp_or_bb_v<QueryValue, Rtree>), int> = 0 |
| 65 | +> |
| 66 | +void test_queries_bp_bb(Rtree const& ) {} |
| 67 | + |
| 68 | +template |
| 69 | +< |
| 70 | + typename QueryValue, typename Rtree, |
| 71 | + std::enable_if_t<is_pb_or_bb_v<QueryValue, Rtree>, int> = 0 |
| 72 | +> |
| 73 | +void test_queries_pb_bb(Rtree const& rtree) |
| 74 | +{ |
| 75 | + // These predicates use algorithms that are not implemented for |
| 76 | + // some geometry combinations |
| 77 | + std::vector<typename Rtree::value_type> values; |
| 78 | + rtree.query(bgi::contains(QueryValue{}), std::back_inserter(values)); |
| 79 | + rtree.query(bgi::covers(QueryValue{}), std::back_inserter(values)); |
| 80 | +} |
| 81 | + |
| 82 | +template |
| 83 | +< |
| 84 | + typename QueryValue, typename Rtree, |
| 85 | + std::enable_if_t<(!is_pb_or_bb_v<QueryValue, Rtree>), int> = 0 |
| 86 | +> |
| 87 | +void test_queries_pb_bb(Rtree const& ) {} |
| 88 | + |
| 89 | +template |
| 90 | +< |
| 91 | + typename QueryValue, typename Rtree, |
| 92 | + std::enable_if_t<is_pp_or_bb_v<QueryValue, Rtree>, int> = 0 |
| 93 | +> |
| 94 | +void test_queries_pp_bb(Rtree const& rtree) |
| 95 | +{ |
| 96 | + // These predicates use algorithms that are not implemented for |
| 97 | + // some geometry combinations |
| 98 | + std::vector<typename Rtree::value_type> values; |
| 99 | + rtree.query(bgi::overlaps(QueryValue{}), std::back_inserter(values)); |
| 100 | + rtree.query(bgi::touches(QueryValue{}), std::back_inserter(values)); |
| 101 | +} |
| 102 | + |
| 103 | +template |
| 104 | +< |
| 105 | + typename QueryValue, typename Rtree, |
| 106 | + std::enable_if_t<(!is_pp_or_bb_v<QueryValue, Rtree>), int> = 0 |
| 107 | +> |
| 108 | +void test_queries_pp_bb(Rtree const& ) {} |
| 109 | + |
| 110 | +template <typename QueryValue, typename Rtree> |
| 111 | +void test_queries(Rtree const& rtree) |
| 112 | +{ |
| 113 | + std::vector<typename Rtree::value_type> values; |
| 114 | + rtree.query(bgi::intersects(QueryValue{}), std::back_inserter(values)); |
| 115 | + rtree.query(bgi::nearest(QueryValue{}, 1), std::back_inserter(values)); |
| 116 | + test_queries_bp_bb<QueryValue>(rtree); |
| 117 | + test_queries_pb_bb<QueryValue>(rtree); |
| 118 | + test_queries_pp_bb<QueryValue>(rtree); |
| 119 | +} |
| 120 | + |
| 121 | +template <typename Value, typename Params, typename Strategies> |
| 122 | +void test_strategies() |
| 123 | +{ |
| 124 | + std::vector<Value> values; |
| 125 | + bgi::rtree<Value, bgi::parameters<Params, Strategies>> rtree{values}; |
| 126 | + rtree.insert(Value{}); |
| 127 | + rtree.remove(Value{}); |
| 128 | + |
| 129 | + test_queries<point>(rtree); |
| 130 | + test_queries<box>(rtree); |
| 131 | + test_queries<segment>(rtree); |
| 132 | +} |
| 133 | + |
| 134 | +template <typename Value, typename Params> |
| 135 | +void test_params() |
| 136 | +{ |
| 137 | + test_strategies<Value, Params, bg::strategies::index::cartesian<>>(); |
| 138 | + test_strategies<Value, Params, bg::strategies::cartesian<>>(); |
| 139 | + test_strategies<Value, Params, bg::strategies::index::spherical<>>(); |
| 140 | + test_strategies<Value, Params, bg::strategies::spherical<>>(); |
| 141 | + test_strategies<Value, Params, bg::strategies::index::geographic<>>(); |
| 142 | + test_strategies<Value, Params, bg::strategies::geographic<>>(); |
| 143 | +} |
| 144 | + |
| 145 | +template <typename Value> |
| 146 | +void test_value() |
| 147 | +{ |
| 148 | + test_params<Value, bgi::linear<4>>(); |
| 149 | + test_params<Value, bgi::quadratic<4>>(); |
| 150 | + test_params<Value, bgi::rstar<4>>(); |
| 151 | +} |
| 152 | + |
| 153 | +int test_main(int, char* []) |
| 154 | +{ |
| 155 | + test_value<point>(); |
| 156 | + test_value<box>(); |
| 157 | + test_value<segment>(); |
| 158 | + |
| 159 | + return 0; |
| 160 | +} |
0 commit comments