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

source code of boost/libs/geometry/test/algorithms/envelope_expand/envelope.cpp