]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/relational_operations/touches/touches.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / relational_operations / touches / touches.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 //
3 // Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2013, 2014. 2015.
6 // Modifications copyright (c) 2013-2015, Oracle and/or its affiliates.
7
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_touches.hpp"
15
16 template <typename P>
17 void test_all()
18 {
19 typedef bg::model::ring<P> ring;
20 typedef bg::model::polygon<P> polygon;
21 typedef bg::model::linestring<P> linestring;
22 typedef bg::model::multi_polygon<polygon> mpolygon;
23 typedef bg::model::multi_linestring<linestring> mlinestring;
24
25 // Touching at corner
26 test_touches<polygon, polygon>
27 (
28 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
29 "POLYGON((100 100,100 200,200 200, 200 100,100 100))",
30 true
31 );
32
33 // Intersecting at corner
34 test_touches<polygon, polygon>
35 (
36 "POLYGON((0 0,0 100,101 101,100 0,0 0))",
37 "POLYGON((100 100,100 200,200 200, 200 100,100 100))",
38 false
39 );
40
41 // Touching at side (interior of a segment)
42 test_touches<polygon, polygon>
43 (
44 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
45 "POLYGON((200 0,100 50,200 100,200 0))",
46 true
47 );
48
49 // Touching at side (partly collinear)
50 test_touches<polygon, polygon>
51 (
52 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
53 "POLYGON((200 20,100 20,100 80,200 80,200 20))",
54 true
55 );
56
57 // Completely equal
58 test_touches<polygon, polygon>
59 (
60 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
61 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
62 false
63 );
64
65 // Spatially equal
66 test_touches<polygon, polygon>
67 (
68 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
69 "POLYGON((0 0,0 100,100 100,100 80,100 20,100 0,0 0))",
70 false
71 );
72
73 // Spatially equal (without equal segments)
74 test_touches<polygon, polygon>
75 (
76 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
77 "POLYGON((0 0,0 50,0 100,50 100,100 100,100 50,100 0,50 0,0 0))",
78 false
79 );
80
81
82 // Touching at side (opposite equal)
83 test_touches<polygon, polygon>
84 (
85 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
86 "POLYGON((200 0,100 0,100 100,200 100,200 0))",
87 true
88 );
89
90 // Touching at side (opposite equal - but with real "equal" turning point)
91 test_touches<polygon, polygon>
92 (
93 "POLYGON((0 0,0 100,100 100,100 80,100 20,100 0,0 0))",
94 "POLYGON((200 0,100 0,100 20,100 80,100 100,200 100,200 0))",
95 true
96 );
97 // First partly collinear to side, than overlapping
98 test_touches<polygon, polygon>
99 (
100 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
101 "POLYGON((200 20,100 20,100 50,50 50,50 80,100 80,200 80,200 20))",
102 false
103 );
104
105 // Touching interior (= no touch)
106 test_touches<polygon, polygon>
107 (
108 "POLYGON((0 0,0 100,100 100,100 0,0 0))",
109 "POLYGON((20 20,20 80,100 50,20 20))",
110 false
111 );
112
113 // Fitting in hole
114 test_touches<polygon, polygon>
115 (
116 "POLYGON((0 0,0 100,100 100,100 0,0 0),(40 40,60 40,60 60,40 60,40 40))",
117 "POLYGON((40 40,40 60,60 60,60 40,40 40))",
118 true
119 );
120
121 // mysql 21873343
122 test_touches<polygon, polygon>
123 (
124 "POLYGON((0 0,0 10,10 10,10 0,0 0), (0 8, 8 5, 8 8, 0 8))",
125 "POLYGON((0 8,-8 5,-8 8,0 8))",
126 true
127 );
128 test_touches<polygon, polygon>
129 (
130 "POLYGON((0 0,0 10,10 10,10 0,0 0), (0 6, 6 3, 6 6, 0 6))",
131 "POLYGON((0 6,-6 3,-6 6,0 6))",
132 true
133 );
134
135 // Point-Polygon
136 test_touches<P, ring>("POINT(40 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true);
137 test_touches<P, polygon>("POINT(40 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true);
138 test_touches<P, polygon>("POINT(60 60)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true);
139 test_touches<P, polygon>("POINT(50 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", false);
140 test_touches<P, polygon>("POINT(30 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", false);
141
142 // Point-MultiPolygon
143 test_touches<P, mpolygon>("POINT(40 50)", "MULTIPOLYGON(((40 40,40 60,60 60,60 40,40 40)),((0 0,0 10,10 10,10 0)))", true);
144
145 // Point-Linestring
146 test_touches<P, linestring>("POINT(0 0)", "LINESTRING(0 0, 2 2, 10 2)", true);
147 test_touches<P, linestring>("POINT(2 2)", "LINESTRING(0 0, 2 2, 10 2)", false);
148 test_touches<P, linestring>("POINT(1 1)", "LINESTRING(0 0, 2 2, 10 2)", false);
149 test_touches<P, linestring>("POINT(5 5)", "LINESTRING(0 0, 2 2, 10 2)", false);
150
151 // Point-MultiLinestring
152 test_touches<P, mlinestring>("POINT(0 0)", "MULTILINESTRING((0 0, 2 2, 10 2),(5 5, 6 6))", true);
153 test_touches<P, mlinestring>("POINT(0 0)", "MULTILINESTRING((0 0, 2 2, 10 2),(0 0, 6 6))", false);
154
155 // Linestring-Linestring
156 test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(0 0,0 2)", true);
157 test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(2 0,2 2)", true);
158 test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(0 2,0 0)", true);
159 test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(2 2,2 0)", true);
160 test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(0 0,0 2)", true);
161 test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(2 0,2 2)", true);
162 test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(0 2,0 0)", true);
163 test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(2 2,2 0)", true);
164 test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(1 0,1 1)", true);
165 test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(1 1,1 0)", true);
166 test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(1 0,1 1)", true);
167 test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(1 1,1 0)", true);
168
169 test_touches<linestring, linestring>("LINESTRING(0 0,10 0)", "LINESTRING(0 0,5 5,10 0)", true);
170 test_touches<linestring, linestring>("LINESTRING(0 0,10 10)", "LINESTRING(0 0,0 5,10 5)", false);
171
172 test_touches<linestring, linestring>("LINESTRING(0 5,5 6,10 5)", "LINESTRING(0 7,5 6,10 7)", false);
173 test_touches<linestring, linestring>("LINESTRING(0 5,5 6,10 5)", "LINESTRING(10 7,5 6,0 7)", false);
174 test_touches<linestring, linestring>("LINESTRING(10 5,5 6,0 5)", "LINESTRING(0 7,5 6,10 7)", false);
175 test_touches<linestring, linestring>("LINESTRING(10 5,5 6,0 5)", "LINESTRING(10 7,5 6,0 7)", false);
176
177 test_touches<linestring, linestring>("LINESTRING(0 0,1 1,2 2)", "LINESTRING(2 0,2 2,1 2,1 1)", true);
178 test_touches<linestring, linestring>("LINESTRING(2 2,1 1,0 0)", "LINESTRING(2 0,2 2,1 2,1 1)", true);
179 test_touches<linestring, linestring>("LINESTRING(0 0,1 1,2 2)", "LINESTRING(1 1,1 2,2 2,2 0)", true);
180 test_touches<linestring, linestring>("LINESTRING(2 2,1 1,0 0)", "LINESTRING(1 1,1 2,2 2,2 0)", true);
181
182 test_touches<linestring, linestring>("LINESTRING(0 0,1 1,0 1)", "LINESTRING(1 1,2 2,1 2,1 1)", false);
183
184 test_touches<linestring, mlinestring>("LINESTRING(0 0,1 1,0 1)", "MULTILINESTRING((1 1,2 2),(1 2,1 1))", false);
185
186 //Linestring-Polygon
187 test_touches<linestring, polygon>("LINESTRING(10 0,15 5,10 10,5 15,5 10,0 10,5 15,5 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
188 test_touches<linestring, polygon>("LINESTRING(5 10,5 15,0 10,5 10,5 15,10 10,15 5,10 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
189 test_touches<linestring, polygon>("LINESTRING(5 10,5 15,0 10,5 10,5 15,10 10,5 5,10 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
190 test_touches<linestring, ring>("LINESTRING(0 15,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
191 test_touches<linestring, polygon>("LINESTRING(0 15,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
192 test_touches<linestring, polygon>("LINESTRING(0 15,5 10,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
193 test_touches<linestring, polygon>("LINESTRING(10 15,5 10,0 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
194
195 test_touches<linestring, polygon>("LINESTRING(0 0,3 3)", "POLYGON((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0))", true);
196
197 test_touches<linestring, mpolygon>("LINESTRING(-1 -1,3 3)", "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)))", true);
198
199 test_touches<mlinestring, mpolygon>("MULTILINESTRING((0 0,11 11))", "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)))", false);
200 }
201
202 int test_main( int , char* [] )
203 {
204 test_all<bg::model::d2::point_xy<double> >();
205
206 #if defined(HAVE_TTMATH)
207 test_all<bg::model::d2::point_xy<ttmath_big> >();
208 #endif
209
210 return 0;
211 }
212
213 /*
214 with viewy as
215 (
216 select geometry::STGeomFromText('POLYGON((0 0,0 100,100 100,100 0,0 0))',0) as p
217 , geometry::STGeomFromText('POLYGON((200 0,100 50,200 100,200 0))',0) as q
218 )
219 -- select p from viewy union all select q from viewy
220 select p.STTouches(q) from viewy
221 */