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) 2008-2015 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
7
8 // This file was modified by Oracle on 2017.
9 // Modifications copyright (c) 2017 Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18
19 #ifndef BOOST_GEOMETRY_TEST_DISJOINT_HPP
20 #define BOOST_GEOMETRY_TEST_DISJOINT_HPP
21
22 #include <iostream>
23 #include <string>
24 #include <boost/variant/variant.hpp>
25
26 #include <geometry_test_common.hpp>
27
28 #include <boost/geometry/algorithms/disjoint.hpp>
29 #include <boost/geometry/io/wkt/read.hpp>
30
31
32 struct no_strategy {};
33
34 template <typename Geometry1, typename Geometry2, typename Strategy>
call_disjoint(Geometry1 const & geometry1,Geometry2 const & geometry2,Strategy const & strategy)35 bool call_disjoint(Geometry1 const& geometry1,
36 Geometry2 const& geometry2,
37 Strategy const& strategy)
38 {
39 return bg::disjoint(geometry1, geometry2, strategy);
40 }
41
42 template <typename Geometry1, typename Geometry2>
call_disjoint(Geometry1 const & geometry1,Geometry2 const & geometry2,no_strategy)43 bool call_disjoint(Geometry1 const& geometry1,
44 Geometry2 const& geometry2,
45 no_strategy)
46 {
47 return bg::disjoint(geometry1, geometry2);
48 }
49
50 template <typename G1, typename G2, typename Strategy>
check_disjoint(std::string const & id,std::string const & wkt1,std::string const & wkt2,G1 const & g1,G2 const & g2,bool expected,Strategy const & strategy)51 void check_disjoint(std::string const& id,
52 std::string const& wkt1,
53 std::string const& wkt2,
54 G1 const& g1,
55 G2 const& g2,
56 bool expected,
57 Strategy const& strategy)
58 {
59 bool detected = call_disjoint(g1, g2, strategy);
60 if (id.empty())
61 {
62 BOOST_CHECK_MESSAGE(detected == expected,
63 "disjoint: " << wkt1 << " and " << wkt2
64 << " -> Expected: " << expected
65 << " detected: " << detected);
66 }
67 else
68 {
69 BOOST_CHECK_MESSAGE(detected == expected,
70 "disjoint: " << id
71 << " -> Expected: " << expected
72 << " detected: " << detected);
73 }
74 }
75
76 template <typename G1, typename G2>
test_disjoint(std::string const & id,std::string const & wkt1,std::string const & wkt2,bool expected)77 void test_disjoint(std::string const& id,
78 std::string const& wkt1,
79 std::string const& wkt2,
80 bool expected)
81 {
82 G1 g1;
83 bg::read_wkt(wkt1, g1);
84
85 G2 g2;
86 bg::read_wkt(wkt2, g2);
87
88 boost::variant<G1> v1(g1);
89 boost::variant<G2> v2(g2);
90
91 typedef typename bg::strategy::disjoint::services::default_strategy
92 <
93 G1, G2
94 >::type strategy_type;
95
96 check_disjoint(id, wkt1, wkt2, g1, g2, expected, no_strategy());
97 check_disjoint(id, wkt1, wkt2, g1, g2, expected, strategy_type());
98 check_disjoint(id, wkt1, wkt2, g1, g2, expected, no_strategy());
99 check_disjoint(id, wkt1, wkt2, v1, g2, expected, no_strategy());
100 check_disjoint(id, wkt1, wkt2, g1, v2, expected, no_strategy());
101 check_disjoint(id, wkt1, wkt2, v1, v2, expected, no_strategy());
102 }
103
104 template <typename G1, typename G2>
test_geometry(std::string const & wkt1,std::string const & wkt2,bool expected)105 void test_geometry(std::string const& wkt1,
106 std::string const& wkt2,
107 bool expected)
108 {
109 test_disjoint<G1, G2>("", wkt1, wkt2, expected);
110 }
111
112 #endif // BOOST_GEOMETRY_TEST_DISJOINT_HPP
113