]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/detail/as_range.cpp
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)
16 #include <geometry_test_common.hpp>
19 #include <boost/geometry/views/detail/range_type.hpp>
20 #include <boost/geometry/algorithms/detail/as_range.hpp>
22 #include <boost/geometry/core/cs.hpp>
23 #include <boost/geometry/geometries/geometries.hpp>
25 #include <boost/geometry/io/wkt/read.hpp>
27 template <int D
, typename Range
>
28 double sum(Range
const& range
)
31 for (typename
boost::range_const_iterator
<Range
>::type it
= boost::begin(range
);
32 it
!= boost::end(range
); ++it
)
40 void test_geometry(std::string
const& wkt
, double expected_x
, double expected_y
)
44 // Declare a range-type, compatible with boost::range,
45 // such that range_iterator etc could be called
46 typedef typename
bg::detail::range_type
<G
>::type range_type
;
48 bg::read_wkt(wkt
, geometry
);
50 double s
= sum
<0>(bg::detail::as_range
<range_type
>(geometry
));
51 BOOST_CHECK_CLOSE(s
, expected_x
, 0.001);
53 s
= sum
<1>(bg::detail::as_range
<range_type
>(geometry
));
54 BOOST_CHECK_CLOSE(s
, expected_y
, 0.001);
61 // As-range utility should consider a geometry as a range, so
62 // linestring stays linestring
63 test_geometry
<bg::model::linestring
<P
> >("LINESTRING(1 2,3 4)", 4, 6);
65 // polygon will only be outer-ring
66 test_geometry
<bg::model::polygon
<P
> >("POLYGON((1 2,3 4))", 4, 6);
67 test_geometry
<bg::model::polygon
<P
> >("POLYGON((1 2,3 4),(5 6,7 8,9 10))", 4, 6);
69 // the utility is useful for:
70 // - convex hull (holes do not count)
74 int test_main(int, char* [])
76 test_all
<bg::model::point
<double, 2, bg::cs::cartesian
> >();