使用boost::geometry::intersects时出现运行时错误
Run-time error when using boost::geometry::intersects
当使用boost::geometry::intersects来判断两个几何体是否相交时,我得到一个运行时错误,我得到这个错误:
test:/bigdisk/geo.agorithms/maso_packages/headers/boost/1.65.1/include/boost/geometry/policies/robusty/segment_ratio.hpp:54:static bool boost::geometry::detail::segment_radio::less::apply(const ratio&,const ratio&)[其中ratio=boost:几何体::segment_ratio;Type=double]:断言`lhs.denominator()!="0"失败。第1行等于第2行:中止
在我天真的眼中,问题出在哪里并不明显。如果有人有任何建议,我将不胜感激。
我已经将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-string是一样的,但这不是问题所在,因为在其他情况下它运行得很好。
更奇怪的是,在这种情况下,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;
一个断言被触发。您的某些数据无效/不适合您尝试执行的操作。
具体地,内部计算步骤遇到分母(q)为零的分数(p/q)。那不会飞的。
现在,造成这种情况的原因将是未满足的先决条件。
也许您的几何图形无效(您尝试过bg::is_valid()
吗?查看过bg::correct()
吗?)。
如果满足了所有先决条件,那么罪魁祸首可能是对自定义类型的改编。如果自适应调用了未定义的行为(例如错误地返回对临时性的引用),则所有赌注都将失效。
试验台
你可以调整这个测试台来获得一些诊断:
在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
- 删除指向指针的指针是运行时错误吗
- c++中的指针和运行时错误
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 对单向链表进行排序时出现运行时错误
- 为什么此代码存在运行时错误?
- 你能解释一下什么运行时错误是如何解决它的吗?
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 运行时错误:引用绑定到类型为"int"的空指针
- 为什么当 vector 为空时会显示运行时错误?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 运行时错误:矢量下标超出范围:正在检查空集
- 分配给gslice_array会导致运行时错误
- cout 新创建的对象引发运行时错误
- C++在使用std::multimap时出现运行时错误的几率很小
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- 试图找出为什么我会收到运行时错误?
- 迭代二维矢量时发生运行时错误
- 调用 java 的回调() 时应用程序崩溃.由于 detatchThread 而获得运行时错误