1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
6 // This file was modified by Oracle on 2014.
7 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
15 #ifndef BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP
16 #define BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP
19 #include <geometry_test_common.hpp>
21 #include <boost/geometry/algorithms/covered_by.hpp>
22 #include <boost/geometry/algorithms/within.hpp>
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>
31 #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
32 #include <boost/geometry/strategies/spherical/ssf.hpp>
35 #include <boost/geometry/geometries/point.hpp>
36 #include <boost/geometry/geometries/box.hpp>
37 #include <boost/geometry/geometries/polygon.hpp>
39 #include <boost/geometry/io/wkt/wkt.hpp>
42 template <typename Strategy>
43 inline const char * strategy_name(Strategy const&)
45 return typeid(Strategy).name();
48 template <typename P, typename PoS, typename CT>
49 inline const char * strategy_name(bg::strategy::within::crossings_multiply<P, PoS, CT> const&)
51 return "crossings_multiply";
54 template <typename P, typename PoS, typename CT>
55 inline const char * strategy_name(bg::strategy::within::franklin<P, PoS, CT> const&)
60 template <typename P, typename PoS, typename CT>
61 inline const char * strategy_name(bg::strategy::within::winding<P, PoS, CT> const&)
67 template <typename Point, typename Polygon, typename Strategy>
68 void test_point_in_polygon(std::string const& case_id,
70 Polygon const& polygon,
71 Strategy const& strategy,
73 bool use_within = true)
75 BOOST_CONCEPT_ASSERT( (bg::concepts::WithinStrategyPolygonal<Strategy>) );
76 bool detected = use_within ?
77 bg::within(point, polygon, strategy) :
78 bg::covered_by(point, polygon, strategy);
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)
89 template <typename Point, typename Polygon, typename Strategy>
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,
95 bool use_within = true)
99 bg::read_wkt(wkt_point, point);
100 bg::read_wkt(wkt_polygon, polygon);
102 test_point_in_polygon(case_id, point, polygon, strategy, expected, use_within);
106 #endif // BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP