Ticket #11984: union_bug.cxx

File union_bug.cxx, 2.6 KB (added by max@…, 7 years ago)

Demo source for the union_ bug

Line 
1#include <boost/geometry/geometry.hpp>
2#include <boost/geometry/geometries/point_xy.hpp>
3#include <boost/geometry/geometries/polygon.hpp>
4#include <boost/geometry/multi/geometries/multi_polygon.hpp>
5#include <boost/geometry/algorithms/union.hpp>
6#include <boost/geometry/algorithms/intersection.hpp>
7
8#include <stdio.h>
9
10typedef boost::geometry::model::d2::point_xy<double> Point;
11typedef boost::geometry::model::ring<Point, false, false> Ring;
12typedef boost::geometry::model::polygon<Point, false, false> Polygon;
13typedef boost::geometry::model::multi_polygon<Polygon> MultiPolygon;
14
15template<typename T>
16static void Check(const T &shape, const char *name)
17{
18 std::string msg;
19 if (boost::geometry::is_valid(shape, msg))
20 printf("%s is valid\n", name);
21 else
22 printf("%s is invalid: %s\n", name, msg.c_str());
23
24}
25
26int main(int argc, char **argv) {
27 MultiPolygon mp;
28 boost::geometry::read_wkt("MULTIPOLYGON(((-104.025 72.5541,-95 67,-94 64,-95 60,-81.5804 61.9881,-75 52,-73.1862 50.0729,-75 48,-69.2 42.6,-96 56,-102 51,-119 49,-128 41,-126 33,-99 29,-61.9276 35.8291,-46 21,-30 10,-45 8,-104 6,-119 -8,-89 -18,-29 -10,-20 -9,-16 -11,-15 -13,-27 -29,-9 -13,-7 -14,-13.4737 -33.4211,-21 -34,-25 -36,-30 -40,-40 -49,-35 -50,-30 -51,-27 -53,-21 -52,-20.037 -52.642,-31.5314 -70.8413,-37.9815 -75.2274,-52.1689 -78.5148,-55 -78,-55 -79,-55 -79.1707,-112.692 -92.5385,-120 -94,-90.9143 -94.9695,-91 -95,-90 -99.5,-90 -103,-95 -114,-93 -116,-92 -117,-90 -119,-87.28 -119.68,-87 -120,-86.4444 -119.889,-82 -121,-80.821 -119.728,-77.6667 -119,-73 -119,-55 -114,-54 -114,-47 -114,-40 -121,-39.9327 -120.951,-39.3478 -121.609,-39 -123,-35.2182 -118.927,-24.536 -110.248,-22.875 -109.292,-22 -109,-22 -109,-16 -107,-9 -105,-7.83333 -104.833,-1.33333 -104.333,0.962934 -105.481,11.9682 -122.413,13 -129,20.1579 -120.053,22 -119,29.5 -115.25,30.2903 -114.968,39 -114,48 -112,47.156 -108.962,61 -117,54.9172 -103.176,65 -107,51.482 -95.3683,50.2426 -92.5515,53 -92,51.806 -91.0448,52 -91,49.1363 -88.9091,25.1429 -69.7143,22.733 -56.1314,24.9744 -49.3053,26.9174 -45.1157,27 -45,27.1481 -44.6543,33.4226 -34.0476,35.5919 -31.272,39 -29,39.4424 -26.3458,44.296 -20.136,46 -19,53 -14,53.3759 -13.4361,58.9297 -10.7874,115 13,110.286 13,114 14,112.414 14.7207,247.196 184.001,250 189,239.971 201.765,239 216,237.627 218.027,237.317 223.454,243 229)))", mp);
29 Check(mp, "input multipolygon");
30
31 Ring r;
32 boost::geometry::read_wkt("POLYGON((-31 6,-51 220,-84 241,-120 249,-146 224,-67 56,-74 52,-95 60,-38 10,-38 9))", r);
33 Check(r, "input ring");
34
35 MultiPolygon result;
36 boost::geometry::union_(mp, r, result);
37 Check(result, "result multipolygon");
38}