]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/correct.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
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
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
21 #include <algorithms/test_correct.hpp>
23 #include <boost/geometry/strategies/strategies.hpp>
25 #include <boost/geometry/io/dsv/write.hpp>
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>
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
)
43 bg::read_wkt(wkt
, geometry
);
44 bg::correct(geometry
);
46 std::ostringstream out
;
47 out
<< bg::dsv(geometry
);
49 BOOST_CHECK_EQUAL(out
.str(), expected
);
58 void test_ring_polygon()
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))";
67 test_geometry
<bg::model::ring
<P
> >(cw_ring
, cw_ring
);
70 test_geometry
<bg::model::ring
<P
> >(ccw_ring
, cw_ring
);
72 // ccw-ring, input ccw-ring, already correct
73 test_geometry
<bg::model::ring
<P
, false> >(ccw_ring
, ccw_ring
);
75 // ccw-ring, input cw-ring, corrected
76 test_geometry
<bg::model::ring
<P
, false> >(cw_ring
, ccw_ring
);
78 // open-ring, input ccw-ring, already correct
79 test_geometry
<bg::model::ring
<P
, true, false> >(cw_open_ring
, cw_open_ring
);
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))");
87 test_geometry
<bg::model::ring
<P
> >(
91 // counter clockwise, cw_ring
92 test_geometry
<bg::model::ring
<P
, false> >(ccw_ring
, ccw_ring
);
94 test_geometry
<bg::model::ring
<P
, false> >(cw_ring
, ccw_ring
);
98 test_geometry
<bg::model::polygon
<P
> >(cw_ring
, cw_ring
);
100 test_geometry
<bg::model::polygon
<P
> >(
101 "POLYGON((0 0,1 0,1 1,0 1,0 0))",
103 // wrong order & not closed
104 test_geometry
<bg::model::polygon
<P
> >(
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))";
114 // with holes: cw_ring
115 test_geometry
<bg::model::polygon
<P
> >(
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))",
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))",
127 // wrong order of main and hole
128 test_geometry
<bg::model::polygon
<P
> >(ccw_holey_polygon
, cw_holey_polygon
);
130 // test the counter-clockwise
131 test_geometry
<bg::model::polygon
<P
, false> >(
132 ccw_holey_polygon
, ccw_holey_polygon
);
136 template <typename P
>
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))";
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
);
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
);
157 template <typename P
>
160 test_ring_polygon
<P
>();
165 int test_main(int, char* [])
167 //test_all<int[2]>();
168 //test_all<float[2]>(); not yet because cannot be copied, for polygon
169 //test_all<double[2]>();
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> >();
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
> > >();
178 #if defined(HAVE_TTMATH)
179 test_all
<bg::model::d2::point_xy
<ttmath_big
> >();