C++ 助推交叉口

C++ 助推交叉口,c++,boost,boost-geometry,C++,Boost,Boost Geometry,我对boost交叉算法有一个问题。我不确定我是否犯了错误或是一个bug #include <boost/geometry/algorithms/intersection.hpp> #include <boost/version.hpp> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry

我对boost交叉算法有一个问题。我不确定我是否犯了错误或是一个bug

#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/version.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
int main()
{
    typedef boost::geometry::model::d2::point_xy<double> BoostPointXY;
    typedef boost::geometry::model::polygon<BoostPointXY> BoostPolygon;

    BoostPolygon polyOne, polyTwo;
    boost::geometry::read_wkt(
            "POLYGON((45, 4), (45, 17), (44, 19), (44, 22), (50, 20), (51.5, 17), (58, 4), (60, 0), (53, 0), (45, 0), (45, 4))",
            polyOne);
    boost::geometry::read_wkt(
            "POLYGON((-10, -5), (0, 25), (43, 25), (45, 20), (50, 20), (60, 0), (5, 0), (5, -5), (-10, -5))", polyTwo);
    std::vector<BoostPolygon> multiPoly;
    boost::geometry::correct(polyOne);
    boost::geometry::correct(polyTwo);
    boost::geometry::intersection(polyOne,polyTwo,multiPoly);
    std::cout << "Size of Multi " << multiPoly.size() << std::endl;
    std::cout << "Using Boost "
              << BOOST_VERSION / 100000     << "."  // major version
              << BOOST_VERSION / 100 % 1000 << "."  // minior version
              << BOOST_VERSION % 100                // patch level
              << std::endl;
}
但是多边形的大小应该是1或?当它是一个bug时,有人能用当前的boost 1.57测试它吗?我现在无法更改我的boost版本


谢谢

您的WKT数据无效:

boost::geometry::read_wkt("POLYGON((45  4, 45  17, 44  19, 44  22, 50  20, 51.5  17, 58  4, 60  0, 53  0, 45  0, 45  4))", polyOne);
boost::geometry::read_wkt("POLYGON((-10  -5, 0  25, 43  25, 45  20, 50  20, 60  0, 5  0, 5  -5, -10  -5))", polyTwo);
您的样本使用了许多无效的(?)内环

现在您可以:

Size of Multi 1

#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/io/io.hpp>
#include <fstream>
#include <iostream>

int main() {
    typedef boost::geometry::model::d2::point_xy<double> BoostPointXY;
    typedef boost::geometry::model::polygon<BoostPointXY> BoostPolygon;

    BoostPolygon polyOne, polyTwo;
    boost::geometry::read_wkt("POLYGON((45  4, 45  17, 44  19, 44  22, 50  20, 51.5  17, 58  4, 60  0, 53  0, 45  0, 45  4))", polyOne);
    boost::geometry::read_wkt("POLYGON((-10  -5, 0  25, 43  25, 45  20, 50  20, 60  0, 5  0, 5  -5, -10  -5))", polyTwo);

    boost::geometry::correct(polyOne);
    boost::geometry::correct(polyTwo);

    {
        std::ofstream svg("/tmp/svg.svg");
        boost::geometry::svg_mapper<BoostPointXY> mapper(svg, 400, 400);
        mapper.add(polyOne);
        mapper.add(polyTwo);

        mapper.map(polyOne, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
        mapper.map(polyTwo, "fill-opacity:0.5;fill:rgb(204,153,0);stroke:rgb(204,153,0);stroke-width:2");
    }

    std::vector<BoostPolygon> multiPoly;
    boost::geometry::intersection(polyOne,polyTwo,multiPoly);
    std::cout << "Size of Multi " << multiPoly.size() << std::endl;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int main(){
typedef boost::geometry::model::d2::point_xy BoostPointXY;
typedef boost::geometry::model::polygon BoostPolygon;
BoostPolygon polyOne,polyTwo;
boost::geometry::read_wkt(“多边形((454,4517,4419,4422,5020,51.517,584,600,530,450,454))”,普立万;
几何体:read_wkt(“多边形(-10-5,025,4325,4520,5020,600,50,5-5,-10-5)),polyTwo;
升压::几何::正确(普立万);
boost::geometry::correct(两个多边形);
{
std::ofstreamsvg(“/tmp/svg.svg”);
boost::geometry::svg\U映射器映射器(svg,400400);
映射器添加(普立万);
mapper.add(两个);
地图(普立万,“填充不透明度:0.5;填充:rgb(153204,0);笔划:rgb(153204,0);笔划宽度:2”);
map(polytoo,“填充不透明度:0.5;填充:rgb(204153,0);笔划:rgb(204153,0);笔划宽度:2”);
}
std::向量多通道;
boost::geometry::intersection(polyOne、polyTwo、multiPoly);

std::cout相同的1.57输出是多边形无效吗?还是我犯了一个错误?你试过绘制多边形了吗?这是我快速尝试得到的结果:谢谢,我在某处看到了这个wkt。你现在使用了boost 1.57还是?在boost 1.55上,我的输出仍然为零(请键入正确的单词)。你搞乱了其他东西。boost 1_55给出了“Multi 1的大小”完全相同
#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/io/io.hpp>
#include <fstream>
#include <iostream>

int main() {
    typedef boost::geometry::model::d2::point_xy<double> BoostPointXY;
    typedef boost::geometry::model::polygon<BoostPointXY> BoostPolygon;

    BoostPolygon polyOne, polyTwo;
    boost::geometry::read_wkt("POLYGON((45  4, 45  17, 44  19, 44  22, 50  20, 51.5  17, 58  4, 60  0, 53  0, 45  0, 45  4))", polyOne);
    boost::geometry::read_wkt("POLYGON((-10  -5, 0  25, 43  25, 45  20, 50  20, 60  0, 5  0, 5  -5, -10  -5))", polyTwo);

    boost::geometry::correct(polyOne);
    boost::geometry::correct(polyTwo);

    {
        std::ofstream svg("/tmp/svg.svg");
        boost::geometry::svg_mapper<BoostPointXY> mapper(svg, 400, 400);
        mapper.add(polyOne);
        mapper.add(polyTwo);

        mapper.map(polyOne, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
        mapper.map(polyTwo, "fill-opacity:0.5;fill:rgb(204,153,0);stroke:rgb(204,153,0);stroke-width:2");
    }

    std::vector<BoostPolygon> multiPoly;
    boost::geometry::intersection(polyOne,polyTwo,multiPoly);
    std::cout << "Size of Multi " << multiPoly.size() << std::endl;
}