PageRenderTime 67ms CodeModel.GetById 14ms app.highlight 49ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/algorithms/union.cpp

http://hadesmem.googlecode.com/
C++ | 327 lines | 205 code | 76 blank | 46 comment | 2 complexity | 3e8516cee1cab8c4f05e73a9926f1da2 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// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  6// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  7
  8// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
 10
 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)
 14
 15#include <iostream>
 16#include <string>
 17
 18//#define BOOST_GEOMETRY_DEBUG_ASSEMBLE
 19//#define BOOST_GEOMETRY_DEBUG_IDENTIFIER
 20
 21
 22#include <algorithms/test_union.hpp>
 23#include <algorithms/test_overlay.hpp>
 24
 25#include <algorithms/overlay/overlay_cases.hpp>
 26#include <boost/geometry/geometries/point_xy.hpp>
 27
 28static std::string javier4[2] =
 29    {
 30    "POLYGON((-2 2, 1842 2, 1842 -2362, -2 -2362, -2 2), (0 0, 0 -2360, 1840 -2360, 1840 0, 0 0))",
 31    // "POLYGON((-0.01 -1960, 0 -1960, 0 -1880, 0.01 -1960, -0.01 -1960))"
 32    "POLYGON ((-0.01 -1960, 80.01 -1960, 0 -1880, -0.01 -1960))"
 33    };
 34
 35
 36
 37
 38
 39
 40
 41
 42template <typename Ring, typename Polygon>
 43void test_areal()
 44{
 45    test_one<Polygon, Polygon, Polygon>("javier4",
 46        javier4[0], javier4[1],
 47        1, 1, 13, 20016.4);
 48
 49    test_one<Polygon, Polygon, Polygon>("simplex_normal",
 50        simplex_normal[0], simplex_normal[1],
 51        1, 0, 13, 11.526367);
 52
 53    test_one<Polygon, Polygon, Polygon>("simplex_with_empty_1",
 54        simplex_normal[0], polygon_empty,
 55        1, 0, 4, 8.0);
 56    test_one<Polygon, Polygon, Polygon>("simplex_with_empty_2",
 57        polygon_empty, simplex_normal[0],
 58        1, 0, 4, 8.0);
 59
 60    test_one<Polygon, Polygon, Polygon>("star_ring", example_star, example_ring,
 61        1, 0, 23, 5.67017141);
 62
 63    // This sample was selected because of the border case, and ttmath generates one point more.
 64    test_one<Polygon, Polygon, Polygon>("star_poly", example_star, example_polygon,
 65        1, 1,
 66#if defined(HAVE_TTMATH)
 67        boost::is_same<typename bg::coordinate_type<Ring>::type, ttmath_big>::value ? 28 : 27,
 68#else
 69        27,
 70#endif
 71            5.647949);
 72
 73    // Pseudo-box as Polygon
 74    // (note, internally, the intersection points is different, so yes,
 75    // it has to be tested)
 76    test_one<Polygon, Polygon, Polygon>("box_poly3", "POLYGON((1.5 1.5 , 1.5 2.5 , 4.5 2.5 , 4.5 1.5 , 1.5 1.5))",
 77            "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,5.3 2.5,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3))",
 78                1, 1, 15, 5.93625);
 79
 80    test_one<Polygon, Polygon, Polygon>("first_within_second",
 81        first_within_second[0], first_within_second[1],
 82        1, 0, 5, 25.0);
 83
 84    test_one<Polygon, Polygon, Polygon>("second_within_first",
 85        first_within_second[1], first_within_second[0],
 86        1, 0, 5, 25.0);
 87
 88    test_one<Polygon, Polygon, Polygon>("first_within_hole_of_second",
 89        first_within_hole_of_second[0], first_within_hole_of_second[1],
 90        2, 1, 15, 17.0);
 91
 92    test_one<Polygon, Polygon, Polygon>("new_hole",
 93        new_hole[0], new_hole[1],
 94        1, 1, 14, 23.0);
 95
 96    test_one<Polygon, Polygon, Polygon>("side_side",
 97        side_side[0], side_side[1], 1, 0, 7, 2.0);
 98
 99    test_one<Polygon, Polygon, Polygon>("identical",
100        identical[0], identical[1], 1, 0, 5, 1.0);
101
102    test_one<Polygon, Polygon, Polygon>("disjoint",
103        disjoint[0], disjoint[1], 2, 0, 10, 2.0);
104
105    test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect",
106        intersect_holes_intersect[0], intersect_holes_intersect[1],
107        1, 1, 14, 39.75);
108
109    test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect_and_disjoint",
110        intersect_holes_intersect_and_disjoint[0], intersect_holes_intersect_and_disjoint[1],
111        1, 1, 14, 39.75);
112
113    test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect_and_touch",
114        intersect_holes_intersect_and_touch[0], intersect_holes_intersect_and_touch[1],
115        1, 1, 14, 39.75);
116
117    test_one<Polygon, Polygon, Polygon>("intersect_holes_new_ring",
118        intersect_holes_new_ring[0], intersect_holes_new_ring[1],
119        1, 2, 15, 253.8961);
120
121    test_one<Polygon, Polygon, Polygon>("intersect_holes_disjoint",
122        intersect_holes_disjoint[0],
123        intersect_holes_disjoint[1],
124        1, 0, 9, 40.0);
125
126    test_one<Polygon, Polygon, Polygon>("within_holes_disjoint",
127        within_holes_disjoint[0], within_holes_disjoint[1],
128        1, 0, 5, 49.0);
129
130    test_one<Polygon, Polygon, Polygon>("winded",
131        winded[0], winded[1],
132        1, 5, 30, 114.0);
133
134    test_one<Polygon, Polygon, Polygon>("two_bends",
135        two_bends[0], two_bends[1],
136        1, 0, 7, 40.0);
137
138    test_one<Polygon, Polygon, Polygon>("star_comb_15",
139        star_comb_15[0], star_comb_15[1],
140        1, 27, 204, 898.09693338);
141
142    test_one<Polygon, Polygon, Polygon>("equal_holes_disjoint",
143        equal_holes_disjoint[0], equal_holes_disjoint[1],
144        1, 1, 10, 81 - 3 * 7);
145
146    test_one<Polygon, Polygon, Polygon>("only_hole_intersections1",
147        only_hole_intersections[0], only_hole_intersections[1],
148        1, 2, 13, 190.9090909);
149    test_one<Polygon, Polygon, Polygon>("only_hole_intersections2",
150        only_hole_intersections[0], only_hole_intersections[2],
151        1, 2, 13, 190.9090909);
152
153    test_one<Polygon, Polygon, Polygon>("intersect_exterior_and_interiors_winded",
154        intersect_exterior_and_interiors_winded[0], intersect_exterior_and_interiors_winded[1],
155        1, 1, 26, 66.5333333);
156
157    test_one<Polygon, Polygon, Polygon>("crossed",
158        crossed[0], crossed[1],
159        1, 3, 17, 23.5); // Area from SQL Server - was somehow wrong before
160
161    test_one<Polygon, Polygon, Polygon>("fitting",
162        fitting[0], fitting[1],
163        1, 0, 5, 25);
164
165    test_one<Polygon, Polygon, Polygon>("distance_zero",
166        distance_zero[0], distance_zero[1],
167        1, 0, 11, 9.0098387);
168
169    test_one<Polygon, Polygon, Polygon>("wrapped_a",
170        wrapped[0], wrapped[1],
171        1, 1, 16, 16);
172    test_one<Polygon, Polygon, Polygon>("wrapped_b",
173        wrapped[0], wrapped[2],
174        1, 1, 16, 16);
175
176    test_one<Polygon, Polygon, Polygon>("9",
177                case_9[0], case_9[1], 2, 0, 8, 11);
178    test_one<Polygon, Polygon, Polygon>("22",
179                case_22[0], case_22[1], 2, 0, 8, 9.5);
180    test_one<Polygon, Polygon, Polygon>("25",
181                case_25[0], case_25[1], 2, 0, 8, 7);
182    test_one<Polygon, Polygon, Polygon>("26",
183                case_26[0], case_26[1], 2, 0, 9, 7.5);
184    test_one<Polygon, Polygon, Polygon>("31",
185                case_31[0], case_31[1], 2, 0, 8, 4.5);
186    test_one<Polygon, Polygon, Polygon>("32",
187                case_32[0], case_32[1], 2, 0, 8, 4.5);
188    test_one<Polygon, Polygon, Polygon>("33",
189                case_33[0], case_33[1], 2, 0, 8, 4.5);
190    test_one<Polygon, Polygon, Polygon>("36",
191                case_36[0], case_36[1], 1, 0, 10, 14.375);
192    test_one<Polygon, Polygon, Polygon>("40",
193                case_40[0], case_40[1], 2, 0, 18, 11);
194
195    // Test rings which should be generated by assemble
196    test_one<Polygon, Polygon, Polygon>("53_iet",
197                case_53[0], case_53[2], 1, 1, 16, 16);
198    test_one<Polygon, Polygon, Polygon>("58_iet",
199                case_58[0], case_58[2], 1, 3, 20, 12.16666);
200    test_one<Polygon, Polygon, Polygon>("59_iet",
201                case_59[0], case_59[2], 1, 1, 14, 17.20833);
202
203
204    /*
205    test_one<Polygon, Polygon, Polygon>(102,
206        simplex_normal[0], simplex_reversed[1],
207        1, 0, 7, X);
208
209    test_one<Polygon, Polygon, Polygon>(103,
210        simplex_reversed[0], simplex_normal[1],
211        1, 0, 7, 24.0);
212
213    test_one<Polygon, Polygon, Polygon>(104,
214        simplex_reversed[0], simplex_reversed[1],
215        1, 0, 7, 24.0);
216
217    test_one<Polygon, Polygon, Polygon>(100,
218        star_15, comb_15,
219        1, 10, 7, 24.0);
220    */
221
222    // test some other input/output types
223
224    // 1 input Ring
225    test_one<Polygon, Polygon, Ring>("identical_pr", identical[0], identical[1], 1, 0, 5, 1.0);
226    test_one<Polygon, Ring, Polygon>("identical_rp", identical[0], identical[1], 1, 0, 5, 1.0);
227
228    // 2 input rings
229    test_one<Polygon, Ring, Ring>("identical_rr", identical[0], identical[1], 1, 0, 5, 1.0);
230
231    // output is also Ring
232    test_one<Ring, Ring, Ring>("identical_rrr", identical[0], identical[1], 1, 0, 5, 1.0);
233
234    // "new hole", tested with Ring -> the newly formed hole will be omitted
235    test_one<Ring, Ring, Ring>("new_hole_discarded", new_hole[0], new_hole[1], 1, 0, 9, 24.0);
236
237    test_one<Polygon, Polygon, Polygon>("ggl_list_20110306_javier",
238        ggl_list_20110306_javier[0], ggl_list_20110306_javier[1],
239        1, 1, 16, 80456.4904910401);
240
241#ifdef _MSC_VER
242    {
243        // Isovist (submitted by Brandon during Formal Review)
244        std::string tn = string_from_type<typename bg::coordinate_type<Polygon>::type>::name();
245        test_one<Polygon, Polygon, Polygon>("isovist",
246            isovist1[0], isovist1[1],
247            1,
248            0,
249            tn == std::string("f") ? 71
250                : tn == std::string("d") ? 72
251                : 73,
252            313.36036462);
253    }
254#endif
255}
256
257template <typename P>
258void test_all()
259{
260    typedef bg::model::polygon<P> polygon;
261    typedef bg::model::ring<P> ring;
262    typedef bg::model::box<P> box;
263
264    test_areal<ring, polygon>();
265
266    // Open
267    test_areal<bg::model::ring<P, true, false>, bg::model::polygon<P, true, false> >();
268
269    // Counter clockwise
270    test_areal<bg::model::ring<P, false>, bg::model::polygon<P, false> >();
271
272    // Counter clockwise and open
273    test_areal<bg::model::ring<P, false, false>, bg::model::polygon<P, false, false> >();
274
275    test_one<polygon, box, polygon>("box_ring", example_box, example_ring,
276        1, 1, 15, 6.38875);
277
278    test_one<polygon, box, polygon>("box_poly", example_box, example_polygon,
279        1, 3, 23, 6.30983);
280
281
282    test_one<polygon, box, polygon>("box_poly1", example_box,
283            "POLYGON((3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2))",
284                1, 1, 15, 6.38875);
285    test_one<polygon, box, polygon>("box_poly2", example_box,
286            "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,5.3 2.5,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3))",
287                1, 1, 15, 5.93625);
288
289    // 3: see areal
290
291    test_one<polygon, box, polygon>("box_poly4", example_box,
292            "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,4.5 2.5,4.5 1.2,4.9 0.8,2.9 0.7,2 1.3))",
293                1, 1, 15, 4.651245);
294
295    test_one<polygon, box, polygon>("box_poly5", example_box,
296            "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,4.5 2.5,4.5 2.3,5.0 2.3,5.0 2.1,4.5 2.1,4.5 1.9,4.0 1.9,4.5 1.2,4.9 0.8,2.9 0.7,2 1.3))",
297                1, 1, 21, 4.7191);
298
299    test_one<polygon, box, polygon>("box_poly6", example_box,
300            "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,4.5 1.2,2.9 0.7,2 1.3))",
301                1, 1, 15, 4.2174);
302
303    test_one<polygon, box, polygon>("box_poly7", example_box,
304            "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.0 3.0,5.0 2.0,2.9 0.7,2 1.3))",
305                1, 1, 17, 4.270554);
306
307    test_one<polygon, box, polygon>("box_poly8", "box(0 0, 3 3)",
308            "POLYGON((2 2, 1 4, 2 4, 3 3, 2 2))",
309                1, 0, 8, 10.25);
310}
311
312
313int test_main(int, char* [])
314{
315    test_all<bg::model::d2::point_xy<double> >();
316
317#if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
318    test_all<bg::model::d2::point_xy<float> >();
319    //test_all<bg::model::d2::point_xy<long double> >();
320
321#if defined(HAVE_TTMATH)
322    test_all<bg::model::d2::point_xy<ttmath_big> >();
323#endif
324#endif
325
326    return 0;
327}