1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <algorithm>
11 #include <iterator>
12 #include <sstream>
13 #include <string>
14
15 #include <geometry_test_common.hpp>
16
17 #include <boost/geometry/geometries/geometries.hpp>
18 #include <boost/geometry/geometries/point_xy.hpp>
19 #include <boost/geometry/views/segment_view.hpp>
20 #include <boost/geometry/io/wkt/read.hpp>
21
22
23
24 template <typename Segment>
test_geometry(std::string const & wkt,std::string const & expected)25 void test_geometry(std::string const& wkt, std::string const& expected)
26 {
27
28 Segment segment;
29 bg::read_wkt(wkt, segment);
30
31 typedef bg::segment_view<Segment> range_type;
32 range_type range(segment);
33
34 {
35 std::ostringstream out;
36 for (typename boost::range_iterator<range_type>::type it = boost::begin(range);
37 it != boost::end(range); ++it)
38 {
39 out << " " << bg::get<0>(*it) << bg::get<1>(*it);
40 }
41 BOOST_CHECK_EQUAL(out.str(), expected);
42 }
43
44 {
45 // Check forward/backward behaviour
46 std::ostringstream out;
47 typename boost::range_iterator<range_type>::type it = boost::begin(range);
48 it++;
49 it--;
50 out << " " << bg::get<0>(*it) << bg::get<1>(*it);
51 typename boost::range_iterator<range_type>::type it2 = boost::end(range);
52 it2--;
53 out << " " << bg::get<0>(*it2) << bg::get<1>(*it2);
54 BOOST_CHECK_EQUAL(out.str(), expected);
55 }
56
57 {
58 // Check random access behaviour
59 int const n = boost::size(range);
60 BOOST_CHECK_EQUAL(n, 2);
61 }
62
63 // Check Boost.Range concept
64 BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept<range_type>) );
65
66 }
67
68
69 template <typename P>
test_all()70 void test_all()
71 {
72 test_geometry<bg::model::segment<P> >("linestring(1 1,2 2)", " 11 22");
73 test_geometry<bg::model::segment<P> >("linestring(4 4,3 3)", " 44 33");
74 }
75
76
test_main(int,char * [])77 int test_main(int, char* [])
78 {
79 std::vector<int> a;
80 a.push_back(1);
81 boost::range_iterator<std::vector<int> const>::type it = a.end();
82 --it;
83 std::cout << *it << std::endl;
84 test_all<bg::model::d2::point_xy<double> >();
85 return 0;
86 }
87