3 // Copyright (c) 2016 Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 #include "test_within.hpp"
12 #include <algorithms/overlay/overlay_cases.hpp>
13 #include <algorithms/overlay/multi_overlay_cases.hpp>
15 #include <boost/geometry/geometries/geometries.hpp>
19 void test_polygon_polygon()
21 typedef bg::model::polygon
<P
> poly
;
22 typedef bg::model::ring
<P
> ring
;
24 test_geometry
<ring
, ring
>(case_1
[0], case_1
[1],
26 test_geometry
<ring
, poly
>(case_1
[0], case_1
[1],
29 test_geometry
<poly
, poly
>(case_1
[0], case_1
[1],
31 test_geometry
<poly
, poly
>(case_2
[0], case_2
[1],
33 test_geometry
<poly
, poly
>(case_3_sph
[0], case_3_sph
[1],
35 test_geometry
<poly
, poly
>(case_3_2_sph
[0], case_3_2_sph
[1],
37 test_geometry
<poly
, poly
>(case_4
[0], case_4
[1],
39 test_geometry
<poly
, poly
>(case_5
[0], case_5
[1],
41 test_geometry
<poly
, poly
>(case_6_sph
[0], case_6_sph
[1],
43 test_geometry
<poly
, poly
>(case_6_sph
[1], case_6_sph
[0],
46 test_geometry
<poly
, poly
>(case_7
[0], case_7
[1],
48 test_geometry
<poly
, poly
>(case_8_sph
[0], case_8_sph
[1],
50 test_geometry
<poly
, poly
>(case_9_sph
[0], case_9_sph
[1],
52 test_geometry
<poly
, poly
>(case_10_sph
[0], case_10_sph
[1],
54 test_geometry
<poly
, poly
>(case_11_sph
[0], case_11_sph
[1],
56 test_geometry
<poly
, poly
>(case_11_sph
[1], case_11_sph
[0],
58 test_geometry
<poly
, poly
>(case_12
[0], case_12
[1],
61 test_geometry
<poly
, poly
>(case_13_sph
[0], case_13_sph
[1],
63 test_geometry
<poly
, poly
>(case_14_sph
[0], case_14_sph
[1],
65 test_geometry
<poly
, poly
>(case_15_sph
[0], case_15_sph
[1],
67 test_geometry
<poly
, poly
>(case_16_sph
[0], case_16_sph
[1],
69 test_geometry
<poly
, poly
>(case_17_sph
[0], case_17_sph
[1],
71 test_geometry
<poly
, poly
>(case_17_sph
[1], case_17_sph
[0],
73 test_geometry
<poly
, poly
>(case_18_sph
[0], case_18_sph
[1],
75 test_geometry
<poly
, poly
>(case_18_sph
[1], case_18_sph
[0],
80 void test_polygon_multi_polygon()
82 typedef bg::model::polygon
<P
> poly
;
83 typedef bg::model::ring
<P
> ring
;
84 typedef bg::model::multi_polygon
<poly
> mpoly
;
86 test_geometry
<ring
, mpoly
>(case_1
[0], case_multi_2
[0],
88 test_geometry
<poly
, mpoly
>(case_2
[0], case_multi_2
[0],
93 void test_multi_polygon_multi_polygon()
95 typedef bg::model::polygon
<P
> poly
;
96 typedef bg::model::multi_polygon
<poly
> mpoly
;
98 test_geometry
<mpoly
, mpoly
>(case_multi_2
[0], case_multi_2
[1],
102 template <typename P
>
103 void test_linestring_polygon()
105 typedef bg::model::linestring
<P
> ls
;
106 typedef bg::model::polygon
<P
> poly
;
107 typedef bg::model::polygon
<P
> ring
;
109 test_geometry
<ls
, poly
>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
110 test_geometry
<ls
, ring
>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
111 test_geometry
<ls
, poly
>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
112 test_geometry
<ls
, poly
>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
113 test_geometry
<ls
, poly
>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
114 test_geometry
<ls
, poly
>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
116 test_geometry
<ls
, poly
>("LINESTRING(9 1,10 5,9 9)",
117 "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
120 test_geometry
<ls
, poly
>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
121 "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
124 test_geometry
<ls
, poly
>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
125 "POLYGON((0 0,0 10,10 10,10 0,0 0))",
129 template <typename P
>
130 void test_linestring_multi_polygon()
132 typedef bg::model::linestring
<P
> ls
;
133 typedef bg::model::polygon
<P
> poly
;
134 typedef bg::model::multi_polygon
<poly
> mpoly
;
136 test_geometry
<ls
, mpoly
>("LINESTRING(10 1,10 5,10 9)",
137 "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)))",
141 template <typename P
>
142 void test_multi_linestring_polygon()
144 typedef bg::model::linestring
<P
> ls
;
145 typedef bg::model::multi_linestring
<ls
> mls
;
146 typedef bg::model::polygon
<P
> poly
;
147 typedef bg::model::ring
<P
> ring
;
149 test_geometry
<mls
, poly
>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
150 "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
153 test_geometry
<mls
, ring
>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))",
154 "POLYGON((5 5,5 15,15 15,15 5,5 5))",
157 test_geometry
<mls
, poly
>("MULTILINESTRING((3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 2))",
158 "POLYGON((0 0,0 10,10 10,10 0,0 0))",
162 template <typename P
>
163 void test_multi_linestring_multi_polygon()
165 typedef bg::model::linestring
<P
> ls
;
166 typedef bg::model::polygon
<P
> poly
;
167 typedef bg::model::multi_linestring
<ls
> mls
;
168 typedef bg::model::multi_polygon
<poly
> mpoly
;
170 test_geometry
<mls
, mpoly
>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))",
171 "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))",
174 test_geometry
<mls
, mpoly
>("MULTILINESTRING((0 0,10 0,10 10),(10 10,0 10,0 0),(20 20,50 50,20 80,20 20))",
175 "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
178 test_geometry
<mls
, mpoly
>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
179 "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
183 template <typename P
>
184 void test_linestring_linestring()
186 typedef bg::model::linestring
<P
> ls
;
188 test_geometry
<ls
, ls
>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
190 test_geometry
<ls
, ls
>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", false);
193 template <typename P
>
194 void test_linestring_multi_linestring()
196 typedef bg::model::linestring
<P
> ls
;
197 typedef bg::model::multi_linestring
<ls
> mls
;
199 test_geometry
<ls
, mls
>("LINESTRING(0 0,10 0)",
200 "MULTILINESTRING((1 0,2 0),(1 1,2 1))",
203 test_geometry
<ls
, mls
>("LINESTRING(0 0,5 0,5 5,0 5,0 0)",
204 "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))",
208 template <typename P
>
209 void test_multi_linestring_multi_linestring()
211 typedef bg::model::linestring
<P
> ls
;
212 typedef bg::model::multi_linestring
<ls
> mls
;
214 test_geometry
<mls
, mls
>("MULTILINESTRING((0 0,0 0,18 0,18 0,19 0,19 0,19 0,30 0,30 0))",
215 "MULTILINESTRING((0 10,5 0,20 0,20 0,30 0))",
219 template <typename P
>
220 void test_point_polygon()
222 typedef bg::model::polygon
<P
> poly
;
224 // https://svn.boost.org/trac/boost/ticket/9162
225 test_geometry
<P
, poly
>("POINT(0 90)",
226 "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
228 test_geometry
<P
, poly
>("POINT(-120 21)",
229 "POLYGON((30 0,30 30,90 30, 90 0, 30 0))",
232 test_geometry
<P
, poly
>("POINT(0 -90)",
233 "POLYGON((0 -80,90 -80, -180 -80, -90 -80, 0 -80))",
235 test_geometry
<P
, poly
>("POINT(0 89)",
236 "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
238 test_geometry
<P
, poly
>("POINT(-180 89)",
239 "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
244 template <typename P
>
247 test_polygon_polygon
<P
>();
248 test_polygon_multi_polygon
<P
>();
249 test_multi_polygon_multi_polygon
<P
>();
251 test_linestring_polygon
<P
>();
252 test_linestring_multi_polygon
<P
>();
253 test_multi_linestring_polygon
<P
>();
254 test_multi_linestring_multi_polygon
<P
>();
256 test_linestring_linestring
<P
>();
257 test_linestring_multi_linestring
<P
>();
258 test_multi_linestring_multi_linestring
<P
>();
260 test_point_polygon
<P
>();
264 int test_main( int , char* [] )
266 test_all
<bg::model::point
<double, 2, bg::cs::spherical_equatorial
<bg::degree
> > >();