1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
15 #error This unit test is not updated for several years
19 #include <geometry_test_common.hpp>
21 #include <boost/geometry/algorithms/intersection.hpp>
23 //#include <boost/geometry/algorithms/detail/overlay/get_intersection_points.hpp>
24 //#include <boost/geometry/algorithms/detail/overlay/merge_intersection_points.hpp>
25 #include <boost/geometry/algorithms/detail/overlay/enrich_intersection_points.hpp>
27 #include <boost/geometry/strategies/strategies.hpp>
29 #define GEOMETRY_TEST_OVERLAY_NOT_REVERSED
32 #include <boost/algorithm/string/replace.hpp>
35 #if defined(TEST_WITH_SVG)
36 # include <boost/geometry/io/svg/svg_mapper.hpp>
39 struct test_enrich_intersection_points
41 static inline std::string
dir(int d
)
43 return d
== 0 ? "-" : (d
== 1 ? "L" : "R");
46 template <typename G1
, typename G2
>
47 static void apply(std::string
const& id
,
48 boost::tuple
<int, std::string
> const& expected_count_and_center
,
49 G1
const& g1
, G2
const& g2
, double precision
)
51 //std::cout << "#" << id << std::endl;
53 typedef bg::detail::intersection::intersection_point
54 <typename
bg::point_type
<G2
>::type
> ip
;
55 typedef typename
boost::range_const_iterator
<std::vector
<ip
> >::type iterator
;
58 bg::get_intersection_points(g1
, g2
, ips
);
59 bg::merge_intersection_points(ips
);
60 bg::enrich_intersection_points(ips
, true);
62 std::ostringstream out
;
63 out
<< std::setprecision(2);
66 for (iterator it
= boost::begin(ips
); it
!= boost::end(ips
); ++it
, first
= false)
68 out
<< (first
? "" : ",");
69 for (unsigned int i
= 0; i
< it
->info
.size(); i
++)
71 out
<< dir(it
->info
[i
].direction
);
74 int n
= boost::size(ips
);
75 //std::cout << n << " " << out.str() << std::endl;
76 BOOST_CHECK_EQUAL(expected_count_and_center
.get
<0>(), n
);
77 BOOST_CHECK_EQUAL(expected_count_and_center
.get
<1>(), out
.str());
81 #if defined(TEST_WITH_SVG)
83 std::ostringstream filename
;
84 filename
<< "enrich_ip" << id
<< ".svg";
86 std::ofstream
svg(filename
.str().c_str());
88 bg::svg_mapper
<typename
bg::point_type
<G2
>::type
> mapper(svg
, 500, 500);
92 mapper
.map(g1
, "fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1");
93 mapper
.map(g2
, "opacity:0.8;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1");
95 for (iterator it
= boost::begin(ips
); it
!= boost::end(ips
); ++it
)
97 mapper
.map(it
->point
, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
105 int test_main(int, char* [])
107 std::vector
<boost::tuple
<int, std::string
> > expected
;
110 TODO Will be refactored
112 // NOTE: the order is sometimes not really important, in GCC it is sometimes
113 // different from here...
117 expected.push_back(boost::make_tuple(6, "RL,LR,LR,RL,RL,LR"));
118 expected.push_back(boost::make_tuple(8, "RL,LR,LR,RL,RL,LR,LR,RL"));
119 expected.push_back(boost::make_tuple(4, "RLRR,RRRL,RRRL,RRRL"));
120 expected.push_back(boost::make_tuple(12, "RL,LR,RL,LR,LR,RL,RL,LR,LR,RL,LR,RL"));
121 expected.push_back(boost::make_tuple(17, "LR,RL,LR,RRLR,RL,LR,RL,RL,LR,LR,RL,LR,RL,RL,LR,RL,LR"));
122 expected.push_back(boost::make_tuple(2, "--RR,LR"));
125 expected.push_back(boost::make_tuple(2, "LL,LL"));
126 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
127 expected.push_back(boost::make_tuple(1, "RLLL"));
128 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
129 expected.push_back(boost::make_tuple(1, "RRLR"));
130 expected.push_back(boost::make_tuple(8, "RL,LR,RL,LR,RL,LR,RL,LR"));
133 expected.push_back(boost::make_tuple(2, "LL--,LL--"));
134 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
135 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
136 expected.push_back(boost::make_tuple(2, "LL,--RL"));
137 expected.push_back(boost::make_tuple(2, "RR--,--LR"));
138 expected.push_back(boost::make_tuple(2, "RR--,--LR"));
141 expected.push_back(boost::make_tuple(2, "LL,LL"));
142 expected.push_back(boost::make_tuple(0, ""));
143 expected.push_back(boost::make_tuple(0, ""));
144 expected.push_back(boost::make_tuple(1, "RLLLRRLR"));
145 expected.push_back(boost::make_tuple(2, "RL,RLRRRRLR"));
146 expected.push_back(boost::make_tuple(1, "LRRRRRLR"));
149 expected.push_back(boost::make_tuple(1, "LRRRLLRL"));
150 expected.push_back(boost::make_tuple(1, "LRLLLLLR"));
151 expected.push_back(boost::make_tuple(2, "LR,LRRRRRRL"));
152 expected.push_back(boost::make_tuple(2, "LR,LRLLRRLR"));
153 expected.push_back(boost::make_tuple(2, "RL,LRRRLLLR"));
154 expected.push_back(boost::make_tuple(2, "LR,LRLLLLRL"));
157 expected.push_back(boost::make_tuple(1, "--LLLL--"));
158 expected.push_back(boost::make_tuple(1, "LR--LLRL"));
159 expected.push_back(boost::make_tuple(1, "LRLLLL--"));
160 expected.push_back(boost::make_tuple(2, "LR,LRLLRR--"));
161 expected.push_back(boost::make_tuple(1, "LRLLRRLR"));
162 expected.push_back(boost::make_tuple(3, "RL,LR,RLLLRRLR"));
165 expected.push_back(boost::make_tuple(3, "LRRRRRLR,RL,LR"));
166 expected.push_back(boost::make_tuple(3, "LR--RRRL,LR,RL"));
167 expected.push_back(boost::make_tuple(3, "RL,LR,LRRRRRRL"));
170 expected.push_back(boost::make_tuple(4, "LR,RL,RL,LR"));
173 expected.push_back(boost::make_tuple(16, "--RL,RRLR,RRLR,RL,LLRL,RLLLRRLR,RR--,--LR,RLRR,--LL,RL--,RL,RRRL,RL,LR,RRRLRRRL"));
176 expected.push_back(boost::make_tuple(3, "RL,LR,RL"));
179 expected.push_back(boost::make_tuple(6, "LR,RL,LR,RL,RL,LR"));
181 //test_all<bg::model::d2::point_xy<float>, test_enrich_intersection_points>(expected);
182 test_all<bg::model::d2::point_xy<double>, test_enrich_intersection_points>(expected);
183 //test_all<boost::tuple<double, double>, test_enrich_intersection_points>(expected);