Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用boost::geometry::intersects时出现运行时错误_C++_Boost_Boost Geometry - Fatal编程技术网

C++ 使用boost::geometry::intersects时出现运行时错误

C++ 使用boost::geometry::intersects时出现运行时错误,c++,boost,boost-geometry,C++,Boost,Boost Geometry,当使用boost::geometry::intersects判断两个几何体是否相交时,我遇到一个运行时错误,我得到以下错误: 测试:/bigdisk/geo.algorithms/mason_包/headers/boost/1.65.1/include/boost/geometry/policies/robustness/segment_ratio.hpp:54:静态bool boost::geometry::detail::segment_ratio::less::apply(const ra

当使用boost::geometry::intersects判断两个几何体是否相交时,我遇到一个运行时错误,我得到以下错误:

测试:/bigdisk/geo.algorithms/mason_包/headers/boost/1.65.1/include/boost/geometry/policies/robustness/segment_ratio.hpp:54:静态bool boost::geometry::detail::segment_ratio::less::apply(const ratio&,const ratio&)[with ratio=boost::geometry::segment_ratio::Type=double]:断言`lhs.分母“0”失败。 第1行等于第2行:中止

在我天真的眼中,问题并不明显。如果有人有任何建议,我将不胜感激

我已将boost geometry改编为我自己的几何模型,在这种情况下,boost的intersects函数刚刚中止:

    point<double, GCJ02LL> pt11{118.8031, 32.10011};
    point<double, GCJ02LL> pt12{118.80297, 32.10016};
    point<double, GCJ02LL> pt13{118.80284, 32.10021};
    dataop::geometry::line_string<double, GCJ02LL> line1{pt11, pt12, pt13};
    dataop::geometry::line_string<double, GCJ02LL> line2{pt11, pt12, pt13};
    std::cout << "line1 intersects line2? : " << intersects(line1, line2) << std::endl;
点pt11{118.8031,32.10011};
pt12点{118.80297,32.10016};
点pt13{118.80284,32.10021};
dataop::geometry::line_字符串line1{pt11,pt12,pt13};
dataop::geometry::line_字符串line2{pt11,pt12,pt13};

std::cout触发断言。您的某些数据无效/不适合您尝试执行的操作

具体而言,内部计算步骤遇到分母(q)为零的分数(p/q)。那不会飞的

现在,造成这种情况的原因可能是未满足的先决条件

可能您的几何图形无效(您是否尝试过
bg::is\u valid()
?是否查看了
bg::correct()
?)

如果满足了所有的先决条件,那么罪魁祸首可能是对自定义类型的修改。如果改编调用了未定义的行为(例如错误地返回对临时人员的引用),则所有赌注都将被取消

试验台 您可以调整此测试台以获得一些诊断:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

#include <iostream>

namespace bg = boost::geometry;
namespace bgm = bg::model;

int main() {
    using P = bgm::d2::point_xy<double>;
    P pt11{ 118.8031, 32.10011 };
    P pt12{ 118.80297, 32.10016 };
    P pt13{ 118.80284, 32.10021 };
    bgm::linestring<P> line1{ pt11, pt12, pt13 };
    bgm::linestring<P> line2{ pt11, pt12, pt13 };
    std::string reason;
    std::cout << std::boolalpha;
    std::cout << "line1 valid? " << bg::is_valid(line1, reason) << " (" << reason << ")\n";
    std::cout << "line2 valid? " << bg::is_valid(line2, reason) << " (" << reason << ")\n";
    std::cout << "line1 intersects line2? : " << bg::intersects(line1, line2) << std::endl;
}

一个断言触发。您的某些数据无效/不适合您尝试执行的操作

具体而言,内部计算步骤遇到分母(q)为零的分数(p/q)。那不会飞的

现在,造成这种情况的原因可能是未满足的先决条件

可能您的几何图形无效(您是否尝试过
bg::is\u valid()
?是否查看了
bg::correct()
?)

如果满足了所有的先决条件,那么罪魁祸首可能是对自定义类型的修改。如果改编调用了未定义的行为(例如错误地返回对临时人员的引用),则所有赌注都将被取消

试验台 您可以调整此测试台以获得一些诊断:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

#include <iostream>

namespace bg = boost::geometry;
namespace bgm = bg::model;

int main() {
    using P = bgm::d2::point_xy<double>;
    P pt11{ 118.8031, 32.10011 };
    P pt12{ 118.80297, 32.10016 };
    P pt13{ 118.80284, 32.10021 };
    bgm::linestring<P> line1{ pt11, pt12, pt13 };
    bgm::linestring<P> line2{ pt11, pt12, pt13 };
    std::string reason;
    std::cout << std::boolalpha;
    std::cout << "line1 valid? " << bg::is_valid(line1, reason) << " (" << reason << ")\n";
    std::cout << "line2 valid? " << bg::is_valid(line2, reason) << " (" << reason << ")\n";
    std::cout << "line1 intersects line2? : " << bg::intersects(line1, line2) << std::endl;
}
line1 valid? true (Geometry is valid)
line2 valid? true (Geometry is valid)
line1 intersects line2? : true