1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
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)
13 #include <geometry_test_common.hpp>
16 #include <boost/foreach.hpp>
18 #include <boost/geometry/algorithms/intersection.hpp>
20 #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp>
21 #include <boost/geometry/algorithms/detail/overlay/get_relative_order.hpp>
23 #include <boost/geometry/geometries/point_xy.hpp>
25 #if defined(TEST_WITH_SVG)
26 # include <boost/geometry/io/svg/svg_mapper.hpp>
30 template <typename P, typename T>
31 void test_with_point(std::string const& caseid,
32 T pi_x, T pi_y, T pj_x, T pj_y,
33 T ri_x, T ri_y, T rj_x, T rj_y,
34 T si_x, T si_y, T sj_x, T sj_y,
37 P pi = bg::make<P>(pi_x, pi_y);
38 P pj = bg::make<P>(pj_x, pj_y);
39 P ri = bg::make<P>(ri_x, ri_y);
40 P rj = bg::make<P>(rj_x, rj_y);
41 P si = bg::make<P>(si_x, si_y);
42 P sj = bg::make<P>(sj_x, sj_y);
44 int order = bg::detail::overlay::get_relative_order<P>::apply(pi, pj, ri, rj, si, sj);
46 BOOST_CHECK_EQUAL(order, expected_order);
53 << (caseid.find("_") == std::string::npos ? " " : "")
62 /*#if defined(TEST_WITH_SVG)
64 std::ostringstream filename;
65 filename << "get_turn_info_" << caseid
66 << "_" << string_from_type<typename bg::coordinate_type<P>::type>::name()
69 std::ofstream svg(filename.str().c_str());
71 bg::svg_mapper<P> mapper(svg, 500, 500);
72 mapper.add(bg::make<P>(0, 0));
73 mapper.add(bg::make<P>(10, 10));
75 bg::model::linestring<P> p; p.push_back(pi); p.push_back(pj); p.push_back(pk);
76 bg::model::linestring<P> q; q.push_back(qi); q.push_back(qj); q.push_back(qk);
77 mapper.map(p, "opacity:0.8;stroke:rgb(0,192,0);stroke-width:3");
78 mapper.map(q, "opacity:0.8;stroke:rgb(0,0,255);stroke-width:3");
80 std::string style = ";font-family='Verdana';font-weight:bold";
81 std::string align = ";text-anchor:end;text-align:end";
84 mapper.text(pi, "pi", "fill:rgb(0,192,0)" + style, offset, offset);
85 mapper.text(pj, "pj", "fill:rgb(0,192,0)" + style, offset, offset);
86 mapper.text(pk, "pk", "fill:rgb(0,192,0)" + style, offset, offset);
88 mapper.text(qi, "qi", "fill:rgb(0,0,255)" + style + align, -offset, offset);
89 mapper.text(qj, "qj", "fill:rgb(0,0,255)" + style + align, -offset, offset);
90 mapper.text(qk, "qk", "fill:rgb(0,0,255)" + style + align, -offset, offset);
93 int factor = 1; // second info, if any, will go left by factor -1
95 for (typename tp_vector::const_iterator it = info.begin();
97 ++it, factor *= -1, ch++)
99 bool at_j = it->method == bg::detail::overlay::method_crosses;
101 op += operation_char(it->operations[0].operation);
102 align = ";text-anchor:middle;text-align:center";
103 mapper.text(at_j ? pj : pk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
106 op += operation_char(it->operations[1].operation);
107 mapper.text(at_j ? qj : qk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
109 // Map intersection point + method
110 mapper.map(it->point, "opacity:0.8;fill:rgb(255,0,0);stroke:rgb(0,0,100);stroke-width:1");
113 op += method_char(it->method);
114 if (info.size() != 1)
117 op += " p:"; op += operation_char(it->operations[0].operation);
118 op += " q:"; op += operation_char(it->operations[1].operation);
120 mapper.text(it->point, op, "fill:rgb(255,0,0)" + style, offset, -offset);
129 template <typename P>
132 test_with_point<P, double>("OLR1",
137 test_with_point<P, double>("OLR2",
142 test_with_point<P, double>("OLR3",
147 test_with_point<P, double>("OLR4",
152 test_with_point<P, double>("OLR5",
157 test_with_point<P, double>("OLR6",
162 test_with_point<P, double>("OLR7",
167 test_with_point<P, double>("OLR8",
174 test_with_point<P, double>("OD1",
180 test_with_point<P, double>("OD9",
185 test_with_point<P, double>("OD10",
190 test_with_point<P, double>("OD11",
195 test_with_point<P, double>("OD12",
203 int test_main(int, char* [])
205 test_all<bg::model::d2::point_xy<double> >();