• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // This file was modified by Oracle on 2014, 2016.
7 // Modifications copyright (c) 2014-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 
15 #include <strategies/test_within.hpp>
16 
17 
18 template <typename Point>
test_cartesian()19 void test_cartesian()
20 {
21     typedef bg::model::polygon<Point> polygon;
22 
23     std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))";
24     std::string const triangle = "POLYGON((0 0,0 4,6 0,0 0))";
25     std::string const with_hole = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))";
26 
27     bg::strategy::within::winding<Point> s;
28 
29 
30     test_geometry<Point, polygon>("b1", "POINT(1 1)", box, s, true);
31     test_geometry<Point, polygon>("b2", "POINT(3 3)", box, s, false);
32 
33     // Test ALL corners (officialy false but some strategies might answer true)
34     test_geometry<Point, polygon>("b3a", "POINT(0 0)", box, s, false);
35     test_geometry<Point, polygon>("b3b", "POINT(0 2)", box, s, false);
36     test_geometry<Point, polygon>("b3c", "POINT(2 2)", box, s, false);
37     test_geometry<Point, polygon>("b3d", "POINT(2 0)", box, s, false);
38 
39     // Test ALL sides (officialy false but some strategies might answer true)
40     test_geometry<Point, polygon>("b4a", "POINT(0 1)", box, s, false);
41     test_geometry<Point, polygon>("b4b", "POINT(1 2)", box, s, false);
42     test_geometry<Point, polygon>("b4c", "POINT(2 1)", box, s, false);
43     test_geometry<Point, polygon>("b4d", "POINT(1 0)", box, s, false);
44 
45 
46     test_geometry<Point, polygon>("t1", "POINT(1 1)", triangle, s, true);
47     test_geometry<Point, polygon>("t2", "POINT(3 3)", triangle, s, false);
48 
49     test_geometry<Point, polygon>("t3a", "POINT(0 0)", triangle, s, false);
50     test_geometry<Point, polygon>("t3b", "POINT(0 4)", triangle, s, false);
51     test_geometry<Point, polygon>("t3c", "POINT(5 0)", triangle, s, false);
52 
53     test_geometry<Point, polygon>("t4a", "POINT(0 2)", triangle, s, false);
54     test_geometry<Point, polygon>("t4b", "POINT(3 2)", triangle, s, false);
55     test_geometry<Point, polygon>("t4c", "POINT(2 0)", triangle, s, false);
56 
57 
58     test_geometry<Point, polygon>("h1", "POINT(0.5 0.5)", with_hole, s, true);
59     test_geometry<Point, polygon>("h2a", "POINT(1.5 1.5)", with_hole, s, false);
60     test_geometry<Point, polygon>("h2b", "POINT(5 5)", with_hole, s, false);
61 
62     test_geometry<Point, polygon>("h3a", "POINT(1 1)", with_hole, s, false);
63     test_geometry<Point, polygon>("h3b", "POINT(2 2)", with_hole, s, false);
64     test_geometry<Point, polygon>("h3c", "POINT(0 0)", with_hole, s, false);
65 
66     test_geometry<Point, polygon>("h4a", "POINT(1 1.5)", with_hole, s, false);
67     test_geometry<Point, polygon>("h4b", "POINT(1.5 2)", with_hole, s, false);
68 
69     // Lying ON (one of the sides of) interior ring
70     test_geometry<Point, polygon>("#77-1", "POINT(6 3.5)",
71         "POLYGON((5 3,5 4,4 4,4 5,3 5,3 6,5 6,5 5,7 5,7 6,8 6,8 5,9 5,9 2,8 2,8 1,7 1,7 2,5 2,5 3),(6 3,8 3,8 4,6 4,6 3))",
72         s, false);
73 }
74 
75 template <typename T>
test_spherical()76 void test_spherical()
77 {
78     typedef bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::degree> > point;
79     typedef bg::model::polygon<point> polygon;
80 
81     bg::strategy::within::winding<point> s;
82 
83 
84     // Ticket #9354
85     test_geometry<point, polygon>(
86         "#9354",
87         "POINT(-78.1239 25.9556)",
88         "POLYGON((-97.08466667 25.95683333, -97.13683333 25.954, -97.1 26, -97.08466667 25.95683333))",
89         s,
90         false);
91 
92     test_geometry<point, polygon>(
93         "sph1N",
94         "POINT(0 10.001)",
95         "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
96         s,
97         bg::strategy::side::spherical_side_formula<>::apply(
98             point(-10, 10),
99             point(10, 10),
100             point(0, (T)10.001)) == -1 // right side
101         /*true*/);
102     test_geometry<point, polygon>(
103         "sph1S",
104         "POINT(0 -10.001)",
105         "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
106         s,
107         bg::strategy::side::spherical_side_formula<>::apply(
108               point(10, -10),
109               point(-10, -10),
110               point(0, (T)-10.001)) == -1 // right side
111       /*true*/);
112 
113     test_geometry<point, polygon>(
114         "sph2S",
115         "POINT(0 10.001)",
116         "POLYGON((-10 20, 10 20, 10 10, -10 10, -10 20))",
117         s,
118         bg::strategy::side::spherical_side_formula<>::apply(
119               point(10, 10),
120               point(-10, 10),
121               point(0, (T)10.001)) == -1 // right side
122         /*false*/);
123 
124     test_geometry<point, polygon>(
125         "sph3N",
126         "POINT(0 10)",
127         "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
128         s,
129         bg::strategy::side::spherical_side_formula<>::apply(
130             point(-10, 10),
131             point(10, 10),
132             point(0, (T)10.001)) == -1 // right side
133         /*true*/);
134     test_geometry<point, polygon>(
135         "sph3S",
136         "POINT(0 -10)",
137         "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
138         s,
139         bg::strategy::side::spherical_side_formula<>::apply(
140               point(10, -10),
141               point(-10, -10),
142               point(0, (T)-10.001)) == -1 // right side
143       /*true*/);
144 
145     test_geometry<point, polygon>(
146         "sphEq1",
147         "POINT(179 10)",
148         "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
149         s,
150         true,
151         false);
152     test_geometry<point, polygon>(
153         "sphEq2",
154         "POINT(179 10)",
155         "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
156         s,
157         false,
158         false);
159     test_geometry<point, polygon>(
160         "sphEq3",
161         "POINT(-179 10)",
162         "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
163         s,
164         true,
165         false);
166     test_geometry<point, polygon>(
167         "sphEq4",
168         "POINT(-179 10)",
169         "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
170         s,
171         false,
172         false);
173 
174     test_geometry<point, polygon>(
175         "sphEq5",
176         "POINT(169 10)",
177         "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
178         s,
179         false,
180         false);
181     test_geometry<point, polygon>(
182         "sphEq6",
183         "POINT(-169 10)",
184         "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
185         s,
186         false,
187         false);
188     test_geometry<point, polygon>(
189         "sphEq7",
190         "POINT(169 10)",
191         "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
192         s,
193         false,
194         false);
195     test_geometry<point, polygon>(
196         "sphEq8",
197         "POINT(-169 10)",
198         "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
199         s,
200         false,
201         false);
202 }
203 
test_main(int,char * [])204 int test_main(int, char* [])
205 {
206     test_cartesian<bg::model::point<float, 2, bg::cs::cartesian> >();
207     test_cartesian<bg::model::point<double, 2, bg::cs::cartesian> >();
208 
209     test_spherical<float>();
210     test_spherical<double>();
211 
212 #if defined(HAVE_TTMATH)
213     test_cartesian<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
214     test_spherical<ttmath_big>();
215 #endif
216 
217     return 0;
218 }
219