]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/algorithms/intersects/intersects.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / intersects / intersects.cpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
5
6// This file was modified by Oracle on 2013, 2015, 2016.
7// Modifications copyright (c) 2013-2016, Oracle and/or its affiliates.
8// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9
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)
13
14#include "test_intersects.hpp"
15
16
17#include <boost/geometry/geometries/geometries.hpp>
18#include <boost/geometry/geometries/point_xy.hpp>
19
20#include <boost/geometry/util/rational.hpp>
21
22template <typename P1, typename P2>
23void test_intersects_polygon_polygon()
24{
25 typedef bg::model::polygon<P1, false, false> poly_ccw_o1;
26 typedef bg::model::polygon<P2, false, false> poly_ccw_o2;
27 test_geometry<poly_ccw_o1, poly_ccw_o2>("POLYGON((1 1, 3 3, 2 5))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true);
28 test_geometry<poly_ccw_o1, poly_ccw_o2>("POLYGON((6 6, 7 6, 7 7, 6 7))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false);
29 test_geometry<poly_ccw_o1, poly_ccw_o2>("POLYGON((7 7, 9 7, 9 9, 7 9))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true);
30}
31
32template <typename P1, typename P2>
33void test_intersects_linestring_segment()
34{
35 typedef bg::model::linestring<P1> ls;
36 typedef bg::model::segment<P2> seg;
37
38 test_geometry<ls, seg>("LINESTRING(1 1, 3 3, 2 5)", "SEGMENT(2 0, 2 6)", true);
39 test_geometry<ls, seg>("LINESTRING(1 1, 3 3)", "SEGMENT(1 0, 1 1)", true);
40 test_geometry<ls, seg>("LINESTRING(1 1, 3 3)", "SEGMENT(2 0, 2 2)", true);
41 test_geometry<ls, seg>("LINESTRING(1 1, 3 3)", "SEGMENT(3 0, 4 1)", false);
42}
43
44template <typename P1, typename P2>
45void test_intersects_linestring_linestring()
46{
47 typedef bg::model::linestring<P1> ls1;
48 typedef bg::model::linestring<P2> ls2;
49
50 test_geometry<ls1, ls2>("LINESTRING(0 0,2 0,3 0)", "LINESTRING(0 0,1 1,2 2)", true);
51 test_geometry<ls1, ls2>("LINESTRING(0 0,2 0,3 0)", "LINESTRING(2 2,1 1,0 0)", true);
52 test_geometry<ls1, ls2>("LINESTRING(3 0,2 0,0 0)", "LINESTRING(0 0,1 1,2 2)", true);
53 test_geometry<ls1, ls2>("LINESTRING(3 0,2 0,0 0)", "LINESTRING(2 2,1 1,0 0)", true);
54
55 test_geometry<ls1, ls2>("LINESTRING(0 0,2 0,3 0)", "LINESTRING(1 0,4 0,5 0)", true);
56 test_geometry<ls1, ls2>("LINESTRING(1 0,2 0)", "LINESTRING(1 0,0 0)", true);
57}
58
59template <typename P1, typename P2>
60void test_intersects_linestring_polygon()
61{
62 typedef bg::model::linestring<P1> ls;
63 typedef bg::model::multi_linestring<ls> mls;
64 typedef bg::model::polygon<P2> poly_cw_c;
65 typedef bg::model::polygon<P2, false> poly_ccw_c;
66 typedef bg::model::polygon<P2, false, false> poly_ccw_o;
67 typedef bg::model::multi_polygon<poly_ccw_c> mpoly_ccw_c;
68
69 test_geometry<ls, poly_ccw_c>("LINESTRING(1 1,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true);
70 test_geometry<ls, poly_ccw_c>("LINESTRING(1 0,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true);
71 test_geometry<ls, poly_ccw_c>("LINESTRING(11 0,12 12)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", false);
72
73 test_geometry<ls, poly_ccw_o>("LINESTRING(1 1, 3 3, 2 5)", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true);
74 test_geometry<ls, poly_ccw_o>("LINESTRING(6 6, 7 6, 7 7, 6 7)", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false);
75 test_geometry<ls, poly_ccw_o>("LINESTRING(7 7, 9 7, 9 9, 7 9)", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true);
76
77 test_geometry<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(-2 -2, 12 7)", true);
78 test_geometry<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(5 5, 15 4)", true);
79 test_geometry<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(7 6, 15 4)", true);
80 test_geometry<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(6 2, 12 1)", true);
81
82 // MULTI
83 test_geometry<ls, mpoly_ccw_c>("LINESTRING(1 1,2 2)", "MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", true);
84 test_geometry<mls, mpoly_ccw_c>("MULTILINESTRING((1 1,2 2))", "MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", true);
85}
86
87template <typename P1, typename P2>
88void test_intersects_linestring_ring()
89{
90 typedef bg::model::linestring<P1> ls;
91 typedef bg::model::multi_linestring<ls> mls;
92 typedef bg::model::ring<P2, false> ring_ccw_c;
93
94 test_geometry<ls, ring_ccw_c>("LINESTRING(1 1,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true);
95 test_geometry<ls, ring_ccw_c>("LINESTRING(1 0,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true);
96 test_geometry<ls, ring_ccw_c>("LINESTRING(11 0,12 12)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", false);
97
98 // MULTI
99 test_geometry<mls, ring_ccw_c>("MULTILINESTRING((1 1,2 2))", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true);
100}
101
102template <typename P1, typename P2>
103void test_intersects_ring_polygon()
104{
105 typedef bg::model::ring<P1, false, false> ring_ccw_o;
106 typedef bg::model::polygon<P2, false, false> poly_ccw_o;
107
108 test_geometry<ring_ccw_o, poly_ccw_o>("POLYGON((1 1, 3 3, 2 5))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true);
109 test_geometry<ring_ccw_o, poly_ccw_o>("POLYGON((6 6, 7 6, 7 7, 6 7))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false);
110 test_geometry<ring_ccw_o, poly_ccw_o>("POLYGON((7 7, 9 7, 9 9, 7 9))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true);
111
112 test_geometry<ring_ccw_o, poly_ccw_o>("POLYGON((6 6,7 6,7 7,6 7))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false);
113}
114
115template <typename P1, typename P2>
116void test_intersects_point_linestring()
117{
118 typedef bg::model::linestring<P2> ls;
119 typedef bg::model::multi_linestring<ls> mls;
120
121 test_geometry<P1, ls>("POINT(0 0)", "LINESTRING(0 0,2 2,4 0)", true);
122 test_geometry<P1, ls>("POINT(1 1)", "LINESTRING(0 0,2 2,4 0)", true);
123 test_geometry<P1, ls>("POINT(1 0)", "LINESTRING(0 0,2 2,4 0)", false);
124
125 // MULTI
126 test_geometry<P1, mls>("POINT(0 0)", "MULTILINESTRING((0 0,2 2,4 0))", true);
127}
128
129template <typename P1, typename P2>
130void test_intersects_point_segment()
131{
132 typedef bg::model::segment<P2> seg;
133
134 test_geometry<P1, seg>("POINT(0 0)", "LINESTRING(0 0,2 2)", true);
135 test_geometry<P1, seg>("POINT(1 1)", "LINESTRING(0 0,2 2)", true);
136 test_geometry<P1, seg>("POINT(1 0)", "LINESTRING(0 0,2 2)", false);
137}
138
139template <typename P1, typename P2>
140void test_multi_linestring_polygon()
141{
142 typedef bg::model::linestring<P1> ls;
143 typedef bg::model::multi_linestring<ls> mls;
144 typedef bg::model::polygon<P2> poly;
145
146 test_geometry<mls, poly>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
147 "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
148 true);
149 test_geometry<mls, poly>("MULTILINESTRING((10 0, 18 12),(2 2,2 1))",
150 "POLYGON((5 0,0 -5,-5 0,0 5,5 0))",
151 true);
152}
153
154template <typename P1, typename P2>
155void test_multi_polygon_polygon()
156{
157 typedef bg::model::polygon<P1> poly1;
158 typedef bg::model::multi_polygon<poly1> mpoly;
159 typedef bg::model::polygon<P2> poly2;
160
161 test_geometry<mpoly, poly2>("MULTIPOLYGON(((11 11,11 20,20 20,20 11,11 11)),((5 5,5 6,6 6,6 5,5 5)))",
162 "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
163 true);
164}
165
166template <typename P1, typename P2>
167void test_point_polygon()
168{
169 typedef bg::model::ring<P2> ring;
170 typedef bg::model::polygon<P2> poly;
171
172 test_geometry<P1, ring>(
173 "POINT(0 0)",
174 "POLYGON((0 0,3 3,3 3,4 1))",
175 true);
176 test_geometry<P1, poly>(
177 "POINT(0 0)",
178 "POLYGON((0 0,3 3,3 3,4 1))",
179 true);
180
181 test_geometry<ring, P1>(
182 "POLYGON((0 0,3 3,3 3,4 1))",
183 "POINT(0 0)",
184 true);
185 test_geometry<poly, P1>(
186 "POLYGON((0 0,3 3,3 3,4 1))",
187 "POINT(0 0)",
188 true);
189}
190
191template <typename P1, typename P2>
192void test_all()
193{
194 test_intersects_point_segment<P1, P2>();
195 test_intersects_point_linestring<P1, P2>();
196 test_intersects_polygon_polygon<P1, P2>();
197 test_intersects_linestring_polygon<P1, P2>();
198 test_intersects_linestring_ring<P1, P2>();
199 test_intersects_linestring_segment<P1, P2>();
200 test_intersects_linestring_linestring<P1, P2>();
201 test_intersects_ring_polygon<P1, P2>();
202 test_multi_linestring_polygon<P1, P2>();
203 test_multi_polygon_polygon<P1, P2>();
204 test_point_polygon<P1, P2>();
205}
206
207template <typename P>
208void test_all()
209{
210 test_all<P, P>();
211}
212
213int test_main( int , char* [] )
214{
215 test_all<bg::model::d2::point_xy<double> >();
216 test_all<bg::model::d2::point_xy<double>, bg::model::point<double, 2, bg::cs::cartesian> >();
217
218#if ! defined(BOOST_GEOMETRY_RESCALE_TO_ROBUST)
219 test_all<bg::model::d2::point_xy<boost::rational<int> > >();
220#endif
221
7c673cae
FG
222 return 0;
223}