side_of_intersection.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2011-2015 Barend Gehrels, Amsterdam, the Netherlands.
  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 <geometry_test_common.hpp>
  8. #include <boost/geometry/strategies/cartesian/side_of_intersection.hpp>
  9. #include <boost/geometry/geometries/point_xy.hpp>
  10. #include <boost/geometry/geometries/segment.hpp>
  11. namespace bg = boost::geometry;
  12. int test_main(int, char* [])
  13. {
  14. typedef bg::model::d2::point_xy<boost::long_long_type> point;
  15. typedef bg::model::segment<point> segment;
  16. typedef bg::strategy::side::side_of_intersection side;
  17. point no_fb(-99, -99);
  18. segment a(point(20, 10), point(10, 20));
  19. segment b1(point(11, 16), point(20, 14)); // IP with a: (14.857, 15.143)
  20. segment b2(point(10, 16), point(20, 14)); // IP with a: (15, 15)
  21. segment c1(point(15, 16), point(13, 8));
  22. segment c2(point(15, 16), point(14, 8));
  23. segment c3(point(15, 16), point(15, 8));
  24. BOOST_CHECK_EQUAL( 1, side::apply(a, b1, c1, no_fb));
  25. BOOST_CHECK_EQUAL(-1, side::apply(a, b1, c2, no_fb));
  26. BOOST_CHECK_EQUAL(-1, side::apply(a, b1, c3, no_fb));
  27. BOOST_CHECK_EQUAL( 1, side::apply(a, b2, c1, no_fb));
  28. BOOST_CHECK_EQUAL( 1, side::apply(a, b2, c2, no_fb));
  29. BOOST_CHECK_EQUAL( 0, side::apply(a, b2, c3, no_fb));
  30. // Collinear cases
  31. // 1: segments intersecting are collinear (with a fallback point):
  32. {
  33. point fb(5, 5);
  34. segment col1(point(0, 5), point(5, 5));
  35. segment col2(point(5, 5), point(10, 5)); // One IP with col1 at (5,5)
  36. segment col3(point(5, 0), point(5, 5));
  37. BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
  38. }
  39. // 2: segment of side calculation collinear with one of the segments
  40. {
  41. point fb(5, 5);
  42. segment col1(point(0, 5), point(10, 5));
  43. segment col2(point(5, 5), point(5, 12)); // IP with col1 at (5,5)
  44. segment col3(point(5, 1), point(5, 5)); // collinear with col2
  45. BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
  46. }
  47. {
  48. point fb(5, 5);
  49. segment col1(point(10, 5), point(0, 5));
  50. segment col2(point(5, 5), point(5, 12)); // IP with col1 at (5,5)
  51. segment col3(point(5, 1), point(5, 5)); // collinear with col2
  52. BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
  53. }
  54. {
  55. point fb(5, 5);
  56. segment col1(point(0, 5), point(10, 5));
  57. segment col2(point(5, 12), point(5, 5)); // IP with col1 at (5,5)
  58. segment col3(point(5, 1), point(5, 5)); // collinear with col2
  59. BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
  60. }
  61. {
  62. point fb(517248, -517236);
  63. segment col1(point(-172408, -517236), point(862076, -517236));
  64. segment col2(point(517248, -862064), point(517248, -172408));
  65. segment col3(point(517248, -172408), point(517248, -517236));
  66. BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
  67. }
  68. {
  69. point fb(-221647, -830336);
  70. segment col1(point(-153817, -837972), point(-222457, -830244));
  71. segment col2(point(-221139, -833615), point(-290654, -384388));
  72. segment col3(point(-255266, -814663), point(-264389, -811197));
  73. BOOST_CHECK_EQUAL(1, side::apply(col1, col2, col3, fb)); // Left of segment...
  74. }
  75. {
  76. point fb(27671131, 30809240);
  77. segment col1(point(27671116, 30809247), point(27675474, 30807351));
  78. segment col2(point(27666779, 30811130), point(27671139, 30809237));
  79. segment col3(point(27671122, 30809244), point(27675480, 30807348));
  80. BOOST_CHECK_EQUAL(1, side::apply(col1, col2, col3, fb)); // Left of segment...
  81. }
  82. // TODO: we might add a check calculating the IP, determining the side
  83. // with the normal side strategy, and verify the results are equal
  84. return 0;
  85. }