distance_ca_pl_pl.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2014-2018, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  5. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  6. // Licensed under the Boost Software License version 1.0.
  7. // http://www.boost.org/users/license.html
  8. #include <iostream>
  9. #ifndef BOOST_TEST_MODULE
  10. #define BOOST_TEST_MODULE test_distance_cartesian_pointlike_pointlike
  11. #endif
  12. #include <boost/test/included/unit_test.hpp>
  13. #include "test_distance_common.hpp"
  14. #include "test_empty_geometry.hpp"
  15. typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
  16. typedef bg::model::multi_point<point_type> multi_point_type;
  17. namespace services = bg::strategy::distance::services;
  18. typedef bg::default_distance_result<point_type>::type return_type;
  19. typedef bg::strategy::distance::pythagoras<> point_point_strategy;
  20. //===========================================================================
  21. template <typename Strategy>
  22. void test_distance_point_point(Strategy const& strategy)
  23. {
  24. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  25. std::cout << std::endl;
  26. std::cout << "point/point distance tests" << std::endl;
  27. #endif
  28. typedef test_distance_of_geometries<point_type, point_type> tester;
  29. tester::apply("point(1 1)",
  30. "point(0 0)",
  31. sqrt(2.0), 2, strategy);
  32. tester::apply("point(1 1)",
  33. "point(1 1)",
  34. 0, 0, strategy);
  35. // distance overflows
  36. tester::apply("point(0 0)",
  37. "point(4.297374e+307 8.433875e+307)",
  38. 0, 0, strategy, false);
  39. }
  40. //===========================================================================
  41. template <typename Strategy>
  42. void test_distance_point_multipoint(Strategy const& strategy)
  43. {
  44. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  45. std::cout << std::endl;
  46. std::cout << "point/multipoint distance tests" << std::endl;
  47. #endif
  48. typedef test_distance_of_geometries<point_type, multi_point_type> tester;
  49. tester::apply("point(1 1)",
  50. "multipoint(1 1,2 1,2 2,1 2)",
  51. 0, 0, strategy);
  52. tester::apply("point(1 1)",
  53. "multipoint(2 2,2 3,3 2,3 3)",
  54. sqrt(2.0), 2, strategy);
  55. tester::apply("point(3 0)",
  56. "multipoint(2 2,2 4,4 2,4 4)",
  57. sqrt(5.0), 5, strategy);
  58. }
  59. //===========================================================================
  60. template <typename Strategy>
  61. void test_distance_multipoint_multipoint(Strategy const& strategy)
  62. {
  63. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  64. std::cout << std::endl;
  65. std::cout << "multipoint/multipoint distance tests" << std::endl;
  66. #endif
  67. typedef test_distance_of_geometries
  68. <
  69. multi_point_type, multi_point_type
  70. > tester;
  71. tester::apply("multipoint(0 0,1 0,0 1,1 1)",
  72. "multipoint(1 1,2 1,2 2,1 2)",
  73. 0, 0, strategy);
  74. tester::apply("multipoint(0 0,1 0,0 1,1 1)",
  75. "multipoint(2 2,2 3,3 2,3 3)",
  76. sqrt(2.0), 2, strategy);
  77. }
  78. //===========================================================================
  79. BOOST_AUTO_TEST_CASE( test_all_point_point )
  80. {
  81. test_distance_point_point(point_point_strategy());
  82. }
  83. BOOST_AUTO_TEST_CASE( test_all_point_multipoint )
  84. {
  85. test_distance_point_multipoint(point_point_strategy());
  86. }
  87. BOOST_AUTO_TEST_CASE( test_all_multipoint_multipoint )
  88. {
  89. test_distance_multipoint_multipoint(point_point_strategy());
  90. }
  91. BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_pointlike )
  92. {
  93. test_more_empty_input_pointlike_pointlike
  94. <
  95. point_type
  96. >(point_point_strategy());
  97. }