PageRenderTime 48ms CodeModel.GetById 20ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/geometry/test/geometries/boost_range.cpp

http://hadesmem.googlecode.com/
C++ | 116 lines | 80 code | 27 blank | 9 comment | 2 complexity | dd1b0d92c6bd1b9426c6e0b22a0cd2e7 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 <geometry_test_common.hpp>
 12
 13
 14#include <boost/geometry/geometry.hpp>
 15#include <boost/geometry/geometries/geometries.hpp>
 16#include <boost/geometry/geometries/point_xy.hpp>
 17#include <boost/geometry/geometries/adapted/boost_range/adjacent_filtered.hpp>
 18#include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>
 19#include <boost/geometry/geometries/adapted/boost_range/reversed.hpp>
 20#include <boost/geometry/geometries/adapted/boost_range/strided.hpp>
 21#include <boost/geometry/geometries/adapted/boost_range/sliced.hpp>
 22#include <boost/geometry/geometries/adapted/boost_range/uniqued.hpp>
 23
 24#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
 25
 26#include <sstream>
 27
 28struct not_two
 29{
 30    template <typename P>
 31    bool operator()(P const& p) const
 32    {
 33        return boost::geometry::get<0>(p) != 2.0;
 34    }
 35};
 36
 37struct sum_not_five
 38{
 39    template <typename P>
 40    bool operator()(P const& p1, P const& p2) const
 41    {
 42        return boost::geometry::get<0>(p1) + boost::geometry::get<0>(p2) != 5.0;
 43    }
 44};
 45
 46
 47template <typename P>
 48void test_range_adaptor()
 49{
 50    bg::model::linestring<P> ls;
 51    bg::read_wkt("LINESTRING(1 1,2 2,3 3,4 4)", ls);
 52
 53    {
 54        std::ostringstream out;
 55        out << bg::wkt(ls);
 56        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
 57    }
 58
 59    {
 60        std::ostringstream out;
 61        out << bg::wkt(ls | boost::adaptors::reversed);
 62        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(4 4,3 3,2 2,1 1)");
 63    }
 64
 65    {
 66        std::ostringstream out;
 67        out << bg::wkt(ls | boost::adaptors::strided(2));
 68        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3)");
 69    }
 70
 71    {
 72        std::ostringstream out;
 73        out << bg::wkt(ls | boost::adaptors::sliced(1,3));
 74        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(2 2,3 3)");
 75    }
 76
 77    {
 78        std::ostringstream out;
 79        out << bg::wkt(ls | boost::adaptors::filtered(not_two()));
 80        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
 81    }
 82
 83    {
 84        std::ostringstream out;
 85        out << bg::wkt(ls | boost::adaptors::adjacent_filtered(sum_not_five()));
 86        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
 87    }
 88
 89    {
 90        bg::model::linestring<P> ls2;
 91        bg::read_wkt("LINESTRING(1 1,1 1,2 2,3 3,3 3,4 4)", ls2);
 92        std::ostringstream out;
 93
 94
 95        // uniqued needs == operator, equals
 96        //out << bg::wkt(ls | boost::adaptors::uniqued);
 97        //BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
 98    }
 99}
100
101template <typename P>
102void test_all()
103{
104    test_range_adaptor<P>();
105}
106
107
108
109int test_main(int, char* [])
110{
111    test_all<bg::model::d2::point_xy<double> >();
112    test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
113
114    return 0;
115 }
116