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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
18 #include <boost/foreach.hpp>
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>
30 #include <boost/geometry/io/wkt/wkt.hpp>
34 #include <geometry_test_common.hpp>
39 typename RescalePolicy
,
43 void test_one(std::string
const& wkt1
, std::string
const& wkt2
,
44 std::string
const& expected_coordinates
)
47 bg::read_wkt(wkt1
, geometry1
);
50 bg::read_wkt(wkt2
, geometry2
);
52 RescalePolicy rescale_policy
53 = bg::get_rescale_policy
<RescalePolicy
>(geometry1
, geometry2
);
55 typedef typename
bg::point_type
<Geometry1
>::type point_type
;
56 typedef typename
bg::robust_point_type
58 point_type
, RescalePolicy
59 >::type robust_point_type
;
62 robust_point_type robust_point
;
63 bg::recalculate(robust_point
, *bg::points_begin(geometry1
), rescale_policy
);
65 std::ostringstream out
;
66 out
<< bg::get
<0>(robust_point
) << " " << bg::get
<1>(robust_point
);
67 BOOST_CHECK_EQUAL(expected_coordinates
, out
.str());
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
);
77 std::ostringstream out
;
78 out
<< bg::get
<0>(p
) << " " << bg::get
<1>(p
);
79 BOOST_CHECK_EQUAL(expected_coordinates
, out
.str());
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))"};
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))"};
94 template <bool Rescale
, typename P
>
95 void test_rescale(std::string
const& expected_normal
, std::string
const& expected_large
)
97 typedef bg::model::polygon
<P
> polygon
;
99 typedef typename
boost::mpl::if_c
102 typename
bg::rescale_policy_type
<P
>::type
,
103 bg::detail::no_rescale_policy
104 >::type rescale_policy_type
;
106 test_one
<rescale_policy_type
, polygon
, polygon
>(
107 simplex_normal
[0], simplex_normal
[1],
109 test_one
<rescale_policy_type
, polygon
, polygon
>(
110 simplex_large
[0], simplex_large
[1],
114 template <typename T
>
115 void test_all(std::string
const& expected_normal
, std::string
const& expected_large
)
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>();
123 int test_main(int, char* [])
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