有关boost :: geometry :: intersects的问题

时间:2019-05-30 05:38:54

标签: c++ boost-geometry

我用"clang++ -fsanitize=undefined"编译了程序。当我使用boost::geometry::intersects检查多边形是否相交时,它为我提供了正确的结果,而且还报告了溢出错误。我的问题是,溢出错误是否导致boost::geometry::intersects函数错误?如果导致功能错误,该如何避免?

#include <iostream>
#include <vector>
#include <limits>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/foreach.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/geometries.hpp>
using namespace std; 
typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<long long> > polygon_t;
int main()
{
    bool overlap=false;
    polygon_t polygon1,polygon2;

    boost::geometry::read_wkt(
    "POLYGON((1036000 1000,1036000 1484300,4193980 1484300,4193980 1000,1036000 1000))", polygon1);
    boost::geometry::read_wkt(
    "POLYGON((1120 1484300,1120 1485000,4193980 1485000,4193980 1484300,1120 1484300))", polygon2);

    overlap=boost::geometry::intersects(polygon1,polygon2);
    if(overlap==true)
    {
        cout<<"detect_overlap"<<endl;
    }
    else
    {   
        cout<<"detect_No_overlap"<<endl;
    }

}

编译后,出现错误:

/usr/local/include/boost/geometry/strategies/cartesian/intersection.hpp:198:29: 
runtime error: signed integer overflow: 6219269238000 * 1483300 cannot be
represented in type 'long long'

以及预期的输出:

detect_overlap

0 个答案:

没有答案