1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
6
7 // This file was modified by Oracle on 2017.
8 // Modifications copyright (c) 2017 Oracle and/or its affiliates.
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_INTERSECTS_HPP
16 #define BOOST_GEOMETRY_TEST_INTERSECTS_HPP
17
18
19 #include <geometry_test_common.hpp>
20
21
22 #include <boost/geometry/core/geometry_id.hpp>
23 #include <boost/geometry/core/point_order.hpp>
24 #include <boost/geometry/core/ring_type.hpp>
25 #include <boost/geometry/algorithms/covered_by.hpp>
26 #include <boost/geometry/algorithms/intersects.hpp>
27 #include <boost/geometry/strategies/strategies.hpp>
28 #include <boost/geometry/geometries/ring.hpp>
29 #include <boost/geometry/geometries/polygon.hpp>
30 #include <boost/geometry/geometries/multi_linestring.hpp>
31 #include <boost/geometry/geometries/multi_polygon.hpp>
32
33 #include <boost/geometry/io/wkt/read.hpp>
34
35
36 struct no_strategy {};
37
38 template <typename Geometry1, typename Geometry2, typename Strategy>
call_intersects(Geometry1 const & geometry1,Geometry2 const & geometry2,Strategy const & strategy)39 bool call_intersects(Geometry1 const& geometry1,
40 Geometry2 const& geometry2,
41 Strategy const& strategy)
42 {
43 return bg::intersects(geometry1, geometry2, strategy);
44 }
45
46 template <typename Geometry1, typename Geometry2>
call_intersects(Geometry1 const & geometry1,Geometry2 const & geometry2,no_strategy)47 bool call_intersects(Geometry1 const& geometry1,
48 Geometry2 const& geometry2,
49 no_strategy)
50 {
51 return bg::intersects(geometry1, geometry2);
52 }
53
54 template <typename G1, typename G2, typename Strategy>
check_intersects(std::string const & wkt1,std::string const & wkt2,G1 const & g1,G2 const & g2,bool expected,Strategy const & strategy)55 void check_intersects(std::string const& wkt1,
56 std::string const& wkt2,
57 G1 const& g1,
58 G2 const& g2,
59 bool expected,
60 Strategy const& strategy)
61 {
62 bool detected = call_intersects(g1, g2, strategy);
63
64 BOOST_CHECK_MESSAGE(detected == expected,
65 "intersects: " << wkt1
66 << " with " << wkt2
67 << " -> Expected: " << expected
68 << " detected: " << detected);
69 }
70
71 template <typename Geometry1, typename Geometry2>
test_geometry(std::string const & wkt1,std::string const & wkt2,bool expected)72 void test_geometry(std::string const& wkt1,
73 std::string const& wkt2, bool expected)
74 {
75 Geometry1 geometry1;
76 Geometry2 geometry2;
77
78 bg::read_wkt(wkt1, geometry1);
79 bg::read_wkt(wkt2, geometry2);
80
81 check_intersects(wkt1, wkt2, geometry1, geometry2, expected, no_strategy());
82 check_intersects(wkt2, wkt1, geometry2, geometry1, expected, no_strategy());
83
84 typedef typename bg::strategy::disjoint::services::default_strategy
85 <
86 Geometry1, Geometry2
87 >::type strategy12_type;
88 typedef typename bg::strategy::disjoint::services::default_strategy
89 <
90 Geometry2, Geometry1
91 >::type strategy21_type;
92
93 check_intersects(wkt1, wkt2, geometry1, geometry2, expected, strategy12_type());
94 check_intersects(wkt2, wkt1, geometry2, geometry1, expected, strategy21_type());
95 }
96
97
98 template <typename Geometry>
test_self_intersects(std::string const & wkt,bool expected)99 void test_self_intersects(std::string const& wkt, bool expected)
100 {
101 Geometry geometry;
102
103 bg::read_wkt(wkt, geometry);
104
105 bool detected = bg::intersects(geometry);
106
107 BOOST_CHECK_MESSAGE(detected == expected,
108 "intersects: " << wkt
109 << " -> Expected: " << expected
110 << " detected: " << detected);
111 }
112
113
114
115 #endif
116