]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. | |
6 | // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. | |
7 | ||
b32b8144 FG |
8 | // This file was modified by Oracle on 2017. |
9 | // Modifications copyright (c) 2017 Oracle and/or its affiliates. | |
10 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
11 | ||
7c673cae FG |
12 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library |
13 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
14 | ||
15 | // Use, modification and distribution is subject to the Boost Software License, | |
16 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
17 | // http://www.boost.org/LICENSE_1_0.txt) | |
18 | ||
19 | #include <sstream> | |
20 | ||
21 | #include <algorithms/test_correct.hpp> | |
22 | ||
23 | #include <boost/geometry/strategies/strategies.hpp> | |
24 | ||
25 | #include <boost/geometry/io/dsv/write.hpp> | |
26 | ||
27 | #include <boost/geometry/geometries/point_xy.hpp> | |
28 | #include <boost/geometry/geometries/box.hpp> | |
29 | #include <boost/geometry/geometries/ring.hpp> | |
30 | #include <boost/geometry/geometries/polygon.hpp> | |
31 | ||
32 | ||
33 | // Note: 3D/box test cannot be done using WKT because: | |
34 | // -> wkt-box does not exist | |
35 | // -> so it is converted to a ring | |
36 | // -> ring representation of 3d-box is not supported, nor feasible | |
37 | // -> so it uses DSV which can represent a box | |
38 | template <typename Geometry> | |
39 | void test_geometry_dsv(std::string const& wkt, std::string const& expected) | |
40 | { | |
41 | Geometry geometry; | |
42 | ||
43 | bg::read_wkt(wkt, geometry); | |
44 | bg::correct(geometry); | |
45 | ||
46 | std::ostringstream out; | |
47 | out << bg::dsv(geometry); | |
48 | ||
49 | BOOST_CHECK_EQUAL(out.str(), expected); | |
50 | } | |
51 | ||
52 | ||
53 | ||
54 | ||
55 | ||
56 | ||
57 | template <typename P> | |
b32b8144 | 58 | void test_ring_polygon() |
7c673cae FG |
59 | { |
60 | // Define clockwise and counter clockwise polygon | |
61 | std::string cw_ring = "POLYGON((0 0,0 1,1 1,1 0,0 0))"; | |
62 | std::string ccw_ring = "POLYGON((0 0,1 0,1 1,0 1,0 0))"; | |
63 | std::string cw_open_ring = "POLYGON((0 0,0 1,1 1,1 0))"; | |
64 | std::string ccw_open_ring = "POLYGON((0 0,1 0,1 1,0 1))"; | |
65 | ||
66 | // already cw_ring | |
67 | test_geometry<bg::model::ring<P> >(cw_ring, cw_ring); | |
68 | ||
69 | // wrong order | |
70 | test_geometry<bg::model::ring<P> >(ccw_ring, cw_ring); | |
71 | ||
72 | // ccw-ring, input ccw-ring, already correct | |
73 | test_geometry<bg::model::ring<P, false> >(ccw_ring, ccw_ring); | |
74 | ||
75 | // ccw-ring, input cw-ring, corrected | |
76 | test_geometry<bg::model::ring<P, false> >(cw_ring, ccw_ring); | |
77 | ||
78 | // open-ring, input ccw-ring, already correct | |
79 | test_geometry<bg::model::ring<P, true, false> >(cw_open_ring, cw_open_ring); | |
80 | ||
81 | // ccw-ring, input cw-ring, corrected | |
82 | test_geometry<bg::model::ring<P, true, false> >(ccw_open_ring, "POLYGON((0 1,1 1,1 0,0 0))"); | |
83 | ||
84 | ||
85 | ||
86 | // not closed | |
87 | test_geometry<bg::model::ring<P> >( | |
88 | ccw_open_ring, | |
89 | cw_ring); | |
90 | ||
91 | // counter clockwise, cw_ring | |
92 | test_geometry<bg::model::ring<P, false> >(ccw_ring, ccw_ring); | |
93 | ||
94 | test_geometry<bg::model::ring<P, false> >(cw_ring, ccw_ring); | |
95 | ||
96 | ||
97 | // polygon: cw_ring | |
98 | test_geometry<bg::model::polygon<P> >(cw_ring, cw_ring); | |
99 | // wrong order | |
100 | test_geometry<bg::model::polygon<P> >( | |
101 | "POLYGON((0 0,1 0,1 1,0 1,0 0))", | |
102 | cw_ring); | |
103 | // wrong order & not closed | |
104 | test_geometry<bg::model::polygon<P> >( | |
105 | ccw_open_ring, | |
106 | cw_ring); | |
107 | ||
108 | ||
109 | std::string cw_holey_polygon = | |
110 | "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,2 1,2 2,1 2,1 1))"; | |
111 | std::string ccw_holey_polygon = | |
112 | "POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,1 2,2 2,2 1,1 1))"; | |
113 | ||
114 | // with holes: cw_ring | |
115 | test_geometry<bg::model::polygon<P> >( | |
116 | cw_holey_polygon, | |
117 | cw_holey_polygon); | |
118 | // wrong order of main | |
119 | test_geometry<bg::model::polygon<P> >( | |
120 | "POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1))", | |
121 | cw_holey_polygon); | |
122 | // wrong order of hole | |
123 | test_geometry<bg::model::polygon<P> >( | |
124 | "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,1 2,2 2,2 1,1 1))", | |
125 | cw_holey_polygon); | |
126 | ||
127 | // wrong order of main and hole | |
128 | test_geometry<bg::model::polygon<P> >(ccw_holey_polygon, cw_holey_polygon); | |
129 | ||
130 | // test the counter-clockwise | |
131 | test_geometry<bg::model::polygon<P, false> >( | |
132 | ccw_holey_polygon, ccw_holey_polygon); | |
133 | ||
b32b8144 FG |
134 | } |
135 | ||
136 | template <typename P> | |
137 | void test_box() | |
138 | { | |
139 | // Boxes. Reference is an open box (because in this test WKT is not | |
140 | // explicitly closed) | |
141 | std::string proper_box = "POLYGON((0 0,0 2,2 2,2 0))"; | |
7c673cae FG |
142 | test_geometry<bg::model::box<P> >(proper_box, proper_box); |
143 | test_geometry<bg::model::box<P> >("BOX(0 0,2 2)", proper_box); | |
144 | test_geometry<bg::model::box<P> >("BOX(2 2,0 0)", proper_box); | |
145 | test_geometry<bg::model::box<P> >("BOX(0 2,2 0)", proper_box); | |
146 | ||
147 | // Cubes | |
148 | typedef bg::model::box<bg::model::point<double, 3, bg::cs::cartesian> > box3d; | |
149 | std::string proper_3d_dsv_box = "((0, 0, 0), (2, 2, 2))"; | |
150 | test_geometry_dsv<box3d>("BOX(0 0 0,2 2 2)", proper_3d_dsv_box); | |
151 | test_geometry_dsv<box3d>("BOX(2 2 2,0 0 0)", proper_3d_dsv_box); | |
152 | test_geometry_dsv<box3d>("BOX(0 2 2,2 0 0)", proper_3d_dsv_box); | |
153 | test_geometry_dsv<box3d>("BOX(2 0 2,0 2 0)", proper_3d_dsv_box); | |
154 | test_geometry_dsv<box3d>("BOX(0 0 2,2 2 0)", proper_3d_dsv_box); | |
155 | } | |
156 | ||
b32b8144 FG |
157 | template <typename P> |
158 | void test_all() | |
159 | { | |
160 | test_ring_polygon<P>(); | |
161 | test_box<P>(); | |
162 | } | |
163 | ||
7c673cae FG |
164 | |
165 | int test_main(int, char* []) | |
166 | { | |
167 | //test_all<int[2]>(); | |
168 | //test_all<float[2]>(); not yet because cannot be copied, for polygon | |
169 | //test_all<double[2]>(); | |
170 | ||
171 | test_all<bg::model::d2::point_xy<int> >(); | |
172 | test_all<bg::model::d2::point_xy<float> >(); | |
173 | test_all<bg::model::d2::point_xy<double> >(); | |
174 | ||
b32b8144 FG |
175 | test_ring_polygon<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); |
176 | test_ring_polygon<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >(); | |
177 | ||
7c673cae FG |
178 | return 0; |
179 | } |