1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
6 // This file was modified by Oracle on 2013, 2015, 2016, 2017.
7 // Modifications copyright (c) 2013-2017 Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_TEST_TOUCHES_HPP
15 #define BOOST_GEOMETRY_TEST_TOUCHES_HPP
18 #include <geometry_test_common.hpp>
20 #include <boost/geometry/core/ring_type.hpp>
21 #include <boost/geometry/algorithms/touches.hpp>
22 #include <boost/geometry/strategies/strategies.hpp>
23 #include <boost/geometry/geometries/geometries.hpp>
24 #include <boost/geometry/geometries/point_xy.hpp>
26 #include <boost/geometry/io/wkt/read.hpp>
27 #include <boost/variant/variant.hpp>
30 struct no_strategy {};
32 template <typename Geometry1, typename Geometry2, typename Strategy>
33 void check_touches(Geometry1 const& geometry1,
34 Geometry2 const& geometry2,
35 std::string const& wkt1,
36 std::string const& wkt2,
38 Strategy const& strategy)
40 bool detected = bg::touches(geometry1, geometry2, strategy);
42 BOOST_CHECK_MESSAGE(detected == expected,
45 << " -> Expected: " << expected
46 << " detected: " << detected);
48 detected = bg::touches(geometry2, geometry1, strategy);
50 BOOST_CHECK_MESSAGE(detected == expected,
53 << " -> Expected: " << expected
54 << " detected: " << detected);
57 template <typename Geometry1, typename Geometry2>
58 void check_touches(Geometry1 const& geometry1,
59 Geometry2 const& geometry2,
60 std::string const& wkt1,
61 std::string const& wkt2,
63 no_strategy = no_strategy())
65 bool detected = bg::touches(geometry1, geometry2);
67 BOOST_CHECK_MESSAGE(detected == expected,
70 << " -> Expected: " << expected
71 << " detected: " << detected);
73 detected = bg::touches(geometry2, geometry1);
75 BOOST_CHECK_MESSAGE(detected == expected,
78 << " -> Expected: " << expected
79 << " detected: " << detected);
82 template <typename Geometry1, typename Geometry2>
83 void test_touches(std::string const& wkt1,
84 std::string const& wkt2, bool expected)
89 bg::read_wkt(wkt1, geometry1);
90 bg::read_wkt(wkt2, geometry2);
92 boost::variant<Geometry1> v1(geometry1);
93 boost::variant<Geometry2> v2(geometry2);
95 typedef typename bg::strategy::relate::services::default_strategy
98 >::type strategy_type;
100 check_touches(geometry1, geometry2, wkt1, wkt2, expected, no_strategy());
101 check_touches(geometry1, geometry2, wkt1, wkt2, expected, strategy_type());
102 check_touches(v1, geometry2, wkt1, wkt2, expected, no_strategy());
103 check_touches(geometry1, v2, wkt1, wkt2, expected, no_strategy());
104 check_touches(v1, v2, wkt1, wkt2, expected, no_strategy());
107 template <typename Geometry1, typename Geometry2>
108 void test_geometry(std::string const& wkt1,
109 std::string const& wkt2,
112 test_touches<Geometry1, Geometry2>(wkt1, wkt2, expected);
116 template <typename Geometry>
117 void check_self_touches(Geometry const& geometry,
118 std::string const& wkt,
121 bool detected = bg::touches(geometry);
123 BOOST_CHECK_MESSAGE(detected == expected,
125 << " -> Expected: " << expected
126 << " detected: " << detected);
129 template <typename Geometry>
130 void test_self_touches(std::string const& wkt, bool expected)
133 bg::read_wkt(wkt, geometry);
134 boost::variant<Geometry> v(geometry);
136 check_self_touches(geometry, wkt, expected);
137 check_self_touches(v, wkt, expected);