expand.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2017.
  7. // Modifications copyright (c) 2017, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #include "test_expand.hpp"
  15. #include <boost/geometry/algorithms/make.hpp>
  16. #include <boost/geometry/geometries/geometries.hpp>
  17. #include <boost/geometry/geometries/adapted/c_array.hpp>
  18. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  19. #include <boost/geometry/geometries/adapted/std_pair_as_segment.hpp>
  20. #include <test_common/test_point.hpp>
  21. BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
  22. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  23. template <typename Point>
  24. void test_point_3d()
  25. {
  26. bg::model::box<Point> b = bg::make_inverse<bg::model::box<Point> >();
  27. test_expand<Point>(b, "POINT(1 2 5)", "(1,2,5),(1,2,5)");
  28. test_expand<Point>(b, "POINT(3 4 6)", "(1,2,5),(3,4,6)");
  29. test_expand<Point>(b, "POINT(4 4 5)", "(1,2,5),(4,4,6)");
  30. test_expand<Point>(b, "POINT(4 5 5)", "(1,2,5),(4,5,6)");
  31. test_expand<Point>(b, "POINT(10 10 4)", "(1,2,4),(10,10,6)");
  32. test_expand<Point>(b, "POINT(9 9 4)", "(1,2,4),(10,10,6)");
  33. test_expand<Point>(b, "POINT(0 2 7)", "(0,2,4),(10,10,7)");
  34. test_expand<Point>(b, "POINT(0 0 7)", "(0,0,4),(10,10,7)");
  35. test_expand<Point>(b, "POINT(-1 -1 5)", "(-1,-1,4),(10,10,7)");
  36. test_expand<Point>(b, "POINT(0 0 5)", "(-1,-1,4),(10,10,7)");
  37. test_expand<Point>(b, "POINT(15 -1 0)", "(-1,-1,0),(15,10,7)");
  38. test_expand<Point>(b, "POINT(-1 15 10)", "(-1,-1,0),(15,15,10)");
  39. }
  40. template <typename Point>
  41. void test_box_3d()
  42. {
  43. typedef bg::model::box<Point> box_type;
  44. box_type b = bg::make_inverse<box_type>();
  45. test_expand<box_type>(b, "BOX(0 2 5,4 4 6)", "(0,2,5),(4,4,6)");
  46. test_expand<box_type>(b, "BOX(0 1 5,4 6 6)", "(0,1,5),(4,6,6)");
  47. test_expand<box_type>(b, "BOX(-1 -1 6,10 10 5)", "(-1,-1,5),(10,10,6)");
  48. test_expand<box_type>(b, "BOX(3 3 6,3 3 5)", "(-1,-1,5),(10,10,6)");
  49. test_expand<box_type>(b, "BOX(3 15 7,-1 3 4)", "(-1,-1,4),(10,15,7)");
  50. test_expand<box_type>(b, "BOX(-15 3 7,3 20 4)", "(-15,-1,4),(10,20,7)");
  51. test_expand<box_type>(b, "BOX(3 -20 8,3 20 3)", "(-15,-20,3),(10,20,8)");
  52. test_expand<box_type>(b, "BOX(-20 3 8,20 3 3)", "(-20,-20,3),(20,20,8)");
  53. }
  54. template <typename P>
  55. void test_3d()
  56. {
  57. test_point_3d<P>();
  58. test_box_3d<P>();
  59. }
  60. template <typename Point>
  61. void test_2d()
  62. {
  63. typedef bg::model::box<Point> box_type;
  64. typedef std::pair<Point, Point> segment_type;
  65. box_type b = bg::make_inverse<box_type>();
  66. test_expand<box_type>(b, "BOX(1 1,2 2)", "(1,1),(2,2)");
  67. // Test an 'incorrect' box -> should also correctly update the bbox
  68. test_expand<box_type>(b, "BOX(3 4,0 1)", "(0,1),(3,4)");
  69. // Test a segment
  70. test_expand<segment_type>(b, "SEGMENT(5 6,7 8)", "(0,1),(7,8)");
  71. }
  72. template <typename Point>
  73. void test_spherical_degree()
  74. {
  75. // it doesn't work with normalization of input enabled
  76. //bg::model::box<Point> b = bg::make_inverse<bg::model::box<Point> >();
  77. Point p;
  78. bg::read_wkt("POINT(179.73 71.56)", p);
  79. bg::model::box<Point> b(p, p);
  80. test_expand<Point>(b, "POINT(179.73 71.56)",
  81. "(179.73,71.56),(179.73,71.56)");
  82. test_expand<Point>(b, "POINT(177.47 71.23)",
  83. "(177.47,71.23),(179.73,71.56)");
  84. // It detects that this point is lying RIGHT of the others,
  85. // and then it "expands" it.
  86. test_expand<Point>(b, "POINT(-178.78 70.78)",
  87. "(177.47,70.78),(181.22,71.56)");
  88. }
  89. template <typename Point>
  90. void test_spherical_radian()
  91. {
  92. // it doesn't work with normalization of input enabled
  93. //bg::model::box<Point> b = bg::make_inverse<bg::model::box<Point> >();
  94. Point p;
  95. bg::read_wkt("POINT(3.128 1.249)", p);
  96. bg::model::box<Point> b(p, p);
  97. test_expand<Point>(b, "POINT(3.128 1.249)",
  98. "(3.128,1.249),(3.128,1.249)");
  99. test_expand<Point>(b, "POINT(3.097 1.243)",
  100. "(3.097,1.243),(3.128,1.249)");
  101. // It detects that this point is lying RIGHT of the others,
  102. // and then it "expands" it.
  103. test_expand<Point>(b, "POINT(-3.121 1.235)",
  104. "(3.097,1.235),(3.16219,1.249)");
  105. }
  106. int test_main(int, char* [])
  107. {
  108. test_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
  109. test_3d<test::test_point>();
  110. test_3d<bg::model::point<int, 3, bg::cs::cartesian> >();
  111. test_3d<bg::model::point<float, 3, bg::cs::cartesian> >();
  112. test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
  113. test_spherical_degree<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >();
  114. test_spherical_radian<bg::model::point<double, 2, bg::cs::spherical<bg::radian> > >();
  115. test_spherical_degree<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  116. test_spherical_radian<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::radian> > >();
  117. #if defined(HAVE_TTMATH)
  118. test_3d<bg::model::point<ttmath_big, 3, bg::cs::cartesian> >();
  119. test_spherical_degree<bg::model::point<ttmath_big, 2, bg::cs::spherical<bg::degree> > >();
  120. test_spherical_radian<bg::model::point<ttmath_big, 2, bg::cs::spherical<bg::radian> > >();
  121. #endif
  122. return 0;
  123. }