]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/index/test/algorithms/is_valid.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / index / test / algorithms / is_valid.cpp
1 // Boost.Geometry Index
2 // Unit Test
3
4 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
5
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)
9
10 #include <algorithm>
11
12 #include <geometry_index_test_common.hpp>
13
14 #include <boost/geometry/index/detail/algorithms/is_valid.hpp>
15
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/point.hpp>
18 #include <boost/geometry/geometries/box.hpp>
19
20 //#define BOOST_GEOMETRY_TEST_DEBUG
21
22 template <typename Geometry>
23 void test(Geometry const& geometry, bool expected_value)
24 {
25 bool value = bgi::detail::is_valid(geometry);
26
27 #ifdef BOOST_GEOMETRY_TEST_DEBUG
28 std::ostringstream out;
29 out << typeid(typename bg::coordinate_type<Geometry>::type).name()
30 << " "
31 << typeid(bool).name()
32 << " "
33 << "is_valid : " << value
34 << std::endl;
35 std::cout << out.str();
36 #endif
37
38 BOOST_CHECK(value == expected_value);
39 }
40
41 template <typename Box>
42 void test_box(std::string const& wkt, bool expected_value)
43 {
44 Box box;
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);
52 }
53
54 void test_large_integers()
55 {
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;
58
59 bg::model::box<int_point_type> int_box;
60 bg::model::box<double_point_type> double_box;
61
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);
65
66 BOOST_CHECK(bgi::detail::is_valid(int_box) == bgi::detail::is_valid(double_box));
67
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);
71
72 BOOST_CHECK(bgi::detail::is_valid(int_box) == bgi::detail::is_valid(double_box));
73 }
74
75 int test_main(int, char* [])
76 {
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;
80
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;
84
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);
91
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);
98
99 test_large_integers();
100
101 return 0;
102 }