test_within.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2014, 2019.
  5. // Modifications copyright (c) 2014, 2019 Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP
  11. #define BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP
  12. #include <geometry_test_common.hpp>
  13. #include <boost/geometry/algorithms/covered_by.hpp>
  14. #include <boost/geometry/algorithms/within.hpp>
  15. #include <boost/geometry/strategies/cartesian/point_in_poly_franklin.hpp>
  16. #include <boost/geometry/strategies/cartesian/point_in_poly_crossings_multiply.hpp>
  17. #include <boost/geometry/strategies/agnostic/point_in_poly_winding.hpp>
  18. #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
  19. #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
  20. #include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp>
  21. #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
  22. #include <boost/geometry/strategies/spherical/ssf.hpp>
  23. #include <boost/geometry/geometries/point.hpp>
  24. #include <boost/geometry/geometries/box.hpp>
  25. #include <boost/geometry/geometries/polygon.hpp>
  26. #include <boost/geometry/io/wkt/wkt.hpp>
  27. template <typename Strategy>
  28. inline const char * strategy_name(Strategy const&)
  29. {
  30. return typeid(Strategy).name();
  31. }
  32. template <typename P, typename PoS, typename CT>
  33. inline const char * strategy_name(bg::strategy::within::crossings_multiply<P, PoS, CT> const&)
  34. {
  35. return "crossings_multiply";
  36. }
  37. template <typename P, typename PoS, typename CT>
  38. inline const char * strategy_name(bg::strategy::within::franklin<P, PoS, CT> const&)
  39. {
  40. return "franklin";
  41. }
  42. template <typename P, typename PoS, typename CT>
  43. inline const char * strategy_name(bg::strategy::within::winding<P, PoS, CT> const&)
  44. {
  45. return "winding";
  46. }
  47. template <typename Point, typename Polygon, typename Strategy>
  48. void test_point_in_polygon(std::string const& case_id,
  49. Point const& point,
  50. Polygon const& polygon,
  51. Strategy const& strategy,
  52. bool expected,
  53. bool use_within = true)
  54. {
  55. BOOST_CONCEPT_ASSERT( (bg::concepts::WithinStrategyPolygonal<Point, Polygon, Strategy>) );
  56. bool detected = use_within ?
  57. bg::within(point, polygon, strategy) :
  58. bg::covered_by(point, polygon, strategy);
  59. BOOST_CHECK_MESSAGE(detected == expected,
  60. (use_within ? "within: " : "covered_by: ") << case_id
  61. << " strategy: " << strategy_name(strategy)
  62. << " output expected: " << int(expected)
  63. << " detected: " << int(detected)
  64. );
  65. }
  66. template <typename Point, typename Polygon, typename Strategy>
  67. void test_geometry(std::string const& case_id,
  68. std::string const& wkt_point,
  69. std::string const& wkt_polygon,
  70. Strategy const& strategy,
  71. bool expected,
  72. bool use_within = true)
  73. {
  74. Point point;
  75. Polygon polygon;
  76. bg::read_wkt(wkt_point, point);
  77. bg::read_wkt(wkt_polygon, polygon);
  78. test_point_in_polygon(case_id, point, polygon, strategy, expected, use_within);
  79. }
  80. #endif // BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP