]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/index/test/algorithms/is_valid.cpp
1 // Boost.Geometry Index
4 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
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_index_test_common.hpp>
14 #include <boost/geometry/index/detail/algorithms/is_valid.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/point.hpp>
18 #include <boost/geometry/geometries/box.hpp>
20 //#define BOOST_GEOMETRY_TEST_DEBUG
22 template <typename Geometry
>
23 void test(Geometry
const& geometry
, bool expected_value
)
25 bool value
= bgi::detail::is_valid(geometry
);
27 #ifdef BOOST_GEOMETRY_TEST_DEBUG
28 std::ostringstream out
;
29 out
<< typeid(typename
bg::coordinate_type
<Geometry
>::type
).name()
31 << typeid(bool).name()
33 << "is_valid : " << value
35 std::cout
<< out
.str();
38 BOOST_CHECK(value
== expected_value
);
41 template <typename Box
>
42 void test_box(std::string
const& wkt
, bool expected_value
)
45 bg::read_wkt(wkt
, box
);
46 test(box
, expected_value
);
47 typename
bg::point_type
<Box
>::type temp_pt
;
48 temp_pt
= box
.min_corner();
49 box
.min_corner() = box
.max_corner();
50 box
.max_corner() = temp_pt
;
51 test(box
, !expected_value
);
54 void test_large_integers()
56 typedef bg::model::point
<int, 2, bg::cs::cartesian
> int_point_type
;
57 typedef bg::model::point
<double, 2, bg::cs::cartesian
> double_point_type
;
59 bg::model::box
<int_point_type
> int_box
;
60 bg::model::box
<double_point_type
> double_box
;
62 std::string
const box_li
= "POLYGON((1536119 192000, 1872000 528000))";
63 bg::read_wkt(box_li
, int_box
);
64 bg::read_wkt(box_li
, double_box
);
66 BOOST_CHECK(bgi::detail::is_valid(int_box
) == bgi::detail::is_valid(double_box
));
68 std::string
const box_li2
= "POLYGON((1872000 528000, 1536119 192000))";
69 bg::read_wkt(box_li2
, int_box
);
70 bg::read_wkt(box_li2
, double_box
);
72 BOOST_CHECK(bgi::detail::is_valid(int_box
) == bgi::detail::is_valid(double_box
));
75 int test_main(int, char* [])
77 typedef bg::model::point
<int, 2, bg::cs::cartesian
> P2ic
;
78 typedef bg::model::point
<float, 2, bg::cs::cartesian
> P2fc
;
79 typedef bg::model::point
<double, 2, bg::cs::cartesian
> P2dc
;
81 typedef bg::model::point
<int, 3, bg::cs::cartesian
> P3ic
;
82 typedef bg::model::point
<float, 3, bg::cs::cartesian
> P3fc
;
83 typedef bg::model::point
<double, 3, bg::cs::cartesian
> P3dc
;
85 test(P2ic(0, 0), true);
86 test(P2fc(0, 0), true);
87 test(P2dc(0, 0), true);
88 test(P3ic(0, 0, 0), true);
89 test(P3fc(0, 0, 0), true);
90 test(P3dc(0, 0, 0), true);
92 test_box
<bg::model::box
<P2ic
> >("POLYGON((0 1,2 4))", true);
93 test_box
<bg::model::box
<P2fc
> >("POLYGON((0 1,2 4))", true);
94 test_box
<bg::model::box
<P2dc
> >("POLYGON((0 1,2 4))", true);
95 test_box
<bg::model::box
<P3ic
> >("POLYGON((0 1 2,2 4 6))", true);
96 test_box
<bg::model::box
<P3fc
> >("POLYGON((0 1 2,2 4 6))", true);
97 test_box
<bg::model::box
<P3dc
> >("POLYGON((0 1 2,2 4 6))", true);
99 test_large_integers();