• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // This file was modified by Oracle on 2014, 2019.
7 // Modifications copyright (c) 2014, 2019 Oracle and/or its affiliates.
8 
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 
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 
15 #ifndef BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP
16 #define BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP
17 
18 
19 #include <geometry_test_common.hpp>
20 
21 #include <boost/geometry/algorithms/covered_by.hpp>
22 #include <boost/geometry/algorithms/within.hpp>
23 
24 #include <boost/geometry/strategies/cartesian/point_in_poly_franklin.hpp>
25 #include <boost/geometry/strategies/cartesian/point_in_poly_crossings_multiply.hpp>
26 #include <boost/geometry/strategies/agnostic/point_in_poly_winding.hpp>
27 #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
28 #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
29 #include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp>
30 
31 #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
32 #include <boost/geometry/strategies/spherical/ssf.hpp>
33 
34 
35 #include <boost/geometry/geometries/point.hpp>
36 #include <boost/geometry/geometries/box.hpp>
37 #include <boost/geometry/geometries/polygon.hpp>
38 
39 #include <boost/geometry/io/wkt/wkt.hpp>
40 
41 
42 template <typename Strategy>
strategy_name(Strategy const &)43 inline const char * strategy_name(Strategy const&)
44 {
45     return typeid(Strategy).name();
46 }
47 
48 template <typename P, typename PoS, typename CT>
strategy_name(bg::strategy::within::crossings_multiply<P,PoS,CT> const &)49 inline const char * strategy_name(bg::strategy::within::crossings_multiply<P, PoS, CT> const&)
50 {
51     return "crossings_multiply";
52 }
53 
54 template <typename P, typename PoS, typename CT>
strategy_name(bg::strategy::within::franklin<P,PoS,CT> const &)55 inline const char * strategy_name(bg::strategy::within::franklin<P, PoS, CT> const&)
56 {
57     return "franklin";
58 }
59 
60 template <typename P, typename PoS, typename CT>
strategy_name(bg::strategy::within::winding<P,PoS,CT> const &)61 inline const char * strategy_name(bg::strategy::within::winding<P, PoS, CT> const&)
62 {
63     return "winding";
64 }
65 
66 
67 template <typename Point, typename Polygon, typename Strategy>
test_point_in_polygon(std::string const & case_id,Point const & point,Polygon const & polygon,Strategy const & strategy,bool expected,bool use_within=true)68 void test_point_in_polygon(std::string const& case_id,
69                            Point const& point,
70                            Polygon const& polygon,
71                            Strategy const& strategy,
72                            bool expected,
73                            bool use_within = true)
74 {
75     BOOST_CONCEPT_ASSERT( (bg::concepts::WithinStrategyPolygonal<Point, Polygon, Strategy>) );
76     bool detected = use_within ?
77                     bg::within(point, polygon, strategy) :
78                     bg::covered_by(point, polygon, strategy);
79 
80     BOOST_CHECK_MESSAGE(detected == expected,
81             (use_within ? "within: " : "covered_by: ") << case_id
82             << " strategy: " << strategy_name(strategy)
83             << " output expected: " << int(expected)
84             << " detected: " << int(detected)
85             );
86 }
87 
88 
89 template <typename Point, typename Polygon, typename Strategy>
test_geometry(std::string const & case_id,std::string const & wkt_point,std::string const & wkt_polygon,Strategy const & strategy,bool expected,bool use_within=true)90 void test_geometry(std::string const& case_id,
91                    std::string const& wkt_point,
92                    std::string const& wkt_polygon,
93                    Strategy const& strategy,
94                    bool expected,
95                    bool use_within = true)
96 {
97     Point point;
98     Polygon polygon;
99     bg::read_wkt(wkt_point, point);
100     bg::read_wkt(wkt_polygon, polygon);
101 
102     test_point_in_polygon(case_id, point, polygon, strategy, expected, use_within);
103 }
104 
105 
106 #endif // BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP
107