PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://hadesmem.googlecode.com/
C++ | 207 lines | 100 code | 30 blank | 77 comment | 0 complexity | b52567eb946b899a886eff35fc359461 MD5 | raw file
  1// Boost.Geometry (aka GGL, Generic Geometry Library)
  2// Unit Test
  3
  4// Copyright (c) 2007-2011 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 <iostream>
 12
 13#include <geometry_test_common.hpp>
 14
 15
 16#include <boost/foreach.hpp>
 17
 18#include <boost/geometry/algorithms/intersection.hpp>
 19
 20#include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp>
 21#include <boost/geometry/algorithms/detail/overlay/get_relative_order.hpp>
 22
 23#include <boost/geometry/geometries/point_xy.hpp>
 24
 25#if defined(TEST_WITH_SVG)
 26#  include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
 27#endif
 28
 29
 30template <typename P, typename T>
 31void 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,
 35                int expected_order)
 36{
 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);
 43
 44    int order = bg::detail::overlay::get_relative_order<P>::apply(pi, pj, ri, rj, si, sj);
 45
 46    BOOST_CHECK_EQUAL(order, expected_order);
 47
 48
 49
 50
 51    /*
 52    std::cout << caseid
 53        << (caseid.find("_") == std::string::npos ? "  " : "")
 54        << " " << method
 55        << " " << detected
 56        << " " << order
 57        << std::endl;
 58    */
 59
 60
 61
 62/*#if defined(TEST_WITH_SVG)
 63    {
 64        std::ostringstream filename;
 65        filename << "get_turn_info_" << caseid
 66            << "_" << string_from_type<typename bg::coordinate_type<P>::type>::name()
 67            << ".svg";
 68
 69        std::ofstream svg(filename.str().c_str());
 70
 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));
 74
 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");
 79
 80        std::string style =  ";font-family='Verdana';font-weight:bold";
 81        std::string align = ";text-anchor:end;text-align:end";
 82        int offset = 8;
 83
 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);
 87
 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);
 91
 92
 93        int factor = 1; // second info, if any, will go left by factor -1
 94        int ch = '1';
 95        for (typename tp_vector::const_iterator it = info.begin();
 96            it != info.end();
 97            ++it, factor *= -1, ch++)
 98        {
 99            bool at_j = it->method == bg::detail::overlay::method_crosses;
100            std::string op;
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);
104
105            op.clear();
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);
108
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");
111
112            op.clear();
113            op += method_char(it->method);
114            if (info.size() != 1)
115            {
116                op += ch;
117                op += " p:"; op += operation_char(it->operations[0].operation);
118                op += " q:"; op += operation_char(it->operations[1].operation);
119            }
120            mapper.text(it->point, op, "fill:rgb(255,0,0)" + style, offset, -offset);
121        }
122    }
123#endif
124*/
125}
126
127
128
129template <typename P>
130void test_all()
131{
132    test_with_point<P, double>("OLR1",
133            5, 1,   5, 8, // p
134            3, 5,   7, 5, // r
135            3, 3,   7, 2, // s
136            1);
137    test_with_point<P, double>("OLR2",
138            5, 1,   5, 8, // p
139            3, 5,   7, 5, // r
140            3, 7,   7, 6, // s
141            -1);
142    test_with_point<P, double>("OLR3",
143            5, 1,   5, 8, // p
144            3, 5,   7, 5, // r
145            4, 2,   9, 6, // s
146            1);
147    test_with_point<P, double>("OLR4",
148            5, 1,   5, 8, // p
149            3, 5,   7, 5, // r
150            3, 8,   9, 4, // s
151            -1);
152    test_with_point<P, double>("OLR5",
153            5, 1,   5, 8, // p
154            3, 5,   7, 5, // r
155            4, 2,   8, 6, // s
156            1);
157    test_with_point<P, double>("OLR6",
158            5, 1,   5, 8, // p
159            3, 5,   7, 5, // r
160            3, 7,   9, 4, // s
161            -1);
162    test_with_point<P, double>("OLR7",
163            5, 1,   5, 8, // p
164            3, 5,   7, 5, // r
165            1, 4,   7, 7, // s
166            -1);
167    test_with_point<P, double>("OLR8",
168            5, 1,   5, 8, // p
169            3, 5,   7, 5, // r
170            1, 6,   7, 3, // s
171            1);
172
173
174    test_with_point<P, double>("OD1",
175            5, 1,   5, 8, // p
176            3, 5,   7, 5, // r
177            7, 2,   3, 3, // s
178            1);
179
180    test_with_point<P, double>("OD9",
181            5, 1,   5, 8, // p
182            3, 5,   7, 5, // r
183            7, 5,   3, 3, // s
184            1);
185    test_with_point<P, double>("OD10",
186            5, 1,   5, 8, // p
187            3, 5,   7, 5, // r
188            7, 5,   3, 7, // s
189            -1);
190    test_with_point<P, double>("OD11",
191            5, 1,   5, 8, // p
192            7, 5,   3, 5, // r
193            3, 5,   7, 7, // s
194            -1);
195    test_with_point<P, double>("OD12",
196            5, 1,   5, 8, // p
197            7, 5,   3, 5, // r
198            3, 5,   7, 3, // s
199            1);
200}
201
202
203int test_main(int, char* [])
204{
205    test_all<bg::model::d2::point_xy<double> >();
206    return 0;
207}