#### /libs/geometry/test/multi/algorithms/multi_union.cpp

https://github.com/delalond/boost_1_54_0-bgq
C++ | 149 lines | 116 code | 25 blank | 8 comment | 0 complexity | 3cb3db114f97914f75884e96b0aa7f85 MD5 | raw file
```  1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2010-2012 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
9
10#include <iostream>
11#include <string>
12
13
14#include <algorithms/test_union.hpp>
15#include <algorithms/test_overlay.hpp>
16#include <multi/algorithms/overlay/multi_overlay_cases.hpp>
17
18#include <boost/geometry/multi/algorithms/correct.hpp>
19#include <boost/geometry/multi/algorithms/intersection.hpp>
20#include <boost/geometry/multi/algorithms/within.hpp>
21
22#include <boost/geometry/geometries/point_xy.hpp>
23#include <boost/geometry/multi/geometries/multi_linestring.hpp>
24#include <boost/geometry/multi/geometries/multi_polygon.hpp>
25
27
28
29template <typename Ring, typename Polygon, typename MultiPolygon>
30void test_areal()
31{
32    test_one<Polygon, MultiPolygon, MultiPolygon>("simplex_multi",
33        case_multi_simplex[0], case_multi_simplex[1],
34        1, 0, 20, 14.58);
35
36    test_one<Polygon, Polygon, MultiPolygon>("simplex_multi_p_mp",
37        case_single_simplex, case_multi_simplex[0],
38        1, 0, 20, 14.58);
39    test_one<Polygon, MultiPolygon, Polygon>("simplex_multi_mp_p",
40        case_multi_simplex[0], case_single_simplex,
41        1, 0, 20, 14.58);
42
43    test_one<Polygon, Ring, MultiPolygon>("simplex_multi_r_mp",
44        case_single_simplex, case_multi_simplex[0],
45        1, 0, 20, 14.58);
46    test_one<Ring, MultiPolygon, Polygon>("simplex_multi_mp_r",
47        case_multi_simplex[0], case_single_simplex,
48        1, 0, 20, 14.58);
49
50
51    // Normal test cases
52    test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_no_ip",
53        case_multi_no_ip[0], case_multi_no_ip[1],
54        4, 0, 16, 66.5);
55    test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_2",
56        case_multi_2[0], case_multi_2[1],
57        3, 0, 16, 59.1);
58
59    // Constructed cases for multi/touch/equal/etc
60    test_one<Polygon, MultiPolygon, MultiPolygon>("case_61_multi",
61        case_61_multi[0], case_61_multi[1],
62        1, 0, 11, 4.0);
63    test_one<Polygon, MultiPolygon, MultiPolygon>("case_62_multi",
64        case_62_multi[0], case_62_multi[1],
65        2, 0, 10, 2.0);
66    test_one<Polygon, MultiPolygon, MultiPolygon>("case_63_multi",
67        case_63_multi[0], case_63_multi[1],
68        2, 0, 10, 2.0);
69    test_one<Polygon, MultiPolygon, MultiPolygon>("case_64_multi",
70        case_64_multi[0], case_64_multi[1],
71        1, 0, 9, 3.0);
72    test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi",
73        case_65_multi[0], case_65_multi[1],
74        3, 0, 15, 4.0);
75    test_one<Polygon, MultiPolygon, MultiPolygon>("case_66_multi",
76        case_66_multi[0], case_66_multi[1],
77        3, 0, 23, 7.0);
78    test_one<Polygon, MultiPolygon, MultiPolygon>("case_75_multi",
79        case_75_multi[0], case_75_multi[1],
80        5, 0, 25, 5.0);
81    test_one<Polygon, MultiPolygon, MultiPolygon>("case_76_multi",
82        case_76_multi[0], case_76_multi[1],
83        5, 0, 31, 8.0);
84    test_one<Polygon, MultiPolygon, MultiPolygon>("case_89_multi",
85        case_89_multi[0], case_89_multi[1],
86        1, 0, 13, 6);
87    test_one<Polygon, MultiPolygon, MultiPolygon>("case_101_multi",
88        case_101_multi[0], case_101_multi[1],
89        1, 0, 32, 22.25);
90    test_one<Polygon, MultiPolygon, MultiPolygon>("case_103_multi",
91        case_103_multi[0], case_103_multi[1],
92        1, 0, 7, 25);
93    test_one<Polygon, MultiPolygon, MultiPolygon>("case_104_multi",
94        case_104_multi[0], case_104_multi[1],
95        1, 0, 8, 25);
96    test_one<Polygon, MultiPolygon, MultiPolygon>("case_105_multi",
97        case_105_multi[0], case_105_multi[1],
98        1, 0, 5, 25);
99
100    test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_1",
101        case_recursive_boxes_1[0], case_recursive_boxes_1[1],
102        1, 1, 36, 97.0);
103    test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_2",
104        case_recursive_boxes_2[0], case_recursive_boxes_2[1],
105        1, 0, 14, 100.0); // Area from SQL Server
106    test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_3",
107        case_recursive_boxes_3[0], case_recursive_boxes_3[1],
108        17, 0, 159, 56.5); // Area from SQL Server
109
110     test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_a",
111         ggl_list_20120915_h2[0], ggl_list_20120915_h2[1],
112         1, 0, 12, 23.0); // Area from SQL Server
113     test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_b",
114         ggl_list_20120915_h2[0], ggl_list_20120915_h2[2],
115         1, 0, 12, 23.0); // Area from SQL Server
116}
117
118template <typename P>
119void test_all()
120{
121
122    {
123        typedef bg::model::ring<P> ring;
124        typedef bg::model::polygon<P> polygon;
125        typedef bg::model::multi_polygon<polygon> multi_polygon;
126        test_areal<ring, polygon, multi_polygon>();
127    }
128
129    {
130        typedef bg::model::ring<P, false> ring_ccw;
131        typedef bg::model::polygon<P, false> polygon_ccw;
132        typedef bg::model::multi_polygon<polygon_ccw> multi_polygon_ccw;
133        test_areal<ring_ccw, polygon_ccw, multi_polygon_ccw>();
134    }
135
136}
137
138
139int test_main(int, char* [])
140{
141    test_all<bg::model::d2::point_xy<double> >();
142
143#ifdef HAVE_TTMATH
144    std::cout << "Testing TTMATH" << std::endl;
145    test_all<bg::model::d2::point_xy<ttmath_big> >();
146#endif
147
148    return 0;
149}
```