1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_GEOMETRY_TEST_COVERED_BY_HPP
13 #define BOOST_GEOMETRY_TEST_COVERED_BY_HPP
16 #include <geometry_test_common.hpp>
18 #include <boost/variant/variant.hpp>
20 #include <boost/geometry/core/ring_type.hpp>
21 #include <boost/geometry/algorithms/covered_by.hpp>
22 #include <boost/geometry/strategies/strategies.hpp>
23 #include <boost/geometry/geometries/ring.hpp>
24 #include <boost/geometry/geometries/polygon.hpp>
26 #include <boost/geometry/io/wkt/read.hpp>
28 #include <boost/geometry/multi/algorithms/covered_by.hpp>
29 #include <boost/geometry/multi/geometries/multi_linestring.hpp>
30 #include <boost/geometry/multi/io/wkt/read.hpp>
32 template <typename Geometry1, typename Geometry2>
33 void check_geometry(Geometry1 const& geometry1,
34 Geometry2 const& geometry2,
35 std::string const& wkt1,
36 std::string const& wkt2,
39 bool detected = bg::covered_by(geometry1, geometry2);
41 BOOST_CHECK_MESSAGE(detected == expected,
42 "covered_by: " << wkt1
44 << " -> Expected: " << expected
45 << " detected: " << detected);
48 template <typename Geometry1, typename Geometry2>
49 void test_geometry(std::string const& wkt1,
50 std::string const& wkt2, bool expected)
54 bg::read_wkt(wkt1, geometry1);
55 bg::read_wkt(wkt2, geometry2);
56 boost::variant<Geometry1> v1(geometry1);
57 boost::variant<Geometry2> v2(geometry2);
59 check_geometry(geometry1, geometry2, wkt1, wkt2, expected);
60 check_geometry(v1, geometry2, wkt1, wkt2, expected);
61 check_geometry(geometry1, v2, wkt1, wkt2, expected);
62 check_geometry(v1, v2, wkt1, wkt2, expected);
67 template <typename Point, bool Clockwise, bool Closed>
68 void test_ordered_ring(std::string const& wkt_point,
69 std::string const& wkt_geometry, bool expected)
71 typedef bg::model::ring<Point, Clockwise, Closed> ring_type;
75 bg::read_wkt(wkt_geometry, ring);
78 std::reverse(boost::begin(ring), boost::end(ring));
82 ring.resize(ring.size() - 1);
85 bg::read_wkt(wkt_point, point);
87 bool detected = bg::covered_by(point, ring);
89 BOOST_CHECK_MESSAGE(detected == expected,
90 "covered_by: " << wkt_point
91 << " in " << wkt_geometry
92 << " -> Expected: " << expected
93 << " detected: " << detected
94 << " clockwise: " << int(Clockwise)
95 << " closed: " << int(Closed)
98 // other strategy (note that this one cannot detect OnBorder
99 // (without modifications)
101 bg::strategy::covered_by::franklin<Point> franklin;
102 detected = bg::covered_by(point, ring, franklin);
105 BOOST_CHECK_MESSAGE(detected == expected,
106 "covered_by: " << wkt_point
107 << " in " << wkt_geometry
108 << " -> Expected: " << expected
109 << " detected: " << detected
110 << " clockwise: " << int(Clockwise)
111 << " closed: " << int(Closed)
116 bg::strategy::covered_by::crossings_multiply<Point> cm;
117 detected = bg::covered_by(point, ring, cm);
120 BOOST_CHECK_MESSAGE(detected == expected,
121 "covered_by: " << wkt_point
122 << " in " << wkt_geometry
123 << " -> Expected: " << expected
124 << " detected: " << detected
125 << " clockwise: " << int(Clockwise)
126 << " closed: " << int(Closed)
131 template <typename Point>
132 void test_ring(std::string const& wkt_point,
133 std::string const& wkt_geometry,
136 test_ordered_ring<Point, true, true>(wkt_point, wkt_geometry, expected);
137 test_ordered_ring<Point, false, true>(wkt_point, wkt_geometry, expected);
138 test_ordered_ring<Point, true, false>(wkt_point, wkt_geometry, expected);
139 test_ordered_ring<Point, false, false>(wkt_point, wkt_geometry, expected);
140 test_geometry<Point, bg::model::polygon<Point> >(wkt_point, wkt_geometry, expected);