// Boost.Geometry (aka GGL, Generic Geometry Library) // // Copyright (c) 2007-2011 Barend Gehrels, 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 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian); template void test_distance(std::string const& wkt1, std::string const& wkt2, double expected) { Geometry1 g1; Geometry2 g2; bg::read_wkt(wkt1, g1); bg::read_wkt(wkt2, g2); typename bg::default_distance_result::type d = bg::distance(g1, g2); BOOST_CHECK_CLOSE(d, expected, 0.0001); } template void test_distance(Strategy const& strategy, std::string const& wkt1, std::string const& wkt2, double expected) { Geometry1 g1; Geometry2 g2; bg::read_wkt(wkt1, g1); bg::read_wkt(wkt2, g2); typename bg::default_distance_result::type d = bg::distance(g1, g2, strategy); BOOST_CHECK_CLOSE(d, expected, 0.0001); } template void test_2d() { typedef bg::model::multi_point

mp; typedef bg::model::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 bg::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 bg::model::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 bg::model::multi_point mp1; typedef bg::model::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 bg::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, bg::model::d2::point_xy >(); #ifdef HAVE_TTMATH test_2d >(); test_mixed, bg::model::d2::point_xy >(); #endif return 0; }