// Boost.Geometry (aka GGL, Generic Geometry Library) // // Copyright Barend Gehrels, Geodan B.V. Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include #include #include #include #include #include #include #include template void test_distance(const std::string& wkt1, const std::string& wkt2, double expected) { Geometry1 g1; Geometry2 g2; boost::geometry::read_wkt(wkt1, g1); boost::geometry::read_wkt(wkt2, g2); double d = boost::geometry::distance(g1, g2); BOOST_CHECK_CLOSE(d, expected, 0.0001); } template void test_distance(const Strategy& strategy, const std::string& wkt1, const std::string& wkt2, double expected) { Geometry1 g1; Geometry2 g2; boost::geometry::read_wkt(wkt1, g1); boost::geometry::read_wkt(wkt2, g2); double d = boost::geometry::distance(g1, g2, strategy); BOOST_CHECK_CLOSE(d, expected, 0.0001); } template void test_2d() { typedef boost::geometry::multi_point

mp; typedef boost::geometry::multi_linestring > ml; test_distance("POINT(0 0)", "POINT(1 1)", sqrt(2.0)); test_distance("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); test_distance("MULTIPOINT((1 1),(1 0),(0 2))", "MULTIPOINT((2 2),(2 3))", sqrt(2.0)); test_distance("POINT(0 0)", "MULTILINESTRING((1 1,2 2),(1 0,2 0),(0 2,0 3))", 1.0); test_distance("MULTILINESTRING((1 1,2 2),(1 0,2 0),(0 2,0 3))", "POINT(0 0)", 1.0); test_distance("MULTILINESTRING((1 1,2 2),(1 0,2 0),(0 2,0 3))", "MULTIPOINT((0 0),(1 1))", 0.0); // Test with a strategy boost::geometry::strategy::distance::pythagoras pyth; test_distance(pyth, "POINT(0 0)", "POINT(1 1)", sqrt(2.0)); test_distance(pyth, "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance(pyth, "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); } template void test_3d() { typedef boost::geometry::multi_point

mp; test_distance("POINT(0 0 0)", "POINT(1 1 1)", sqrt(3.0)); test_distance("POINT(0 0 0)", "MULTIPOINT((1 1 1),(1 0 0),(0 1 2))", 1.0); test_distance("MULTIPOINT((1 1 1),(1 0 0),(0 0 2))", "MULTIPOINT((2 2 2),(2 3 4))", sqrt(3.0)); } template void test_mixed() { typedef boost::geometry::multi_point mp1; typedef boost::geometry::multi_point mp2; test_distance("POINT(0 0)", "POINT(1 1)", sqrt(2.0)); test_distance("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); // Test automatic reversal test_distance("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); test_distance("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); test_distance("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); test_distance("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); // Test multi-multi using different point types for each test_distance("MULTIPOINT((1 1),(1 0),(0 2))", "MULTIPOINT((2 2),(2 3))", sqrt(2.0)); // Test with a strategy using namespace boost::geometry::strategy::distance; test_distance(pythagoras(), "POINT(0 0)", "POINT(1 1)", sqrt(2.0)); test_distance(pythagoras(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance(pythagoras(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance(pythagoras(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); test_distance(pythagoras(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0); // Most interesting: reversal AND a strategy (note that the stategy must be reversed automatically test_distance(pythagoras(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); test_distance(pythagoras(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); test_distance(pythagoras(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); test_distance(pythagoras(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0); } int test_main( int , char* [] ) { test_2d >(); test_2d >(); test_2d >(); test_3d >(); test_3d >(); test_mixed, boost::geometry::point_xy >(); return 0; }