disjoint_point_box_geometry.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2015.
  7. // Modifications copyright (c) 2015, 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_disjoint.hpp"
  15. #include <boost/geometry/geometries/geometries.hpp>
  16. #include <boost/geometry/geometries/point_xy.hpp>
  17. #include <boost/geometry/strategies/strategies.hpp>
  18. #include <test_common/test_point.hpp>
  19. #include <algorithms/overlay/overlay_cases.hpp>
  20. #include <algorithms/predef_relop.hpp>
  21. template <typename P>
  22. void test_all()
  23. {
  24. typedef bg::model::box<P> box;
  25. test_disjoint<P, P>("pp1", "point(1 1)", "point(1 1)", false);
  26. test_disjoint<P, P>("pp2", "point(1 1)", "point(1.001 1)", true);
  27. // left-right
  28. test_disjoint<box, box>("bb1", "box(1 1, 2 2)", "box(3 1, 4 2)", true);
  29. test_disjoint<box, box>("bb2", "box(1 1, 2 2)", "box(2 1, 3 2)", false);
  30. test_disjoint<box, box>("bb3", "box(1 1, 2 2)", "box(2 2, 3 3)", false);
  31. test_disjoint<box, box>("bb4", "box(1 1, 2 2)", "box(2.001 2, 3 3)", true);
  32. // up-down
  33. test_disjoint<box, box>("bb5", "box(1 1, 2 2)", "box(1 3, 2 4)", true);
  34. test_disjoint<box, box>("bb6", "box(1 1, 2 2)", "box(1 2, 2 3)", false);
  35. // right-left
  36. test_disjoint<box, box>("bb7", "box(1 1, 2 2)", "box(0 1, 1 2)", false);
  37. test_disjoint<box, box>("bb8", "box(1 1, 2 2)", "box(0 1, 1 2)", false);
  38. // point-box
  39. test_disjoint<P, box>("pb1", "point(1 1)", "box(0 0, 2 2)", false);
  40. test_disjoint<P, box>("pb2", "point(2 2)", "box(0 0, 2 2)", false);
  41. test_disjoint<P, box>("pb3", "point(2.0001 2)", "box(1 1, 2 2)", true);
  42. test_disjoint<P, box>("pb4", "point(0.9999 2)", "box(1 1, 2 2)", true);
  43. // box-point (to test reverse compiling)
  44. test_disjoint<box, P>("bp1", "box(1 1, 2 2)", "point(2 2)", false);
  45. // Test triangles for polygons/rings, boxes
  46. // Note that intersections are tested elsewhere, they don't need
  47. // thorough test at this place
  48. typedef bg::model::polygon<P> polygon;
  49. typedef bg::model::ring<P> ring;
  50. // Testing overlap (and test compiling with box)
  51. test_disjoint<polygon, polygon>("overlaps_box_pp", overlaps_box[0], overlaps_box[1], false);
  52. test_disjoint<box, polygon>("overlaps_box_bp", overlaps_box[0], overlaps_box[1], false);
  53. test_disjoint<box, ring>("overlaps_box_br", overlaps_box[0], overlaps_box[1], false);
  54. test_disjoint<polygon, box>("overlaps_box_pb", overlaps_box[1], overlaps_box[0], false);
  55. test_disjoint<ring, box>("overlaps_box_rb", overlaps_box[1], overlaps_box[0], false);
  56. test_disjoint<P, ring>("point_ring1", "POINT(0 0)", "POLYGON((0 0,3 3,6 0,0 0))", false);
  57. test_disjoint<P, ring>("point_ring2", "POINT(3 1)", "POLYGON((0 0,3 3,6 0,0 0))", false);
  58. test_disjoint<P, ring>("point_ring3", "POINT(0 3)", "POLYGON((0 0,3 3,6 0,0 0))", true);
  59. test_disjoint<P, polygon>("point_polygon1", "POINT(0 0)", "POLYGON((0 0,3 3,6 0,0 0))", false);
  60. test_disjoint<P, polygon>("point_polygon2", "POINT(3 1)", "POLYGON((0 0,3 3,6 0,0 0))", false);
  61. test_disjoint<P, polygon>("point_polygon3", "POINT(0 3)", "POLYGON((0 0,3 3,6 0,0 0))", true);
  62. test_disjoint<ring, P>("point_ring2", "POLYGON((0 0,3 3,6 0,0 0))", "POINT(0 0)", false);
  63. test_disjoint<polygon, P>("point_polygon2", "POLYGON((0 0,3 3,6 0,0 0))", "POINT(0 0)", false);
  64. // Problem described by Volker/Albert 2012-06-01
  65. test_disjoint<polygon, box>("volker_albert_1",
  66. "POLYGON((1992 3240,1992 1440,3792 1800,3792 3240,1992 3240))",
  67. "BOX(1941 2066, 2055 2166)", false);
  68. test_disjoint<polygon, box>("volker_albert_2",
  69. "POLYGON((1941 2066,2055 2066,2055 2166,1941 2166))",
  70. "BOX(1941 2066, 2055 2166)", false);
  71. }
  72. template <typename P>
  73. void test_3d()
  74. {
  75. typedef bg::model::box<P> box;
  76. test_disjoint<P, P>("pp 3d 1", "point(1 1 1)", "point(1 1 1)", false);
  77. test_disjoint<P, P>("pp 3d 2", "point(1 1 1)", "point(1.001 1 1)", true);
  78. test_disjoint<box, box>("bb1", "box(1 1 1, 2 2 2)", "box(3 1 1, 4 2 1)", true);
  79. test_disjoint<box, box>("bb2", "box(1 1 1, 2 2 2)", "box(2 1 1, 3 2 1)", false);
  80. test_disjoint<box, box>("bb3", "box(1 1 1, 2 2 2)", "box(2 2 1, 3 3 1)", false);
  81. test_disjoint<box, box>("bb4", "box(1 1 1, 2 2 2)", "box(2.001 2 1, 3 3 1)", true);
  82. }
  83. int test_main(int, char* [])
  84. {
  85. test_all<bg::model::d2::point_xy<float> >();
  86. test_all<bg::model::d2::point_xy<double> >();
  87. #ifdef HAVE_TTMATH
  88. test_all<bg::model::d2::point_xy<ttmath_big> >();
  89. #endif
  90. test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
  91. return 0;
  92. }