]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/correct_closure.cpp
4 // Copyright (c) 2017 Barend Gehrels, Amsterdam, the Netherlands.
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
12 #include <geometry_test_common.hpp>
14 #include <boost/geometry/strategies/strategies.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/ring.hpp>
18 #include <boost/geometry/geometries/polygon.hpp>
20 #include <boost/geometry/algorithms/correct_closure.hpp>
21 #include <boost/geometry/io/wkt/read.hpp>
22 #include <boost/geometry/io/wkt/write.hpp>
24 #include <boost/variant/variant.hpp>
27 template <typename BaseGeometry
, typename Geometry
>
28 void check_geometry(Geometry
const& geometry
, std::string
const& expected
)
30 std::ostringstream out
;
31 out
<< bg::wkt_manipulator
<Geometry
>(geometry
, false);
32 BOOST_CHECK_EQUAL(out
.str(), expected
);
35 template <typename Geometry
>
36 void test_geometry(std::string
const& wkt
, std::string
const& expected
)
39 bg::read_wkt(wkt
, geometry
);
42 bg::correct_closure(geometry
);
43 check_geometry
<Geometry
>(geometry
, expected
);
45 // Test varianted type
46 boost::variant
<Geometry
> v(geometry
);
47 bg::correct_closure(v
);
48 check_geometry
<Geometry
>(v
, expected
);
54 typedef bg::model::ring
<P
, true, true> cw_closed_ring_type
;
55 typedef bg::model::ring
<P
, true, false> cw_open_ring_type
;
56 typedef bg::model::ring
<P
, false, true> ccw_closed_ring_type
;
57 typedef bg::model::ring
<P
, false, false> ccw_open_ring_type
;
59 // Define clockwise and counter clockwise polygon
60 std::string cw_ring
= "POLYGON((0 0,0 1,1 1,1 0,0 0))";
61 std::string cw_open_ring
= "POLYGON((0 0,0 1,1 1,1 0))";
63 std::string ccw_ring
= "POLYGON((0 0,1 0,1 1,0 1,0 0))";
64 std::string ccw_open_ring
= "POLYGON((0 0,1 0,1 1,0 1))";
66 // Cases which should be closed or opened
67 test_geometry
<cw_closed_ring_type
>(cw_open_ring
, cw_ring
);
68 test_geometry
<cw_open_ring_type
>(cw_ring
, cw_open_ring
);
69 test_geometry
<ccw_closed_ring_type
>(ccw_open_ring
, ccw_ring
);
70 test_geometry
<ccw_open_ring_type
>(ccw_ring
, ccw_open_ring
);
72 // Cases which are incorrect but should still be closed or opened
73 test_geometry
<cw_closed_ring_type
>(ccw_open_ring
, ccw_ring
);
74 test_geometry
<ccw_open_ring_type
>(cw_ring
, cw_open_ring
);
76 // Cases where no action is necessary (even if order is incorrect)
77 test_geometry
<cw_closed_ring_type
>(cw_ring
, cw_ring
);
78 test_geometry
<cw_closed_ring_type
>(ccw_ring
, ccw_ring
);
79 test_geometry
<cw_open_ring_type
>(cw_open_ring
, cw_open_ring
);
80 test_geometry
<cw_open_ring_type
>(ccw_open_ring
, ccw_open_ring
);
81 test_geometry
<ccw_closed_ring_type
>(cw_ring
, cw_ring
);
82 test_geometry
<ccw_closed_ring_type
>(ccw_ring
, ccw_ring
);
83 test_geometry
<ccw_open_ring_type
>(cw_open_ring
, cw_open_ring
);
84 test_geometry
<ccw_open_ring_type
>(ccw_open_ring
, ccw_open_ring
);
87 std::string cw_polygon
=
88 "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,2 1,2 2,1 2,1 1))";
90 std::string cw_open_polygon
=
91 "POLYGON((0 0,0 4,4 4,4 0),(1 1,2 1,2 2,1 2))";
93 typedef bg::model::polygon
<P
, true, true> cw_closed_polygon_type
;
94 typedef bg::model::polygon
<P
, true, false> cw_open_polygon_type
;
96 test_geometry
<cw_closed_polygon_type
>(cw_open_polygon
, cw_polygon
);
97 test_geometry
<cw_open_polygon_type
>(cw_polygon
, cw_open_polygon
);
99 test_geometry
<cw_closed_polygon_type
>(cw_polygon
, cw_polygon
);
100 test_geometry
<cw_open_polygon_type
>(cw_open_polygon
, cw_open_polygon
);
104 int test_main(int, char* [])
106 test_all
<bg::model::d2::point_xy
<int> >();
107 test_all
<bg::model::d2::point_xy
<float> >();
108 test_all
<bg::model::d2::point_xy
<double> >();
110 test_all
<bg::model::point
<double, 2, bg::cs::spherical_equatorial
<bg::degree
> > >();
111 test_all
<bg::model::point
<double, 2, bg::cs::geographic
<bg::degree
> > >();