Skip to content

Commit cb59e0e

Browse files
committed
test: add test for rtree with strategies in undefined cs
1 parent cce708e commit cb59e0e

File tree

3 files changed

+160
-1
lines changed

3 files changed

+160
-1
lines changed

index/test/rtree/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Boost.Geometry
2+
# Copyright (c) 2025 Adam Wulkiewicz, Lodz, Poland.
23
# Copyright (c) 2024, Oracle and/or its affiliates.
34
# Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
45
# Use, modification and distribution is subject to the Boost Software License,
@@ -13,6 +14,7 @@ foreach(item IN ITEMS
1314
rtree_move_pack
1415
rtree_non_cartesian
1516
rtree_values
17+
rtree_with_strategies
1618
#compile-fail rtree_values_invalid
1719
)
1820
boost_geometry_add_unit_test("index" ${item})

index/test/rtree/Jamfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Boost.Geometry Index
22
#
3-
# Copyright (c) 2011-2016 Adam Wulkiewicz, Lodz, Poland.
3+
# Copyright (c) 2011-2025 Adam Wulkiewicz, Lodz, Poland.
44
#
55
# Use, modification and distribution is subject to the Boost Software License,
66
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -19,5 +19,6 @@ test-suite boost-geometry-index-rtree
1919
[ run rtree_move_pack.cpp ]
2020
[ run rtree_non_cartesian.cpp ]
2121
[ run rtree_values.cpp ]
22+
[ compile rtree_with_strategies.cpp ]
2223
[ compile-fail rtree_values_invalid.cpp ]
2324
;
+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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_box<typename Rtree::value_type>::value
31+
|| bg::util::is_box<QueryValue>::value
32+
&& bg::util::is_point<typename Rtree::value_type>::value;
33+
34+
template <typename QueryValue, typename Rtree>
35+
constexpr bool is_pb_or_bb_v = bg::util::is_box<QueryValue>::value
36+
&& bg::util::is_box<typename Rtree::value_type>::value
37+
|| bg::util::is_point<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_box<QueryValue>::value
42+
&& bg::util::is_box<typename Rtree::value_type>::value
43+
|| bg::util::is_point<QueryValue>::value
44+
&& bg::util::is_point<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+
std::vector<typename Rtree::value_type> values;
54+
rtree.query(bgi::covered_by(QueryValue{}), std::back_inserter(values));
55+
rtree.query(bgi::disjoint(QueryValue{}), std::back_inserter(values));
56+
rtree.query(bgi::within(QueryValue{}), std::back_inserter(values));
57+
}
58+
59+
template
60+
<
61+
typename QueryValue, typename Rtree,
62+
std::enable_if_t<(!is_bp_or_bb_v<QueryValue, Rtree>), int> = 0
63+
>
64+
void test_queries_bp_bb(Rtree const& ) {}
65+
66+
template
67+
<
68+
typename QueryValue, typename Rtree,
69+
std::enable_if_t<is_pb_or_bb_v<QueryValue, Rtree>, int> = 0
70+
>
71+
void test_queries_pb_bb(Rtree const& rtree)
72+
{
73+
// These predicates use algorithms that are not implemented for
74+
// some geometry combinations
75+
std::vector<typename Rtree::value_type> values;
76+
rtree.query(bgi::contains(QueryValue{}), std::back_inserter(values));
77+
rtree.query(bgi::covers(QueryValue{}), std::back_inserter(values));
78+
}
79+
80+
template
81+
<
82+
typename QueryValue, typename Rtree,
83+
std::enable_if_t<(!is_pb_or_bb_v<QueryValue, Rtree>), int> = 0
84+
>
85+
void test_queries_pb_bb(Rtree const& ) {}
86+
87+
template
88+
<
89+
typename QueryValue, typename Rtree,
90+
std::enable_if_t<is_pp_or_bb_v<QueryValue, Rtree>, int> = 0
91+
>
92+
void test_overlaps_pp_bb(Rtree const& rtree)
93+
{
94+
std::vector<typename Rtree::value_type> values;
95+
rtree.query(bgi::overlaps(QueryValue{}), std::back_inserter(values));
96+
rtree.query(bgi::touches(QueryValue{}), std::back_inserter(values));
97+
}
98+
99+
template
100+
<
101+
typename QueryValue, typename Rtree,
102+
std::enable_if_t<(!is_pp_or_bb_v<QueryValue, Rtree>), int> = 0
103+
>
104+
void test_overlaps_pp_bb(Rtree const& ) {}
105+
106+
template <typename QueryValue, typename Rtree>
107+
void test_queries(Rtree const& rtree)
108+
{
109+
std::vector<typename Rtree::value_type> values;
110+
rtree.query(bgi::intersects(QueryValue{}), std::back_inserter(values));
111+
rtree.query(bgi::nearest(QueryValue{}, 1), std::back_inserter(values));
112+
test_queries_bp_bb<QueryValue>(rtree);
113+
test_queries_pb_bb<QueryValue>(rtree);
114+
test_overlaps_pp_bb<QueryValue>(rtree);
115+
}
116+
117+
template <typename Value, typename Params, typename Strategies>
118+
void test_strategies()
119+
{
120+
std::vector<Value> values;
121+
bgi::rtree<Value, bgi::parameters<Params, Strategies>> rtree{values};
122+
rtree.insert(Value{});
123+
rtree.remove(Value{});
124+
125+
test_queries<point>(rtree);
126+
test_queries<box>(rtree);
127+
test_queries<segment>(rtree);
128+
}
129+
130+
template <typename Value, typename Params>
131+
void test_params()
132+
{
133+
test_strategies<Value, Params, bg::strategies::index::cartesian<>>();
134+
test_strategies<Value, Params, bg::strategies::cartesian<>>();
135+
test_strategies<Value, Params, bg::strategies::index::spherical<>>();
136+
test_strategies<Value, Params, bg::strategies::spherical<>>();
137+
test_strategies<Value, Params, bg::strategies::index::geographic<>>();
138+
test_strategies<Value, Params, bg::strategies::geographic<>>();
139+
}
140+
141+
template <typename Value>
142+
void test_value()
143+
{
144+
test_params<Value, bgi::linear<4>>();
145+
test_params<Value, bgi::quadratic<4>>();
146+
test_params<Value, bgi::rstar<4>>();
147+
}
148+
149+
int test_main(int, char* [])
150+
{
151+
test_value<point>();
152+
test_value<box>();
153+
test_value<segment>();
154+
155+
return 0;
156+
}

0 commit comments

Comments
 (0)