covered_by_sph_geo.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Boost.Geometry
  2. // Copyright (c) 2016 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include "test_covered_by.hpp"
  8. #include <boost/geometry/geometries/geometries.hpp>
  9. template <typename P>
  10. void test_point_box()
  11. {
  12. typedef bg::model::box<P> box_t;
  13. test_geometry<P, box_t>("POINT(0 0)", "BOX(0 0, 1 1)", true);
  14. test_geometry<P, box_t>("POINT(1 1)", "BOX(0 0, 2 2)", true);
  15. test_geometry<P, box_t>("POINT(180 1)", "BOX(170 0, 190 2)", true);
  16. test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 190 2)", true);
  17. test_geometry<P, box_t>("POINT(180 1)", "BOX(170 0, 180 2)", true);
  18. test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 180 2)", true);
  19. test_geometry<P, box_t>("POINT(179 1)", "BOX(170 0, 190 2)", true);
  20. test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 190 2)", true);
  21. test_geometry<P, box_t>("POINT(179 1)", "BOX(170 0, 180 2)", true);
  22. test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 180 2)", false);
  23. test_geometry<P, box_t>("POINT(169 1)", "BOX(170 0, 180 2)", false);
  24. // https://svn.boost.org/trac/boost/ticket/12412
  25. test_geometry<P, box_t>("POINT(-0.127592 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
  26. // and related
  27. test_geometry<P, box_t>("POINT(-2.08882 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
  28. test_geometry<P, box_t>("POINT(0.127592 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
  29. test_geometry<P, box_t>("POINT(2.08882 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
  30. test_geometry<P, box_t>("POINT(179.08882 1)", "BOX(179.08882 0, 538.127592 2)", true);
  31. test_geometry<P, box_t>("POINT(178.127592 1)", "BOX(179.08882 0, 538.127592 2)", true);
  32. test_geometry<P, box_t>("POINT(179.08882 1)", "BOX(179.08882 0, 182.127592 2)", true);
  33. test_geometry<P, box_t>("POINT(-177.872408 1)", "BOX(179.08882 0, 182.127592 2)", true);
  34. }
  35. template <typename P>
  36. void test_box_box()
  37. {
  38. typedef bg::model::box<P> box_t;
  39. test_geometry<box_t, box_t>("BOX(0 0, 1 1)", "BOX(0 0, 1 1)", true);
  40. test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(-180 0, 180 1)", true);
  41. test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(170 0, 200 1)", true);
  42. test_geometry<box_t, box_t>("BOX(-170 0,-150 1)", "BOX(170 0, 200 1)", false);
  43. test_geometry<box_t, box_t>("BOX(0 0,1 1)", "BOX(170 0, 370 1)", true);
  44. test_geometry<box_t, box_t>("BOX(0 0,10 1)", "BOX(170 0, 370 1)", true);
  45. test_geometry<box_t, box_t>("BOX(-180 0,10 1)", "BOX(170 0, 370 1)", true);
  46. test_geometry<box_t, box_t>("BOX(-180 0,20 1)", "BOX(170 0, 370 1)", false);
  47. test_geometry<box_t, box_t>("BOX(10 0,20 1)", "BOX(170 0, 370 1)", false);
  48. test_geometry<box_t, box_t>("BOX(160 0,180 1)", "BOX(170 0, 370 1)", false);
  49. test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 190 1)", true); // invalid?
  50. test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 191 1)", true); // invalid?
  51. test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(179 0, 190 1)", true);
  52. test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(181 0, 190 1)", false); // invalid?
  53. test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 189 1)", false); // invalid?
  54. // Related to https://svn.boost.org/trac/boost/ticket/12412
  55. test_geometry<box_t, box_t>("BOX(-1.346346 51.6, -0.127592 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
  56. test_geometry<box_t, box_t>("BOX(-2.08882 51.6, -1.346346 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
  57. test_geometry<box_t, box_t>("BOX(0.127592 51.6, 1.346346 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
  58. test_geometry<box_t, box_t>("BOX(1.346346 51.6, 2.08882 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
  59. test_geometry<box_t, box_t>("BOX(179.08882 1, 180.0 1)", "BOX(179.08882 0, 538.127592 2)", true);
  60. test_geometry<box_t, box_t>("BOX(177.0 1, 178.127592 1)", "BOX(179.08882 0, 538.127592 2)", true);
  61. test_geometry<box_t, box_t>("BOX(179.08882 1, 179.9 1)", "BOX(179.08882 0, 182.127592 2)", true);
  62. test_geometry<box_t, box_t>("BOX(-179.9 1, -177.872408 1)", "BOX(179.08882 0, 182.127592 2)", true);
  63. }
  64. template <typename P>
  65. void test_point_polygon()
  66. {
  67. typename boost::mpl::if_
  68. <
  69. boost::is_same<typename bg::cs_tag<P>::type, bg::geographic_tag>,
  70. bg::strategy::within::geographic_winding<P>,
  71. bg::strategy::within::spherical_winding<P>
  72. >::type s;
  73. typedef bg::model::polygon<P> poly;
  74. // MySQL report 08.2017
  75. test_geometry<P, poly>("POINT(-179 0)",
  76. "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
  77. false);
  78. test_geometry<P, poly>("POINT(-179 0)",
  79. "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
  80. false,
  81. s);
  82. test_geometry<P, poly>("POINT(1 0)",
  83. "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
  84. true);
  85. test_geometry<P, poly>("POINT(1 0)",
  86. "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
  87. true,
  88. s);
  89. }
  90. template <typename P>
  91. void test_cs()
  92. {
  93. test_point_box<P>();
  94. test_box_box<P>();
  95. test_point_polygon<P>();
  96. }
  97. int test_main( int , char* [] )
  98. {
  99. test_cs<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  100. test_cs<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
  101. #if defined(HAVE_TTMATH)
  102. test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  103. test_cs<bg::model::point<ttmath_big, 2, bg::cs::geographic<bg::degree> > >();;
  104. #endif
  105. return 0;
  106. }