]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/geometries/custom_linestring.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)
18 #include <geometry_test_common.hpp>
20 #include <boost/geometry/algorithms/append.hpp>
21 #include <boost/geometry/algorithms/clear.hpp>
22 #include <boost/geometry/algorithms/make.hpp>
23 #include <boost/geometry/core/access.hpp>
24 #include <boost/geometry/geometries/concepts/linestring_concept.hpp>
27 #include <boost/geometry/geometries/geometries.hpp>
28 #include <boost/geometry/geometries/register/linestring.hpp>
29 #include <boost/geometry/geometries/adapted/c_array.hpp>
30 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
31 #include <test_common/test_point.hpp>
33 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian
)
34 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian
)
36 BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector
)
37 BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque
)
39 //#define TEST_FAIL_CLEAR
40 //#define TEST_FAIL_APPEND
44 // ----------------------------------------------------------------------------
45 // First custom linestring, requires ONLY one traits: to register itself as a linestring
47 struct custom_linestring1
: std::vector
<P
> {};
49 namespace boost
{ namespace geometry
{ namespace traits
{
51 struct tag
< custom_linestring1
<P
> > { typedef linestring_tag type
; };
52 }}} // namespace bg::traits
54 // ----------------------------------------------------------------------------
55 // Second custom linestring, decides to implement all edit operations itself
56 // by specializing the "use_std" traits to false.
57 // It should therefore implement the traits:: clear / append_point
59 struct custom_linestring2
: std::deque
<P
> // std::pair<typename std::vector<P>::const_iterator, typename std::vector<P>::const_iterator>
63 namespace boost
{ namespace geometry
{ namespace traits
{
65 struct tag
< custom_linestring2
<P
> > { typedef linestring_tag type
; };
67 #if ! defined(TEST_FAIL_CLEAR)
69 struct clear
< custom_linestring2
<P
> >
71 // does not use std::vector<P>.clear() but something else.
72 static inline void apply(custom_linestring2
<P
>& ls
) { ls
.resize(0); }
76 }}} // namespace bg::traits
78 // ----------------------------------------------------------------------------
81 void test_linestring()
83 BOOST_CONCEPT_ASSERT( (bg::concepts::Linestring
<G
>) );
84 BOOST_CONCEPT_ASSERT( (bg::concepts::ConstLinestring
<G
>) );
87 typedef typename
bg::point_type
<G
>::type P
;
90 BOOST_CHECK_EQUAL(boost::size(geometry
), 0u);
92 bg::append(geometry
, bg::make_zero
<P
>());
93 BOOST_CHECK_EQUAL(boost::size(geometry
), 1u);
95 //std::cout << geometry << std::endl;
98 BOOST_CHECK_EQUAL(boost::size(geometry
), 0u);
101 //P p = boost::range::front(geometry);
104 template <typename P
>
107 test_linestring
<bg::model::linestring
<P
> >();
108 test_linestring
<bg::model::linestring
<P
, std::vector
> >();
109 test_linestring
<bg::model::linestring
<P
, std::deque
> >();
111 test_linestring
<custom_linestring1
<P
> >();
112 test_linestring
<custom_linestring2
<P
> >();
114 test_linestring
<std::vector
<P
> >();
115 test_linestring
<std::deque
<P
> >();
116 //test_linestring<std::list<P> >();
119 int test_main(int, char* [])
121 test_all
<test::test_point
>();
122 test_all
<boost::tuple
<float, float> >();
123 test_all
<bg::model::point
<int, 2, bg::cs::cartesian
> >();
124 test_all
<bg::model::point
<float, 2, bg::cs::cartesian
> >();
125 test_all
<bg::model::point
<double, 2, bg::cs::cartesian
> >();