point_in_box.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.
  5. // Modifications copyright (c) 2014 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. #include <strategies/test_within.hpp>
  11. template <typename Point>
  12. void test_box_of(std::string const& wkt_point, std::string const& wkt_box,
  13. bool expected_within, bool expected_covered_by)
  14. {
  15. typedef bg::model::box<Point> box_type;
  16. Point point;
  17. box_type box;
  18. bg::read_wkt(wkt_point, point);
  19. bg::read_wkt(wkt_box, box);
  20. bool detected_within = bg::within(point, box);
  21. bool detected_covered_by = bg::covered_by(point, box);
  22. BOOST_CHECK_EQUAL(detected_within, expected_within);
  23. BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
  24. // Also test with the non-default agnostic side version
  25. namespace wi = bg::strategy::within;
  26. wi::point_in_box_by_side<> within_strategy;
  27. wi::point_in_box_by_side<wi::decide_covered_by> covered_by_strategy;
  28. detected_within = bg::within(point, box, within_strategy);
  29. detected_covered_by = bg::covered_by(point, box, covered_by_strategy);
  30. BOOST_CHECK_EQUAL(detected_within, expected_within);
  31. BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
  32. // We might exchange strategies between within/covered by.
  33. // So the lines below might seem confusing, but are as intended
  34. detected_within = bg::covered_by(point, box, within_strategy);
  35. detected_covered_by = bg::within(point, box, covered_by_strategy);
  36. BOOST_CHECK_EQUAL(detected_within, expected_within);
  37. BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
  38. // Finally we call the strategies directly
  39. detected_within = within_strategy.apply(point, box);
  40. detected_covered_by = covered_by_strategy.apply(point, box);
  41. BOOST_CHECK_EQUAL(detected_within, expected_within);
  42. BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
  43. }
  44. template <typename Point>
  45. void test_box()
  46. {
  47. test_box_of<Point>("POINT(1 1)", "BOX(0 0,2 2)", true, true);
  48. test_box_of<Point>("POINT(0 0)", "BOX(0 0,2 2)", false, true);
  49. test_box_of<Point>("POINT(2 2)", "BOX(0 0,2 2)", false, true);
  50. test_box_of<Point>("POINT(0 1)", "BOX(0 0,2 2)", false, true);
  51. test_box_of<Point>("POINT(1 0)", "BOX(0 0,2 2)", false, true);
  52. test_box_of<Point>("POINT(3 3)", "BOX(0 0,2 2)", false, false);
  53. }
  54. int test_main(int, char* [])
  55. {
  56. test_box<bg::model::point<float, 2, bg::cs::cartesian> >();
  57. test_box<bg::model::point<double, 2, bg::cs::cartesian> >();
  58. #if defined(HAVE_TTMATH)
  59. test_box<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
  60. #endif
  61. return 0;
  62. }