PageRenderTime 40ms CodeModel.GetById 8ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/geometry/test/views/reversible_closeable.cpp

http://hadesmem.googlecode.com/
C++ | 165 lines | 119 code | 37 blank | 9 comment | 2 complexity | 81618054a175df7fb1582e6bab7ab369 MD5 | raw file
  1// Boost.Geometry (aka GGL, Generic Geometry Library)
  2// Unit Test
  3
  4// Copyright (c) 2010 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
 11#include <algorithm>
 12#include <iterator>
 13#include <sstream>
 14#include <string>
 15
 16#include <geometry_test_common.hpp>
 17
 18#include <boost/geometry/views/closeable_view.hpp>
 19#include <boost/geometry/views/reversible_view.hpp>
 20
 21#include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
 22#include <boost/geometry/util/write_dsv.hpp>
 23#include <boost/geometry/geometries/geometries.hpp>
 24#include <boost/geometry/geometries/point_xy.hpp>
 25#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
 26
 27BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian);
 28
 29
 30template <typename View>
 31void test_option(View const& view, std::string const& expected)
 32{
 33
 34    bool first = true;
 35    std::ostringstream out;
 36
 37    typedef typename boost::range_iterator<View const>::type iterator;
 38
 39    iterator end = boost::end(view);
 40    for (iterator it = boost::begin(view); it != end; ++it, first = false)
 41    {
 42        out << (first ? "" : " ") << bg::dsv(*it);
 43    }
 44    BOOST_CHECK_EQUAL(out.str(), expected);
 45}
 46
 47template <bg::closure_selector Closure, bg::iterate_direction Direction, typename Range>
 48void test_close_reverse(Range const& range, std::string const& expected)
 49{
 50    typedef typename bg::reversible_view<Range const, Direction>::type rview;
 51    typedef typename bg::closeable_view<rview const, Closure>::type cview;
 52
 53    rview view1(range);
 54    cview view2(view1);
 55
 56    test_option(view2, expected);
 57}
 58
 59
 60template <bg::iterate_direction Direction, bg::closure_selector Closure, typename Range>
 61void test_reverse_close(Range const& range, std::string const& expected)
 62{
 63    typedef typename bg::closeable_view<Range const, Closure>::type cview;
 64    typedef typename bg::reversible_view<cview const, Direction>::type rview;
 65
 66    cview view1(range);
 67    rview view2(view1);
 68    test_option(view2, expected);
 69}
 70
 71
 72template
 73<
 74    bg::iterate_direction Direction1,
 75    bg::iterate_direction Direction2,
 76    typename Range
 77>
 78void test_reverse_reverse(Range const& range, std::string const& expected)
 79{
 80    typedef typename bg::reversible_view<Range const, Direction1>::type rview1;
 81    typedef typename bg::reversible_view<rview1 const, Direction2>::type rview2;
 82
 83    rview1 view1(range);
 84    rview2 view2(view1);
 85    test_option(view2, expected);
 86}
 87
 88template
 89<
 90    bg::closure_selector Closure1,
 91    bg::closure_selector Closure2,
 92    typename Range
 93>
 94void test_close_close(Range const& range, std::string const& expected)
 95{
 96    typedef typename bg::closeable_view<Range const, Closure1>::type cview1;
 97    typedef typename bg::closeable_view<cview1 const, Closure2>::type cview2;
 98
 99    cview1 view1(range);
100    cview2 view2(view1);
101    test_option(view2, expected);
102}
103
104
105template <typename Geometry>
106void test_geometry(std::string const& wkt,
107            std::string const& expected_n,
108            std::string const& expected_r,
109            std::string const& closing,
110            std::string const& rclosing
111            )
112{
113    std::string expected;
114    Geometry geo;
115    bg::read_wkt(wkt, geo);
116
117    test_close_reverse<bg::closed, bg::iterate_forward>(geo, expected_n);
118    test_close_reverse<bg::open, bg::iterate_forward>(geo, expected_n + closing);
119    test_close_reverse<bg::closed, bg::iterate_reverse>(geo, expected_r);
120
121    // 13-12-2010, this case was problematic in MSVC
122    // SOLVED: caused by IMPLICIT constructor! It is now explicit and should be kept like that.
123    test_close_reverse<bg::open, bg::iterate_reverse>(geo, expected_r + rclosing);
124
125    test_reverse_close<bg::iterate_forward, bg::closed>(geo, expected_n);
126    test_reverse_close<bg::iterate_forward, bg::open>(geo, expected_n + closing);
127    test_reverse_close<bg::iterate_reverse, bg::closed>(geo, expected_r);
128
129    // first closed, then reversed:
130    expected = boost::trim_copy(closing + " " + expected_r);
131    test_reverse_close<bg::iterate_reverse, bg::open>(geo, expected);
132
133    test_reverse_reverse<bg::iterate_forward, bg::iterate_forward>(geo, expected_n);
134    test_reverse_reverse<bg::iterate_reverse, bg::iterate_reverse>(geo, expected_n);
135    test_reverse_reverse<bg::iterate_forward, bg::iterate_reverse>(geo, expected_r);
136    test_reverse_reverse<bg::iterate_reverse, bg::iterate_forward>(geo, expected_r);
137
138    test_close_close<bg::closed, bg::closed>(geo, expected_n);
139    test_close_close<bg::open, bg::closed>(geo, expected_n + closing);
140    test_close_close<bg::closed, bg::open>(geo, expected_n + closing);
141    test_close_close<bg::open, bg::open>(geo, expected_n + closing + closing);
142}
143
144
145template <typename P>
146void test_all()
147{
148    test_geometry<bg::model::ring<P> >(
149            "POLYGON((1 1,1 4,4 4,4 1))",
150            "(1, 1) (1, 4) (4, 4) (4, 1)",
151            "(4, 1) (4, 4) (1, 4) (1, 1)",
152            " (1, 1)", // closing
153            " (4, 1)" // rclosing
154            );
155}
156
157
158int test_main(int, char* [])
159{
160    test_all<bg::model::d2::point_xy<double> >();
161    test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
162    test_all<boost::tuple<double, double> >();
163
164    return 0;
165}