PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/algorithms/overlay/select_rings.cpp

http://hadesmem.googlecode.com/
C++ | 130 lines | 89 code | 32 blank | 9 comment | 3 complexity | 61e7965d20a0441cadd1a5d222bbf40f MD5 | raw file
  1// Boost.Geometry (aka GGL, Generic Geometry Library)
  2//
  3// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  4// Use, modification and distribution is subject to the Boost Software License,
  5// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6// http://www.boost.org/LICENSE_1_0.txt)
  7
  8#include <geometry_test_common.hpp>
  9
 10#include <algorithms/test_overlay.hpp>
 11
 12#include <boost/range/algorithm/copy.hpp>
 13
 14#include <boost/geometry/geometry.hpp>
 15#include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
 16#include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
 17
 18#include <boost/geometry/geometries/point_xy.hpp>
 19#include <boost/geometry/geometries/polygon.hpp>
 20
 21#include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
 22
 23#include <boost/assign/list_of.hpp>
 24#include <boost/foreach.hpp>
 25#include <boost/tuple/tuple.hpp>
 26
 27
 28
 29template 
 30<
 31    typename Geometry1, 
 32    typename Geometry2, 
 33    bg::overlay_type OverlayType, 
 34    typename RingIdVector,
 35    typename WithinVector
 36>
 37void test_geometry(std::string const& wkt1, std::string const& wkt2, 
 38    RingIdVector const& expected_ids,
 39    WithinVector const& expected_withins)
 40{
 41    typedef bg::detail::overlay::ring_properties<typename bg::point_type<Geometry1>::type> properties;
 42
 43    Geometry1 geometry1;
 44    Geometry2 geometry2;
 45
 46    bg::read_wkt(wkt1, geometry1);
 47    bg::read_wkt(wkt2, geometry2);
 48
 49    typedef std::map<bg::ring_identifier, properties> map_type;
 50    map_type selected;
 51    std::map<bg::ring_identifier, int> empty;
 52
 53    bg::detail::overlay::select_rings<OverlayType>(geometry1, geometry2, empty, selected);
 54
 55    BOOST_CHECK_EQUAL(selected.size(), expected_ids.size());
 56    BOOST_CHECK_EQUAL(selected.size(), expected_withins.size());
 57
 58    if (selected.size() <= expected_ids.size())
 59    {
 60        BOOST_AUTO(eit, expected_ids.begin());
 61        BOOST_AUTO(wit, expected_withins.begin());
 62        for(typename map_type::const_iterator it = selected.begin(); it != selected.end(); ++it, ++eit, ++wit)
 63        {
 64            bg::ring_identifier const ring_id = it->first;
 65            BOOST_CHECK_EQUAL(ring_id.source_index, eit->source_index);
 66            BOOST_CHECK_EQUAL(ring_id.multi_index, eit->multi_index);
 67            BOOST_CHECK_EQUAL(ring_id.ring_index, eit->ring_index);
 68            BOOST_CHECK_EQUAL(it->second.within_code, *wit);
 69        }
 70    }
 71}
 72
 73
 74
 75
 76template <typename P>
 77void test_all()
 78{
 79    // Point in correct clockwise ring -> should return true
 80    typedef bg::ring_identifier rid;
 81
 82    test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_union>(
 83        winded[0], winded[1], 
 84        boost::assign::list_of
 85                (rid(0,-1,-1))
 86                (rid(0,-1, 0))
 87                (rid(0,-1, 1))
 88                (rid(0,-1, 3))
 89                (rid(1,-1, 1))
 90                (rid(1,-1, 2)),
 91
 92        boost::assign::list_of
 93                (-1)
 94                (-1)
 95                (-1)
 96                (-1)
 97                (-1)
 98                (-1)
 99            );
100            
101            //boost::assign::tuple_list_of(0,-1,-1,-1)(0,-1,0,-1)(0,-1,1,-1)(0,-1,3,-1)(1,-1,1,-1)(1,-1,2,-1));
102
103    test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_intersection>(
104            winded[0], winded[1],
105        boost::assign::list_of
106                (rid(0,-1, 2))
107                (rid(1,-1,-1))
108                (rid(1,-1, 0))
109                (rid(1,-1, 3)),
110
111        boost::assign::list_of
112                (1)
113                (1)
114                (1)
115                (1)
116            );
117
118
119            //boost::assign::tuple_list_of(0,-1,2,1)(1,-1,-1,1)(1,-1,0,1)(1,-1,3,1));
120}
121
122
123
124
125int test_main( int , char* [] )
126{
127    test_all<bg::model::d2::point_xy<double> >();
128
129    return 0;
130}