]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | // Copyright (c) 2008-2015 Bruno Lalande, Paris, France. | |
6 | // Copyright (c) 2009-2015 Mateusz Loskot, London, UK. | |
7 | ||
b32b8144 | 8 | // This file was modified by Oracle on 2015, 2016. |
7c673cae FG |
9 | // Modifications copyright (c) 2015, Oracle and/or its affiliates. |
10 | ||
b32b8144 | 11 | // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle |
7c673cae FG |
12 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle |
13 | ||
14 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library | |
15 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
16 | ||
17 | // Use, modification and distribution is subject to the Boost Software License, | |
18 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
19 | // http://www.boost.org/LICENSE_1_0.txt) | |
20 | ||
21 | #include <boost/numeric/conversion/bounds.hpp> | |
22 | ||
23 | #include "test_envelope.hpp" | |
24 | ||
25 | #include <boost/geometry/geometries/geometries.hpp> | |
26 | #include <boost/geometry/geometries/point_xy.hpp> | |
27 | #include <boost/geometry/geometries/adapted/c_array.hpp> | |
28 | #include <boost/geometry/geometries/adapted/boost_tuple.hpp> | |
29 | #include <boost/geometry/geometries/adapted/std_pair_as_segment.hpp> | |
30 | #include <test_common/test_point.hpp> | |
31 | ||
32 | BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) | |
33 | BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) | |
34 | ||
35 | ||
36 | template <typename P> | |
37 | void test_2d() | |
38 | { | |
39 | test_envelope<P>("POINT(1 1)", 1, 1, 1, 1); | |
40 | test_envelope<bg::model::linestring<P> >("LINESTRING(1 1,2 2)", 1, 2, 1, 2); | |
41 | test_envelope<bg::model::polygon<P> >("POLYGON((1 1,1 3,3 3,3 1,1 1))", 1, 3, 1, 3); | |
42 | ||
43 | test_envelope<bg::model::ring<P> >("POLYGON((1 1,1 3,3 3,3 1,1 1))", 1, 3, 1, 3); | |
44 | test_envelope<bg::model::box<P> >("BOX(1 1,3 3)", 1, 3, 1, 3); | |
45 | ||
46 | // Triangle, closed and open, and CCW. | |
47 | // Note that for the envelope algorithm, | |
48 | // these combinations should theoretically not differ | |
49 | test_envelope<bg::model::ring<P> >("POLYGON((4 1,0 7,7 9,4 1))", 0, 7, 1, 9); | |
50 | test_envelope<bg::model::ring<P, true, false> >("POLYGON((4 1,0 7,7 9))", 0, 7, 1, 9); | |
51 | test_envelope<bg::model::ring<P, false> >("POLYGON((4 1,7 9,0 7,4 1))", 0, 7, 1, 9); | |
52 | test_envelope<bg::model::ring<P, false, false> >("POLYGON((4 1,7 9,0 7))", 0, 7, 1, 9); | |
53 | ||
54 | typedef std::pair<P, P> segment_type; | |
55 | test_envelope<segment_type>("SEGMENT(1 1,3 3)", 1, 3, 1, 3); | |
56 | } | |
57 | ||
58 | template <typename P> | |
59 | void test_3d() | |
60 | { | |
61 | test_envelope<P>("POINT(1 2 3)", 1, 1, 2, 2, 3, 3); | |
62 | test_envelope<P>("POINT(3 2 1)", 3, 3, 2, 2, 1, 1); | |
63 | test_envelope<bg::model::linestring<P> >("LINESTRING(1 1 1,2 2 2)", 1, 2, 1, 2, 1, 2); | |
64 | test_envelope<bg::model::box<P> >("BOX(1 1 1,3 3 3)", 1, 3, 1, 3, 1, 3); | |
65 | } | |
66 | ||
67 | template <typename Geometry> | |
68 | void test_empty_geometry(std::string const& wkt) | |
69 | { | |
70 | typedef typename bg::coordinate_type<Geometry>::type ct; | |
71 | ct high_val = boost::numeric::bounds<ct>::highest(); | |
72 | ct low_val = boost::numeric::bounds<ct>::lowest(); | |
73 | ||
74 | test_envelope<Geometry>(wkt, high_val, low_val, high_val, low_val); | |
75 | } | |
76 | ||
77 | template <typename P> | |
78 | void test_empty() | |
79 | { | |
80 | test_empty_geometry<bg::model::linestring<P> >("LINESTRING()"); | |
81 | test_empty_geometry<bg::model::ring<P> >("POLYGON(())"); | |
82 | ||
83 | test_empty_geometry<bg::model::polygon<P> >("POLYGON(())"); | |
84 | ||
85 | test_empty_geometry<bg::model::multi_point<P> >("MULTIPOINT()"); | |
86 | ||
87 | test_empty_geometry | |
88 | < | |
89 | bg::model::multi_linestring<bg::model::linestring<P> > | |
90 | >("MULTILINESTRING()"); | |
91 | ||
92 | test_empty_geometry | |
93 | < | |
94 | bg::model::multi_polygon<bg::model::polygon<P> > | |
95 | >("MULTIPOLYGON()"); | |
96 | } | |
97 | ||
98 | template <typename P> | |
99 | void test_invalid() | |
100 | { | |
101 | // polygon with empty exterior and interior rings | |
102 | test_empty_geometry<bg::model::polygon<P> >("POLYGON((),(),())"); | |
103 | ||
104 | // polygon with empty interior rings | |
105 | test_envelope | |
106 | < | |
107 | bg::model::polygon<P> | |
108 | >("POLYGON((1 2,1 20,22 20,22 2,1 2),(),())", | |
109 | 1, 22, 2, 20); | |
110 | ||
111 | // another polygon with empty interior rings | |
112 | test_envelope | |
113 | < | |
114 | bg::model::polygon<P> | |
115 | >("POLYGON((1 2,1 20,22 20,22 2,1 2),(),(3 4,19 4,19 18,3 18,3 4),())", | |
116 | 1, 22, 2, 20); | |
117 | ||
118 | // polygon with empty exterior ring | |
119 | test_envelope | |
120 | < | |
121 | bg::model::polygon<P> | |
122 | >("POLYGON((),(),(3 4,19 4,19 18,3 18,3 4),())", | |
123 | 3, 19, 4, 18); | |
124 | ||
125 | // another polygon with empty exterior ring | |
126 | test_envelope | |
127 | < | |
128 | bg::model::polygon<P> | |
129 | >("POLYGON((),(),(3 4,19 4,19 18,3 18,3 4),(4 5,18 5,18 17,4 17,4 5))", | |
130 | 3, 19, 4, 18); | |
131 | ||
132 | // yet one more polygon with empty exterior ring | |
133 | test_envelope | |
134 | < | |
135 | bg::model::polygon<P> | |
136 | >("POLYGON((),(),(4 5,18 5,18 17,4 17,4 5),(3 4,19 4,19 18,3 18,3 4))", | |
137 | 3, 19, 4, 18); | |
138 | ||
139 | // multilinestring with empty linestrings | |
140 | test_empty_geometry | |
141 | < | |
142 | bg::model::multi_linestring<bg::model::linestring<P> > | |
143 | >("MULTILINESTRING((),(),())"); | |
144 | ||
145 | // multilinestring with empty and non-empty linestrings | |
146 | test_envelope | |
147 | < | |
148 | bg::model::multi_linestring<bg::model::linestring<P> > | |
149 | >("MULTILINESTRING((),(10 20),())", 10, 10, 20, 20); | |
150 | ||
151 | // multipolygon with empty polygon | |
152 | test_empty_geometry | |
153 | < | |
154 | bg::model::multi_polygon<bg::model::polygon<P> > | |
155 | >("MULTIPOLYGON((()))"); | |
156 | ||
157 | // multipolygon with many empty polygons | |
158 | test_empty_geometry | |
159 | < | |
160 | bg::model::multi_polygon<bg::model::polygon<P> > | |
161 | >("MULTIPOLYGON(((),(),()),(()),((),(),(),(),()))"); | |
162 | ||
163 | // multipolygon with empty polygons and non-empty (valid) polygon | |
164 | test_envelope | |
165 | < | |
166 | bg::model::multi_polygon<bg::model::polygon<P> > | |
167 | >("MULTIPOLYGON(((),(),()),((10 30,10 40,20 30,10 30)),\ | |
168 | ((),(),()),(()))", 10, 20, 30, 40); | |
169 | ||
170 | // multipolygon with empty polygons and non-empty (valid) polygon | |
171 | // that has an interior ring | |
172 | test_envelope | |
173 | < | |
174 | bg::model::multi_polygon<bg::model::polygon<P> > | |
175 | >("MULTIPOLYGON(((),(),()),(()),\ | |
176 | ((1 2,1 20,22 20,22 2,1 2),(3 4,19 4,19 18,3 18,3 4)),(()))", | |
177 | 1, 22, 2, 20); | |
178 | ||
179 | // multipolygon with empty polygons and non-empty (invalid) polygon | |
180 | // that has an interior ring but empty exterior ring | |
181 | test_envelope | |
182 | < | |
183 | bg::model::multi_polygon<bg::model::polygon<P> > | |
184 | >("MULTIPOLYGON(((),(),()),(()),((),(3 4,19 4,19 18,3 18,3 4)),(()))", | |
185 | 3, 19, 4, 18); | |
186 | ||
187 | // multipolygon with empty polygons and non-empty (invalid) polygon | |
188 | // that has an interior ring but empty exterior ring | |
189 | test_envelope | |
190 | < | |
191 | bg::model::multi_polygon<bg::model::polygon<P> > | |
192 | >("MULTIPOLYGON(((),(),()),((),(),(3 4,19 4,19 18,3 18,3 4),()),(()))", | |
193 | 3, 19, 4, 18); | |
194 | ||
195 | // multipolygon with empty polygons and non-empty (invalid) polygon | |
196 | // that has two non-empty interior rings but empty exterior ring | |
197 | test_envelope | |
198 | < | |
199 | bg::model::multi_polygon<bg::model::polygon<P> > | |
200 | >("MULTIPOLYGON(((),(),()),\ | |
201 | ((),(),(3 4,19 4,19 18,3 18,3 4),(4 5,18 5,18 17,4 17,4 5),()),\ | |
202 | (()))", | |
203 | 3, 19, 4, 18); | |
204 | } | |
205 | ||
206 | int test_main(int, char* []) | |
207 | { | |
208 | //test_2d<int[2]>(); | |
209 | //test_2d<float[2]>(); | |
210 | //test_2d<double[2]>(); | |
211 | test_2d<boost::tuple<float, float> >(); | |
212 | test_2d<bg::model::d2::point_xy<int> >(); | |
213 | test_2d<bg::model::d2::point_xy<float> >(); | |
214 | test_2d<bg::model::d2::point_xy<double> >(); | |
215 | ||
216 | test_3d<test::test_point>(); | |
217 | test_3d<boost::tuple<int, int, int> >(); | |
218 | ||
219 | test_empty<boost::tuple<float, float> >(); | |
220 | test_empty<bg::model::d2::point_xy<int> >(); | |
221 | test_empty<bg::model::d2::point_xy<float> >(); | |
222 | test_empty<bg::model::d2::point_xy<double> >(); | |
223 | ||
224 | test_invalid<boost::tuple<float, float> >(); | |
225 | test_invalid<bg::model::d2::point_xy<int> >(); | |
226 | test_invalid<bg::model::d2::point_xy<float> >(); | |
227 | test_invalid<bg::model::d2::point_xy<double> >(); | |
228 | ||
7c673cae FG |
229 | return 0; |
230 | } |