使用boost :: geometry :: intersects时的运行时错误

问题描述 投票:1回答:1

当使用boost :: geometry :: intersects来判断两个几何是否相互交叉时,我得到一个运行时错误,我得到这个错误:

test:/bigdisk/geo.algorithms/mason_packages/headers/boost/1.65.1/include/boost/geometry/policies/robustness/segment_ratio.hpp:54:static bool boost :: geometry :: detail :: segment_ratio :: less :: apply(const Ratio&,const Ratio&)[with Ratio = boost :: geometry :: segment_ratio; Type = double]:断言`lhs.denominator()!= 0'失败。 line1等于line2:已中止

对我天真的眼睛来说,问题是什么并不明显。如果有人有任何建议我会非常感激。

我已经将boost几何修改为我自己的几何模型,并且在这种情况下,boost的交叉函数刚刚中止:

    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;

你可以看到我的两个line_strings是相同的,但它不是问题,因为在其他情况下它运行良好。

更奇怪的是,boost :: geometry :: equal也将在这种情况下中止,如下所示:

    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};
    std::cout << "line1 equal line1? " << equal(line1, line1) << std::endl;
c++ boost boost-geometry
1个回答
0
投票

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

具体地,内部计算步骤遇到分母(p / q),其中分母(q)为零。那不会飞。

现在,造成这种情况的原因将是未满足的前提条件。

也许你的几何形状无效(你试过bg::is_valid()吗?你看过bg::correct()吗?)。

如果所有前提条件都已满足,那么罪魁祸首就是适应您的自定义类型。如果改编调用未定义的行为(例如,错误地返回对临时的引用),那么所有的赌注都是关闭的。

试验台

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

Live On Coliru

#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
© www.soinside.com 2019 - 2024. All rights reserved.