PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/geometry/test/views/segment_view.cpp

https://github.com/delalond/boost_1_54_0-bgq
C++ | 86 lines | 58 code | 19 blank | 9 comment | 2 complexity | 957fcba32700bfaab98f53e038d4ade9 MD5 | raw file
 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
24template <typename Segment>
25void 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
69template <typename P>
70void 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
77int 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}