Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / geometry / test / algorithms / test_covered_by.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
6
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)
10
11
12 #ifndef BOOST_GEOMETRY_TEST_COVERED_BY_HPP
13 #define BOOST_GEOMETRY_TEST_COVERED_BY_HPP
14
15
16 #include <geometry_test_common.hpp>
17
18 #include <boost/variant/variant.hpp>
19
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>
25
26 #include <boost/geometry/io/wkt/read.hpp>
27
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>
31
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,
37                     bool expected)
38 {
39     bool detected = bg::covered_by(geometry1, geometry2);
40
41     BOOST_CHECK_MESSAGE(detected == expected,
42         "covered_by: " << wkt1
43         << " in " << wkt2
44         << " -> Expected: " << expected
45         << " detected: " << detected);
46 }
47
48 template <typename Geometry1, typename Geometry2>
49 void test_geometry(std::string const& wkt1,
50         std::string const& wkt2, bool expected)
51 {
52     Geometry1 geometry1;
53     Geometry2 geometry2;
54     bg::read_wkt(wkt1, geometry1);
55     bg::read_wkt(wkt2, geometry2);
56     boost::variant<Geometry1> v1(geometry1);
57     boost::variant<Geometry2> v2(geometry2);
58
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);
63 }
64
65 /*
66
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)
70 {
71     typedef bg::model::ring<Point, Clockwise, Closed> ring_type;
72     ring_type ring;
73     Point point;
74
75     bg::read_wkt(wkt_geometry, ring);
76     if (! Clockwise)
77     {
78         std::reverse(boost::begin(ring), boost::end(ring));
79     }
80     if (! Closed)
81     {
82         ring.resize(ring.size() - 1);
83     }
84
85     bg::read_wkt(wkt_point, point);
86
87     bool detected = bg::covered_by(point, ring);
88
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)
96         );
97
98     // other strategy (note that this one cannot detect OnBorder
99     // (without modifications)
100
101     bg::strategy::covered_by::franklin<Point> franklin;
102     detected = bg::covered_by(point, ring, franklin);
103     if (! on_border)
104     {
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)
112             );
113     }
114
115
116     bg::strategy::covered_by::crossings_multiply<Point> cm;
117     detected = bg::covered_by(point, ring, cm);
118     if (! on_border)
119     {
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)
127             );
128     }
129 }
130
131 template <typename Point>
132 void test_ring(std::string const& wkt_point,
133         std::string const& wkt_geometry,
134         bool expected)
135 {
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);
141 }
142 */
143
144 #endif