]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/policies/rescale_policy.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / policies / rescale_policy.cpp
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
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15 #include <iostream>
16 #include <string>
17
18 #include <boost/foreach.hpp>
19
20 #include <boost/geometry/algorithms/correct.hpp>
21 #include <boost/geometry/algorithms/detail/recalculate.hpp>
22 #include <boost/geometry/algorithms/length.hpp>
23 #include <boost/geometry/algorithms/num_points.hpp>
24 #include <boost/geometry/geometries/geometries.hpp>
25 #include <boost/geometry/geometries/point_xy.hpp>
26 #include <boost/geometry/strategies/strategies.hpp>
27 #include <boost/geometry/iterators/point_iterator.hpp>
28 #include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
29
30 #include <boost/geometry/io/wkt/wkt.hpp>
31
32
33
34 #include <geometry_test_common.hpp>
35
36
37 template
38 <
39 typename RescalePolicy,
40 typename Geometry1,
41 typename Geometry2
42 >
43 void test_one(std::string const& wkt1, std::string const& wkt2,
44 std::string const& expected_coordinates)
45 {
46 Geometry1 geometry1;
47 bg::read_wkt(wkt1, geometry1);
48
49 Geometry2 geometry2;
50 bg::read_wkt(wkt2, geometry2);
51
52 RescalePolicy rescale_policy
53 = bg::get_rescale_policy<RescalePolicy>(geometry1, geometry2);
54
55 typedef typename bg::point_type<Geometry1>::type point_type;
56 typedef typename bg::robust_point_type
57 <
58 point_type, RescalePolicy
59 >::type robust_point_type;
60
61 {
62 robust_point_type robust_point;
63 bg::recalculate(robust_point, *bg::points_begin(geometry1), rescale_policy);
64
65 std::ostringstream out;
66 out << bg::get<0>(robust_point) << " " << bg::get<1>(robust_point);
67 BOOST_CHECK_EQUAL(expected_coordinates, out.str());
68 }
69
70 {
71 // Assuming Geometry1 is a polygon:
72 typedef bg::model::polygon<robust_point_type> polygon_type;
73 polygon_type geometry_out;
74 bg::recalculate(geometry_out, geometry1, rescale_policy);
75 robust_point_type p = *bg::points_begin(geometry_out);
76
77 std::ostringstream out;
78 out << bg::get<0>(p) << " " << bg::get<1>(p);
79 BOOST_CHECK_EQUAL(expected_coordinates, out.str());
80 }
81 }
82
83
84
85 static std::string simplex_normal[2] =
86 {"POLYGON((0 1,2 5,5 3,0 1))",
87 "POLYGON((3 0,0 3,4 5,3 0))"};
88
89 static std::string simplex_large[2] =
90 {"POLYGON((0 1000,2000 5000,5000 3000,0 1000))",
91 "POLYGON((3000 0,0 3000,4000 5000,3000 0))"};
92
93
94 template <bool Rescale, typename P>
95 void test_rescale(std::string const& expected_normal, std::string const& expected_large)
96 {
97 typedef bg::model::polygon<P> polygon;
98
99 typedef typename boost::mpl::if_c
100 <
101 Rescale,
102 typename bg::rescale_policy_type<P>::type ,
103 bg::detail::no_rescale_policy
104 >::type rescale_policy_type;
105
106 test_one<rescale_policy_type, polygon, polygon>(
107 simplex_normal[0], simplex_normal[1],
108 expected_normal);
109 test_one<rescale_policy_type, polygon, polygon>(
110 simplex_large[0], simplex_large[1],
111 expected_large);
112 }
113
114 template <typename T>
115 void test_all(std::string const& expected_normal, std::string const& expected_large)
116 {
117 typedef bg::model::d2::point_xy<T> point_type;
118 test_rescale<true, point_type>(expected_normal, expected_large);
119 //test_rescale<false, point_type>();
120 }
121
122
123 int test_main(int, char* [])
124 {
125 test_all<double>("-5000000 -3000000", "-5000000 -3000000");
126 test_all<long double>("-5000000 -3000000", "-5000000 -3000000");
127 test_all<int>("0 1", "0 1000");
128 test_all<boost::long_long_type>("0 1", "0 1000");
129 // test_all<short int>(); // compiles but overflows
130
131 return 0;
132 }
133