Skip to content

Commit

Permalink
geometry.index test, example: updated tests and benchmark_experimenta…
Browse files Browse the repository at this point in the history
…l for path_intersection of 2-point linestring.

git-svn-id: http://svn.boost.org/svn/boost/trunk@84238 b8fc166d-592f-0410-95f2-cb63ce0dd405
  • Loading branch information
awulkiew committed May 11, 2013
1 parent afbc9a9 commit 1b62683
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
23 changes: 22 additions & 1 deletion libs/geometry/index/example/benchmark_experimental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ int main()
size_t queries_count = 100000;
size_t nearest_queries_count = 10000;
unsigned neighbours_count = 10;
size_t path_queries_count = 1000;
size_t path_queries_count = 2000;
size_t path_queries_count2 = 10000;
unsigned path_values_count = 10;

float max_val = static_cast<float>(values_count / 2);
Expand Down Expand Up @@ -284,6 +285,26 @@ int main()
dur_t time = clock_t::now() - start;
std::cout << time << " - query(path(LS, " << path_values_count << ")) " << path_queries_count << " found " << temp << '\n';
}

{
LS ls;
ls.resize(2);

clock_t::time_point start = clock_t::now();
size_t temp = 0;
for (size_t i = 0 ; i < path_queries_count2 ; ++i )
{
float x = coords[i].first;
float y = coords[i].second;
ls[0] = P(x, y);
ls[1] = P(x+max_val/100, y+max_val/100);
result.clear();
t.query(bgi::path(ls, path_values_count), std::back_inserter(result));
temp += result.size();
}
dur_t time = clock_t::now() - start;
std::cout << time << " - query(path(LS, " << path_values_count << ")) " << path_queries_count2 << " found " << temp << '\n';
}
#endif
{
clock_t::time_point start = clock_t::now();
Expand Down
18 changes: 10 additions & 8 deletions libs/geometry/index/test/algorithms/path_intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ int test_main(int, char* [])
typedef bg::model::linestring<P3fc> L3fc;
typedef bg::model::linestring<P3dc> L3dc;

test_geometry<bg::model::box<P2ic>, L2ic>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, ::sqrt(29.0f)/5);
test_geometry<bg::model::box<P2fc>, L2fc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, ::sqrt(29.0f)/5);
test_geometry<bg::model::box<P2dc>, L2dc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, ::sqrt(29.0)/5);
test_geometry<bg::model::box<P3ic>, L3ic>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, ::sqrt(78.0f)*2.0f/7);
test_geometry<bg::model::box<P3fc>, L3fc>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, ::sqrt(78.0f)*2.0f/7);
test_geometry<bg::model::box<P3dc>, L3dc>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, ::sqrt(78.0)*2.0/7);
// IMPORTANT! For 2-point linestrings comparable distance optimization is enabled!

test_geometry<bg::model::box<P2ic>, L2ic>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, 1.0f/5);
test_geometry<bg::model::box<P2fc>, L2fc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, 1.0f/5);
test_geometry<bg::model::box<P2dc>, L2dc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, 1.0/5);
test_geometry<bg::model::box<P3ic>, L3ic>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, 2.0f/7);
test_geometry<bg::model::box<P3fc>, L3fc>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, 2.0f/7);
test_geometry<bg::model::box<P3dc>, L3dc>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, 2.0/7);

test_geometry<bg::model::box<P2fc>, L2fc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 1 0, 1 5)", true, 2);
test_geometry<bg::model::box<P2fc>, L2fc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 3 0, 3 2, 0 2)", true, 6);
Expand All @@ -107,8 +109,8 @@ int test_main(int, char* [])
typedef bg::model::linestring<P2ttmc> L2ttmc;
typedef bg::model::linestring<P3ttmc> L3ttmc;

test_geometry<bg::model::box<P2ttmc>, L2ttmc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, ::sqrt(29.0f)/5);
test_geometry<bg::model::box<P3ttmc>, L3ttmc>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, ::sqrt(78.0f)*2.0f/7);
test_geometry<bg::model::box<P2ttmc>, L2ttmc>("POLYGON((0 1,2 4))", "LINESTRING(0 0, 2 5)", true, 1.0/5);
test_geometry<bg::model::box<P3ttmc>, L3ttmc>("POLYGON((0 1 2,2 4 6))", "LINESTRING(0 0 0, 2 5 7)", true, 2.0/7);
#endif

test_large_integers();
Expand Down
22 changes: 11 additions & 11 deletions libs/geometry/index/test/algorithms/segment_intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@

//#include <boost/geometry/io/wkt/read.hpp>

template <typename Box, typename Point>
template <typename Box, typename Point, typename RelativeDistance>
void test_segment_intersection(Box const& box, Point const& p0, Point const& p1,
bool expected_result,
typename bgi::detail::default_relative_distance_type<Box, Point>::type expected_rel_dist)
RelativeDistance expected_rel_dist)
{
typename bgi::detail::default_relative_distance_type<Box, Point>::type rel_dist;
RelativeDistance rel_dist;
bool value = bgi::detail::segment_intersection(box, p0, p1, rel_dist);
BOOST_CHECK(value == expected_result);
if ( value && expected_result )
BOOST_CHECK_CLOSE(rel_dist, expected_rel_dist, 0.0001);
}

template <typename Box, typename Point>
template <typename Box, typename Point, typename RelativeDistance>
void test_geometry(std::string const& wkt_g, std::string const& wkt_p0, std::string const& wkt_p1,
bool expected_result,
typename bgi::detail::default_relative_distance_type<Box, Point>::type expected_rel_dist)
RelativeDistance expected_rel_dist)
{
Box box;
bg::read_wkt(wkt_g, box);
Expand Down Expand Up @@ -106,14 +106,14 @@ int test_main(int, char* [])
test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(0 5)", "POINT(0 0)", true, 0.2f);
test_geometry<bg::model::box<P2dc>, P2dc>("POLYGON((0 1,2 4))", "POINT(0 0)", "POINT(0 5)", true, 0.2);

test_geometry<bg::model::box<P2ic>, P2ic>("POLYGON((0 1,2 4))", "POINT(3 0)", "POINT(3 5)", false, 0);
test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(3 5)", "POINT(3 0)", false, 0);
test_geometry<bg::model::box<P2dc>, P2dc>("POLYGON((0 1,2 4))", "POINT(3 0)", "POINT(3 5)", false, 0);
test_geometry<bg::model::box<P2ic>, P2ic>("POLYGON((0 1,2 4))", "POINT(3 0)", "POINT(3 5)", false, 0.0f);
test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(3 5)", "POINT(3 0)", false, 0.0f);
test_geometry<bg::model::box<P2dc>, P2dc>("POLYGON((0 1,2 4))", "POINT(3 0)", "POINT(3 5)", false, 0.0);

test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(1 0)", "POINT(1 1)", true, 1);
test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(1 4)", "POINT(1 5)", true, 0);
test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(1 0)", "POINT(1 1)", true, 1.0f);
test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(1 4)", "POINT(1 5)", true, 0.0f);

test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(0.5 2)", "POINT(1.5 3)", true, 0);
test_geometry<bg::model::box<P2fc>, P2fc>("POLYGON((0 1,2 4))", "POINT(0.5 2)", "POINT(1.5 3)", true, 0.0f);

#ifdef HAVE_TTMATH
typedef bg::model::point<ttmath_big, 2, bg::cs::cartesian> P2ttmc;
Expand Down

0 comments on commit 1b62683

Please sign in to comment.