File: polygon_set_data_test.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (114 lines) | stat: -rw-r--r-- 3,442 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Boost.Polygon library polygon_set_data_test.cpp file

//          Copyright Andrii Sydorchuk 2015.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org for updates, documentation, and revision history.

#include <boost/core/lightweight_test.hpp>
#include <boost/polygon/polygon.hpp>
#include <vector>

using namespace boost::polygon;
using namespace boost::polygon::operators;

void polygon_set_data_test1()
{
    typedef point_data<int> point_type;
    typedef polygon_with_holes_data<int> polygon_with_holes_type;
    typedef polygon_set_data<int> polygon_set_type;

    polygon_set_type pset;
    std::vector<point_type> outbox;
    outbox.push_back(point_type(0, 0));
    outbox.push_back(point_type(100, 0));
    outbox.push_back(point_type(100, 100));
    outbox.push_back(point_type(0, 100));
    pset.insert_vertex_sequence(outbox.begin(), outbox.end(), COUNTERCLOCKWISE, false);
    std::vector<point_type> inbox;
    inbox.push_back(point_type(20, 20));
    inbox.push_back(point_type(80, 20));
    inbox.push_back(point_type(80, 80));
    inbox.push_back(point_type(20, 80));
    pset.insert_vertex_sequence(inbox.begin(), inbox.end(), COUNTERCLOCKWISE, true);

    BOOST_TEST(!pset.empty());
    BOOST_TEST(!pset.sorted());
    BOOST_TEST(pset.dirty());
    BOOST_TEST_EQ(8, pset.size());

    std::vector<polygon_with_holes_type> vpoly;
    pset.get(vpoly);
    BOOST_TEST_EQ(1, vpoly.size());

    polygon_with_holes_type poly = vpoly[0];
    BOOST_TEST_EQ(5, poly.size());
    BOOST_TEST_EQ(1, poly.size_holes());
}

void polygon_set_data_test2()
{
    typedef point_data<int> point_type;
    typedef polygon_data<int> polygon_type;
    typedef polygon_set_data<int> polygon_set_type;

    std::vector<point_type> data;
    data.push_back(point_type(2,0));
    data.push_back(point_type(4,0));
    data.push_back(point_type(4,3));
    data.push_back(point_type(0,3));
    data.push_back(point_type(0,0));
    data.push_back(point_type(2,0));
    data.push_back(point_type(2,1));
    data.push_back(point_type(1,1));
    data.push_back(point_type(1,2));
    data.push_back(point_type(3,2));
    data.push_back(point_type(3,1));
    data.push_back(point_type(2,1));
    data.push_back(point_type(2,0));

    polygon_type polygon;
    set_points(polygon, data.begin(), data.end());

    polygon_set_type pset;
    pset.insert(polygon);

    std::vector<polygon_type> traps;
    get_trapezoids(traps, pset, HORIZONTAL);

    BOOST_TEST_EQ(4, traps.size());
}

void polygon_set_data_test3()
{
    typedef point_data<int> point_type;
    typedef polygon_data<int> polygon_type;
    typedef polygon_set_data<int> polygon_set_type;

    std::vector<point_type> data;
    data.push_back(point_type(0,0));
    data.push_back(point_type(6,0));
    data.push_back(point_type(6,4));
    data.push_back(point_type(4,6));
    data.push_back(point_type(0,6));
    data.push_back(point_type(0,0));
    data.push_back(point_type(4,4));
    data.push_back(point_type(5,4));

    polygon_type polygon(data.begin(), data.end());
    polygon_set_type pset;
    pset += polygon;

    BOOST_TEST_EQ(32.0, area(polygon));
    BOOST_TEST_EQ(32.0, area(polygon));
}

int main()
{
    polygon_set_data_test1();
    polygon_set_data_test2();
    polygon_set_data_test3();
    return boost::report_errors();
}