123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556 |
- // Boost.Geometry (aka GGL, Generic Geometry Library)
- // Unit Test
- // Copyright (c) 2014-2018, Oracle and/or its affiliates.
- // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
- // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
- // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
- // Licensed under the Boost Software License version 1.0.
- // http://www.boost.org/users/license.html
- #include <iostream>
- #ifndef BOOST_TEST_MODULE
- #define BOOST_TEST_MODULE test_distance_spherical_equatorial_pointlike_linear
- #endif
- #include <boost/test/included/unit_test.hpp>
- #include "test_distance_se_common.hpp"
- #include "test_empty_geometry.hpp"
- typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
- typedef bg::model::point<double, 2, cs_type> point_type;
- typedef bg::model::segment<point_type> segment_type;
- typedef bg::model::multi_point<point_type> multi_point_type;
- typedef bg::model::segment<point_type> segment_type;
- typedef bg::model::linestring<point_type> linestring_type;
- typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
- namespace services = bg::strategy::distance::services;
- typedef bg::default_distance_result<point_type>::type return_type;
- typedef bg::strategy::distance::haversine<double> point_point_strategy;
- typedef bg::strategy::distance::cross_track<> point_segment_strategy;
- //===========================================================================
- template <typename Strategy>
- inline bg::default_distance_result<point_type>::type
- pp_distance(std::string const& wkt1,
- std::string const& wkt2,
- Strategy const& strategy)
- {
- point_type p1, p2;
- bg::read_wkt(wkt1, p1);
- bg::read_wkt(wkt2, p2);
- return bg::distance(p1, p2) * strategy.radius();
- }
- template <typename Strategy>
- inline bg::default_comparable_distance_result<point_type>::type
- pp_comparable_distance(std::string const& wkt1,
- std::string const& wkt2,
- Strategy const&)
- {
- point_type p1, p2;
- bg::read_wkt(wkt1, p1);
- bg::read_wkt(wkt2, p2);
- return bg::comparable_distance(p1, p2);
- }
- template <typename Strategy>
- inline bg::default_distance_result<point_type>::type
- ps_distance(std::string const& wkt1,
- std::string const& wkt2,
- Strategy const& strategy)
- {
- point_type p;
- segment_type s;
- bg::read_wkt(wkt1, p);
- bg::read_wkt(wkt2, s);
- return bg::distance(p, s, strategy);
- }
- template <typename Strategy>
- inline bg::default_comparable_distance_result<point_type>::type
- ps_comparable_distance(std::string const& wkt1,
- std::string const& wkt2,
- Strategy const& strategy)
- {
- point_type p;
- segment_type s;
- bg::read_wkt(wkt1, p);
- bg::read_wkt(wkt2, s);
- return bg::comparable_distance(p, s, strategy);
- }
- template <typename Strategy, typename T>
- T to_comparable(Strategy const& strategy, T const& distance)
- {
- namespace services = bg::strategy::distance::services;
- typedef typename services::comparable_type
- <
- Strategy
- >::type comparable_strategy;
- typedef typename services::result_from_distance
- <
- comparable_strategy,
- point_type,
- bg::point_type<segment_type>::type
- > get_comparable_distance;
- comparable_strategy cstrategy = services::get_comparable
- <
- Strategy
- >::apply(strategy);
- return get_comparable_distance::apply(cstrategy, distance);
- }
- //===========================================================================
- template <typename Strategy>
- void test_distance_point_segment(Strategy const& strategy)
- {
- #ifdef BOOST_GEOMETRY_TEST_DEBUG
- std::cout << std::endl;
- std::cout << "point/segment distance tests" << std::endl;
- #endif
- typedef test_distance_of_geometries<point_type, segment_type> tester;
- double const d2r = bg::math::d2r<double>();
- tester::apply("p-s-01",
- "POINT(0 0)",
- "SEGMENT(2 0,3 0)",
- 2.0 * d2r * strategy.radius(),
- to_comparable(strategy, 2.0 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-s-02",
- "POINT(2.5 3)",
- "SEGMENT(2 0,3 0)",
- 3.0 * d2r * strategy.radius(),
- to_comparable(strategy, 3.0 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-s-03",
- "POINT(2 0)",
- "SEGMENT(2 0,3 0)",
- 0,
- strategy);
- tester::apply("p-s-04",
- "POINT(3 0)",
- "SEGMENT(2 0,3 0)",
- 0,
- strategy);
- tester::apply("p-s-05",
- "POINT(2.5 0)",
- "SEGMENT(2 0,3 0)",
- 0,
- strategy);
- tester::apply("p-s-06",
- "POINT(3.5 3)",
- "SEGMENT(2 0,3 0)",
- pp_distance("POINT(3 0)", "POINT(3.5 3)", strategy),
- pp_comparable_distance("POINT(3 0)",
- "POINT(3.5 3)",
- strategy),
- strategy);
- tester::apply("p-s-07",
- "POINT(0 0)",
- "SEGMENT(0 10,10 10)",
- ps_distance("POINT(0 0)", "SEGMENT(10 10,0 10)", strategy),
- pp_comparable_distance("POINT(0 0)",
- "POINT(0 10)",
- strategy),
- strategy);
- // very small distances to segment
- tester::apply("p-s-07",
- "POINT(90 1e-3)",
- "SEGMENT(0.5 0,175.5 0)",
- 1e-3 * d2r * strategy.radius(),
- to_comparable(strategy, 1e-3 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-s-08",
- "POINT(90 1e-4)",
- "SEGMENT(0.5 0,175.5 0)",
- 1e-4 * d2r * strategy.radius(),
- to_comparable(strategy, 1e-4 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-s-09",
- "POINT(90 1e-5)",
- "SEGMENT(0.5 0,175.5 0)",
- 1e-5 * d2r * strategy.radius(),
- to_comparable(strategy, 1e-5 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-s-10",
- "POINT(90 1e-6)",
- "SEGMENT(0.5 0,175.5 0)",
- 1e-6 * d2r * strategy.radius(),
- to_comparable(strategy, 1e-6 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-s-11",
- "POINT(90 1e-7)",
- "SEGMENT(0.5 0,175.5 0)",
- 1e-7 * d2r * strategy.radius(),
- to_comparable(strategy, 1e-7 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-s-12",
- "POINT(90 1e-8)",
- "SEGMENT(0.5 0,175.5 0)",
- 1e-8 * d2r * strategy.radius(),
- to_comparable(strategy, 1e-8 * d2r * strategy.radius()),
- strategy);
- }
- //===========================================================================
- template <typename Strategy>
- void test_distance_point_linestring(Strategy const& strategy)
- {
- #ifdef BOOST_GEOMETRY_TEST_DEBUG
- std::cout << std::endl;
- std::cout << "point/linestring distance tests" << std::endl;
- #endif
- typedef test_distance_of_geometries<point_type, linestring_type> tester;
- double const r = strategy.radius();
- double const d2r = bg::math::d2r<double>();
- tester::apply("p-l-01",
- "POINT(0 0)",
- "LINESTRING(2 0,2 0)",
- 2.0 * d2r * r,
- to_comparable(strategy, 2.0 * d2r * r),
- strategy);
- tester::apply("p-l-02",
- "POINT(0 0)",
- "LINESTRING(2 0,3 0)",
- 2.0 * d2r * r,
- to_comparable(strategy, 2.0 * d2r * r),
- strategy);
- tester::apply("p-l-03",
- "POINT(2.5 3)",
- "LINESTRING(2 0,3 0)",
- 3.0 * d2r * r,
- to_comparable(strategy, 3.0 * d2r * r),
- strategy);
- tester::apply("p-l-04",
- "POINT(2 0)",
- "LINESTRING(2 0,3 0)",
- 0,
- strategy);
- tester::apply("p-l-05",
- "POINT(3 0)",
- "LINESTRING(2 0,3 0)",
- 0,
- strategy);
- tester::apply("p-l-06",
- "POINT(2.5 0)",
- "LINESTRING(2 0,3 0)",
- 0,
- strategy);
- tester::apply("p-l-07",
- "POINT(7.5 10)",
- "LINESTRING(1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 0)",
- 10.0 * d2r * r,
- to_comparable(strategy, 10.0 * d2r * r),
- strategy);
- tester::apply("p-l-08",
- "POINT(7.5 10)",
- "LINESTRING(1 1,2 1,3 1,4 1,5 1,6 1,7 1,20 2,21 2)",
- ps_distance("POINT(7.5 10)", "SEGMENT(7 1,20 2)", strategy),
- ps_comparable_distance("POINT(7.5 10)",
- "SEGMENT(7 1,20 2)",
- strategy),
- strategy);
- // https://svn.boost.org/trac/boost/ticket/11982
- tester::apply("p-l-09",
- "POINT(10.4 63.43)",
- "LINESTRING(10.733557 59.911923, 10.521812 59.887214)",
- 0.06146397739758279 * r,
- 0.000944156107132969,
- strategy);
- //https://github.com/boostorg/geometry/issues/557
- tester::apply("p-l-issue557",
- "POINT(51.99999790563572 43.71656981636763)",
- "LINESTRING(52.0000243071011 43.716569742012496,\
- 52.0000121532845 43.71656942616241,\
- 52.0 43.7165690998572,\
- 51.999987847203 43.7165687638793)",
- 1.35062e-08 * r,
- 4.5604e-17,
- strategy);
- }
- //===========================================================================
- template <typename Strategy>
- void test_distance_point_multilinestring(Strategy const& strategy)
- {
- #ifdef BOOST_GEOMETRY_TEST_DEBUG
- std::cout << std::endl;
- std::cout << "point/multilinestring distance tests" << std::endl;
- #endif
- typedef test_distance_of_geometries
- <
- point_type, multi_linestring_type
- > tester;
- double const d2r = bg::math::d2r<double>();
- tester::apply("p-ml-01",
- "POINT(0 0)",
- "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
- 2.0 * d2r * strategy.radius(),
- to_comparable(strategy, 2.0 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-ml-02",
- "POINT(2.5 3)",
- "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
- 3.0 * d2r * strategy.radius(),
- to_comparable(strategy, 3.0 * d2r * strategy.radius()),
- strategy);
- tester::apply("p-ml-03",
- "POINT(2 0)",
- "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
- 0,
- strategy);
- tester::apply("p-ml-04",
- "POINT(3 0)",
- "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
- 0,
- strategy);
- tester::apply("p-ml-05",
- "POINT(2.5 0)",
- "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
- 0,
- strategy);
- tester::apply("p-ml-06",
- "POINT(7.5 10)",
- "MULTILINESTRING((-5 0,-3 0),(2 0,3 0,4 0,5 0,6 0,20 1,21 1))",
- ps_distance("POINT(7.5 10)", "SEGMENT(6 0,20 1)", strategy),
- ps_comparable_distance("POINT(7.5 10)",
- "SEGMENT(6 0,20 1)",
- strategy),
- strategy);
- tester::apply("p-ml-07",
- "POINT(-8 10)",
- "MULTILINESTRING((-20 10,-19 11,-18 10,-6 0,-5 0,-3 0),(2 0,6 0,20 1,21 1))",
- ps_distance("POINT(-8 10)", "SEGMENT(-6 0,-18 10)", strategy),
- ps_comparable_distance("POINT(-8 10)",
- "SEGMENT(-6 0,-18 10)",
- strategy),
- strategy);
- }
- //===========================================================================
- template <typename Strategy>
- void test_distance_linestring_multipoint(Strategy const& strategy)
- {
- #ifdef BOOST_GEOMETRY_TEST_DEBUG
- std::cout << std::endl;
- std::cout << "linestring/multipoint distance tests" << std::endl;
- #endif
- typedef test_distance_of_geometries
- <
- linestring_type, multi_point_type
- > tester;
- tester::apply("l-mp-01",
- "LINESTRING(2 0,0 2,100 80)",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy),
- ps_comparable_distance("POINT(1 1)",
- "SEGMENT(2 0,0 2)",
- strategy),
- strategy);
- tester::apply("l-mp-02",
- "LINESTRING(4 0,0 4,100 80)",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- ps_distance("POINT(1 1)", "SEGMENT(0 4,4 0)", strategy),
- ps_comparable_distance("POINT(1 1)",
- "SEGMENT(0 4,4 0)",
- strategy),
- strategy);
- tester::apply("l-mp-03",
- "LINESTRING(1 1,2 2,100 80)",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- 0,
- strategy);
- tester::apply("l-mp-04",
- "LINESTRING(3 3,4 4,100 80)",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- pp_distance("POINT(1 1)", "POINT(3 3)", strategy),
- pp_comparable_distance("POINT(1 1)", "POINT(3 3)", strategy),
- strategy);
- tester::apply("l-mp-05",
- "LINESTRING(0 0,10 0,10 10,0 10,0 0)",
- "MULTIPOINT(1 -1,80 80,5 0,150 90)",
- 0,
- strategy);
- }
- //===========================================================================
- template <typename Strategy>
- void test_distance_multipoint_multilinestring(Strategy const& strategy)
- {
- #ifdef BOOST_GEOMETRY_TEST_DEBUG
- std::cout << std::endl;
- std::cout << "multipoint/multilinestring distance tests" << std::endl;
- #endif
- typedef test_distance_of_geometries
- <
- multi_point_type, multi_linestring_type
- > tester;
- tester::apply("mp-ml-01",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "MULTILINESTRING((2 0,0 2),(2 2,3 3))",
- ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy),
- ps_comparable_distance("POINT(1 1)",
- "SEGMENT(2 0,0 2)",
- strategy),
- strategy);
- tester::apply("mp-ml-02",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "MULTILINESTRING((3 0,0 3),(4 4,5 5))",
- ps_distance("POINT(1 1)", "SEGMENT(3 0,0 3)", strategy),
- ps_comparable_distance("POINT(1 1)",
- "SEGMENT(3 0,0 3)",
- strategy),
- strategy);
- tester::apply("mp-ml-03",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "MULTILINESTRING((4 4,5 5),(1 1,2 2))",
- 0,
- strategy);
- tester::apply("mp-ml-04",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "MULTILINESTRING((4 4,3 3),(4 4,5 5))",
- pp_distance("POINT(1 1)", "POINT(3 3)", strategy),
- pp_comparable_distance("POINT(1 1)", "POINT(3 3)", strategy),
- strategy);
- }
- //===========================================================================
- template <typename Strategy>
- void test_distance_multipoint_segment(Strategy const& strategy)
- {
- #ifdef BOOST_GEOMETRY_TEST_DEBUG
- std::cout << std::endl;
- std::cout << "multipoint/segment distance tests" << std::endl;
- #endif
- typedef test_distance_of_geometries<multi_point_type, segment_type> tester;
- double d2r = bg::math::d2r<double>();
- tester::apply("mp-s-01",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "SEGMENT(2 0,0 2)",
- ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy),
- ps_comparable_distance("POINT(1 1)",
- "SEGMENT(2 0,0 2)",
- strategy),
- strategy);
- tester::apply("mp-s-02",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "SEGMENT(0 -3,1 -10)",
- 3.0 * d2r * strategy.radius(),
- to_comparable(strategy, 3.0 * d2r * strategy.radius()),
- strategy);
- tester::apply("mp-s-03",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "SEGMENT(1 1,2 2)",
- 0,
- strategy);
- tester::apply("mp-s-04",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "SEGMENT(3 3,4 4)",
- pp_distance("POINT(1 1)", "POINT(3 3)", strategy),
- pp_comparable_distance("POINT(1 1)", "POINT(3 3)", strategy),
- strategy);
- tester::apply("mp-s-05",
- "MULTIPOINT(0 0,1 0,0 1,1 1)",
- "SEGMENT(0.5 -3,1 -10)",
- pp_distance("POINT(1 0)", "POINT(0.5 -3)", strategy),
- pp_comparable_distance("POINT(1 0)",
- "POINT(0.5 -3)",
- strategy),
- strategy);
- }
- //===========================================================================
- //===========================================================================
- //===========================================================================
- BOOST_AUTO_TEST_CASE( test_all_pointlike_linear )
- {
- test_distance_point_segment(point_segment_strategy());
- test_distance_point_segment(point_segment_strategy(earth_radius_km));
- test_distance_point_segment(point_segment_strategy(earth_radius_miles));
- }
- BOOST_AUTO_TEST_CASE( test_all_point_linestring )
- {
- test_distance_point_linestring(point_segment_strategy());
- test_distance_point_linestring(point_segment_strategy(earth_radius_km));
- test_distance_point_linestring(point_segment_strategy(earth_radius_miles));
- }
- BOOST_AUTO_TEST_CASE( test_all_point_multilinestring )
- {
- test_distance_point_multilinestring(point_segment_strategy());
- test_distance_point_multilinestring(point_segment_strategy(earth_radius_km));
- test_distance_point_multilinestring(point_segment_strategy(earth_radius_miles));
- }
- BOOST_AUTO_TEST_CASE( test_all_linestring_multipoint )
- {
- test_distance_linestring_multipoint(point_segment_strategy());
- test_distance_linestring_multipoint(point_segment_strategy(earth_radius_km));
- test_distance_linestring_multipoint(point_segment_strategy(earth_radius_miles));
- }
- BOOST_AUTO_TEST_CASE( test_all_multipoint_multilinestring )
- {
- test_distance_multipoint_multilinestring(point_segment_strategy());
- test_distance_multipoint_multilinestring(point_segment_strategy(earth_radius_km));
- test_distance_multipoint_multilinestring(point_segment_strategy(earth_radius_miles));
- }
- BOOST_AUTO_TEST_CASE( test_all_multipoint_segment )
- {
- test_distance_multipoint_segment(point_segment_strategy());
- test_distance_multipoint_segment(point_segment_strategy(earth_radius_km));
- test_distance_multipoint_segment(point_segment_strategy(earth_radius_miles));
- }
- BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_linear )
- {
- test_more_empty_input_pointlike_linear
- <
- point_type
- >(point_segment_strategy());
- test_more_empty_input_pointlike_linear
- <
- point_type
- >(point_segment_strategy(earth_radius_km));
- test_more_empty_input_pointlike_linear
- <
- point_type
- >(point_segment_strategy(earth_radius_miles));
- }
|