| 1 | #include <iostream>
|
|---|
| 2 | #include <vector>
|
|---|
| 3 |
|
|---|
| 4 | #include <boost/multiprecision/gmp.hpp>
|
|---|
| 5 |
|
|---|
| 6 | //#include <boost/multiprecision/cpp_int.hpp>
|
|---|
| 7 | //#include <boost/multiprecision/number.hpp>
|
|---|
| 8 | #include <boost/numeric/conversion/converter.hpp>
|
|---|
| 9 |
|
|---|
| 10 | typedef boost::multiprecision::mpq_rational GeometryCoord;
|
|---|
| 11 | typedef boost::numeric::conversion_traits<double , GeometryCoord> MyFloat_to_double_Traits;
|
|---|
| 12 |
|
|---|
| 13 | namespace boost {
|
|---|
| 14 | namespace numeric {
|
|---|
| 15 | template<>
|
|---|
| 16 | struct raw_converter<MyFloat_to_double_Traits>
|
|---|
| 17 | {
|
|---|
| 18 | static double low_level_convert ( GeometryCoord const& s ) { return( 0.0 ); } // Must be real conversion
|
|---|
| 19 | };
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | #include <boost/geometry.hpp>
|
|---|
| 24 | #include <boost/geometry/geometries/point_xy.hpp>
|
|---|
| 25 | #include <boost/geometry/geometries/polygon.hpp>
|
|---|
| 26 | #include <boost/geometry/io/wkt/wkt.hpp>
|
|---|
| 27 |
|
|---|
| 28 | #include <boost/foreach.hpp>
|
|---|
| 29 |
|
|---|
| 30 | //typedef boost::multiprecision::number<boost::multiprecision::gmp_rational, boost::multiprecision::et_off> GeometryCoord;
|
|---|
| 31 | //typedef boost::multiprecision::number<boost::multiprecision::gmp_rational> GeometryCoord;
|
|---|
| 32 | //typedef boost::multiprecision::mpq_rational GeometryCoord;
|
|---|
| 33 | //typedef boost::multiprecision::number<boost::multiprecision::cpp_rational, boost::multiprecision::et_off> GeometryCoord;
|
|---|
| 34 | typedef boost::geometry::model::d2::point_xy<GeometryCoord> GeometryPoint;
|
|---|
| 35 | typedef boost::geometry::model::segment<GeometryPoint> GeometrySegment;
|
|---|
| 36 | typedef boost::geometry::model::polygon<GeometryPoint> GeometryPolygon;
|
|---|
| 37 |
|
|---|
| 38 | int main()
|
|---|
| 39 | {
|
|---|
| 40 | /*std::vector<GeometryPoint> points;
|
|---|
| 41 |
|
|---|
| 42 | GeometrySegment Segment1(GeometryPoint(0, 3), GeometryPoint(3, 2));
|
|---|
| 43 | GeometrySegment Segment2(GeometryPoint(2, 0), GeometryPoint(0, 5));
|
|---|
| 44 |
|
|---|
| 45 | boost::geometry::intersection(Segment1, Segment2, points);*/
|
|---|
| 46 | /*
|
|---|
| 47 | for (std::vector<point>::const_iterator i = points.begin(); i != points.end(); ++i) {
|
|---|
| 48 | point p = *i;
|
|---|
| 49 |
|
|---|
| 50 | std::cout << "x = " << p.x() << " y = " << p.y() << std::endl;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | std::cout << std::endl;*/
|
|---|
| 54 |
|
|---|
| 55 | GeometryCoord c(3, 4);
|
|---|
| 56 |
|
|---|
| 57 | std::cout << " c = " << c << std::endl;
|
|---|
| 58 |
|
|---|
| 59 | GeometryPolygon green, blue;
|
|---|
| 60 |
|
|---|
| 61 | /*boost::geometry::read_wkt(
|
|---|
| 62 | "POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", green);
|
|---|
| 63 |
|
|---|
| 64 | boost::geometry::read_wkt(
|
|---|
| 65 | "POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))", blue);*/
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | /*boost::geometry::read_wkt(
|
|---|
| 71 | "POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", green);
|
|---|
| 72 |
|
|---|
| 73 | boost::geometry::read_wkt(
|
|---|
| 74 | "POLYGON((0 0, 0 20, 20 20, 20 0, 0 0))", blue);*/
|
|---|
| 75 |
|
|---|
| 76 | /*boost::geometry::read_wkt(
|
|---|
| 77 | "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", green);
|
|---|
| 78 |
|
|---|
| 79 | boost::geometry::read_wkt(
|
|---|
| 80 | "POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))", blue);*/
|
|---|
| 81 |
|
|---|
| 82 | green.outer().push_back(GeometryPoint(GeometryCoord(0), GeometryCoord(0)));
|
|---|
| 83 | green.outer().push_back(GeometryPoint(GeometryCoord(0, 1), GeometryCoord(10, 1)));
|
|---|
| 84 | green.outer().push_back(GeometryPoint(GeometryCoord(101, 10), GeometryCoord(101, 10)));
|
|---|
| 85 | green.outer().push_back(GeometryPoint(GeometryCoord(10, 1), GeometryCoord(0, 1)));
|
|---|
| 86 | green.outer().push_back(GeometryPoint(GeometryCoord(0), GeometryCoord(0)));
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | blue.outer().push_back(GeometryPoint(GeometryCoord(10, 1), GeometryCoord(10, 1)));
|
|---|
| 90 | blue.outer().push_back(GeometryPoint(GeometryCoord(10, 1), GeometryCoord(20, 1)));
|
|---|
| 91 | blue.outer().push_back(GeometryPoint(GeometryCoord(20, 1), GeometryCoord(20, 1)));
|
|---|
| 92 | blue.outer().push_back(GeometryPoint(GeometryCoord(20, 1), GeometryCoord(10, 1)));
|
|---|
| 93 | blue.outer().push_back(GeometryPoint(GeometryCoord(10, 1), GeometryCoord(10, 1)));
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | std::vector<GeometryPolygon> output;
|
|---|
| 97 | //boost::geometry::union_(green, blue, output);
|
|---|
| 98 |
|
|---|
| 99 | boost::geometry::intersection(green, blue, output);
|
|---|
| 100 |
|
|---|
| 101 | //boost::geometry::correct(green);
|
|---|
| 102 |
|
|---|
| 103 | std::cout << "size = " << output.size() << std::endl;
|
|---|
| 104 |
|
|---|
| 105 | //std::cout << "Intersects = " << boost::geometry::intersects(green, blue) << std::endl;
|
|---|
| 106 |
|
|---|
| 107 | BOOST_FOREACH(GeometryPolygon const& p, output) {
|
|---|
| 108 | //std::cout << boost::geometry::wkt<polygon>(p) << std::endl;
|
|---|
| 109 |
|
|---|
| 110 | const boost::geometry::model::ring<GeometryPoint> &ring = p.outer();
|
|---|
| 111 |
|
|---|
| 112 | for(boost::geometry::model::ring<GeometryPoint>::const_iterator i = ring.begin(); i != ring.end(); ++i ) {
|
|---|
| 113 | GeometryPoint Point = *i;
|
|---|
| 114 |
|
|---|
| 115 | std::cout << "x = " << Point.x() << " y = " << Point.y() << std::endl;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | //std::cout << "Point inside: " << boost::geometry::within( point(0, 0), p ) << std::endl;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | return 0;
|
|---|
| 122 | }
|
|---|