• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <deque>
16 #include <vector>
17 
18 #include <geometry_test_common.hpp>
19 
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>
25 
26 
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>
32 
33 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
34 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
35 
36 BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector)
37 BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque)
38 
39 //#define TEST_FAIL_CLEAR
40 //#define TEST_FAIL_APPEND
41 
42 
43 
44 // ----------------------------------------------------------------------------
45 // First custom linestring, requires ONLY one traits: to register itself as a linestring
46 template <typename P>
47 struct custom_linestring1 : std::vector<P> {};
48 
49 namespace boost { namespace geometry { namespace traits {
50     template <typename P>
51     struct tag< custom_linestring1<P> > { typedef linestring_tag type; };
52 }}} // namespace bg::traits
53 
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
58 template <typename P>
59 struct custom_linestring2 : std::deque<P> // std::pair<typename std::vector<P>::const_iterator, typename std::vector<P>::const_iterator>
60 {
61 };
62 
63 namespace boost { namespace geometry { namespace traits {
64     template <typename P>
65     struct tag< custom_linestring2<P> > { typedef linestring_tag type; };
66 
67 #if ! defined(TEST_FAIL_CLEAR)
68     template <typename P>
69     struct clear< custom_linestring2<P> >
70     {
71         // does not use std::vector<P>.clear() but something else.
applyboost::geometry::traits::clear72         static inline void apply(custom_linestring2<P>& ls) { ls.resize(0); }
73     };
74 #endif
75 
76 }}} // namespace bg::traits
77 
78 // ----------------------------------------------------------------------------
79 
80 template <typename G>
test_linestring()81 void test_linestring()
82 {
83     BOOST_CONCEPT_ASSERT( (bg::concepts::Linestring<G>) );
84     BOOST_CONCEPT_ASSERT( (bg::concepts::ConstLinestring<G>) );
85 
86     G geometry;
87     typedef typename bg::point_type<G>::type P;
88 
89     bg::clear(geometry);
90     BOOST_CHECK_EQUAL(boost::size(geometry), 0u);
91 
92     bg::append(geometry, bg::make_zero<P>());
93     BOOST_CHECK_EQUAL(boost::size(geometry), 1u);
94 
95     //std::cout << geometry << std::endl;
96 
97     bg::clear(geometry);
98     BOOST_CHECK_EQUAL(boost::size(geometry), 0u);
99 
100 
101     //P p = boost::range::front(geometry);
102 }
103 
104 template <typename P>
test_all()105 void test_all()
106 {
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> >();
110 
111     test_linestring<custom_linestring1<P> >();
112     test_linestring<custom_linestring2<P> >();
113 
114     test_linestring<std::vector<P> >();
115     test_linestring<std::deque<P> >();
116     //test_linestring<std::list<P> >();
117 }
118 
test_main(int,char * [])119 int test_main(int, char* [])
120 {
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> >();
126 
127     return 0;
128 }
129