首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >促进::几何学::交集返回

促进::几何学::交集返回
EN

Stack Overflow用户
提问于 2020-07-27 15:29:54
回答 1查看 330关注 0票数 1

boost::geometry::intersection( 3.html )的文档表示该函数返回一个bool。但是,文档没有说明返回值指示的是什么。我猜如果找到了一个交集,它就会返回true。

错了!

这段代码

代码语言:javascript
复制
#include <iostream>
#include <deque>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/point.hpp>

namespace bg = boost::geometry;
using namespace std;

class cxy
{
public:
    double x;
    double y;
    cxy( double X, double Y )
        : x( X )
        , y( Y )
    {

    }
    /// boost geometry insists on a default constructor
    cxy()
        : cxy(0,0)
    {

    }
};

BOOST_GEOMETRY_REGISTER_POINT_2D( cxy, double, bg::cs::cartesian, x, y )
typedef bg::model::segment<cxy> segment_t;

int main()
{
    cxy a(1,0);
    cxy b(1,1);
    cxy c(0,0.5);
    cxy d(0.5,0.5) ;

    segment_t ab( a, b );
    segment_t cd( c, d );
    std::vector<cxy> out;
    if( ! bg::intersection( ab, cd, out ) ) {
       std::cout << "intersection returned false\n";
       return 1;
    }
    if( ! out.size() ) {
        std::cout << "no intersection point!\n";
        return 2;
    }
    std::cout << "intersection at " << out[0].x <<" " << out[0].y << "\n";

    return 0;
}

输出

代码语言:javascript
复制
no intersection point!

真实指示的返回是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-27 16:14:25

返回值为true,表示没有错误。例如,在呼叫链的深处:

代码语言:javascript
复制
template <typename RobustPolicy, typename GeometryOut, typename Strategy>
static inline bool apply(Geometry1 const& geometry1,
        Geometry2 const& geometry2,
        RobustPolicy const& robust_policy,
        GeometryOut& geometry_out,
        Strategy const& strategy)
{
    typedef typename geometry::detail::output_geometry_value
        <
            GeometryOut
        >::type SingleOut;

    intersection_insert
        <
            Geometry1, Geometry2, SingleOut,
            overlay_intersection
        >::apply(geometry1, geometry2, robust_policy,
                 geometry::detail::output_geometry_back_inserter(geometry_out),
                 strategy);

    return true;
}

那是在

代码语言:javascript
复制
#0  0x000055555555598c in boost::geometry::dispatch::intersection<boost::geometry::model::segment<cxy>, boost::geometry::model::segment<cxy>, boost::geometry::segment_tag, boost::geometry::segment_tag, false>::apply<boost::geometry::detail::no_rescale_policy, std::vector<cxy, std::allocator<cxy> >, boost::geometry::strategy::intersection::cartesian_segments<void> > (geometry1=..., geometry2=..., robust_policy=..., geometry_out=std::vector of length 0, capacity 0, strategy=...) at /home/sehe/custom/boost_1_73_0/boost/geometry/algorithms/detail/intersection/interface.hpp:63
#1  0x0000555555555842 in boost::geometry::resolve_strategy::intersection::apply<boost::geometry::model::segment<cxy>, boost::geometry::model::segment<cxy>, std::vector<cxy, std::allocator<cxy> > > (geometry1=..., geometry2=..., geometry_out=std::vector of length 0, capacity 0) at /home/sehe/custom/boost_1_73_0/boost/geometry/algorithms/detail/intersection/interface.hpp:175
#2  0x00005555555556ed in boost::geometry::resolve_variant::intersection<boost::geometry::model::segment<cxy>, boost::geometry::model::segment<cxy> >::apply<std::vector<cxy, std::allocator<cxy> >, boost::geometry::default_strategy> (geometry1=..., geometry2=..., geometry_out=std::vector of length 0, capacity 0, strategy=...) at /home/sehe/custom/boost_1_73_0/boost/geometry/algorithms/detail/intersection/interface.hpp:198
#3  0x00005555555554f3 in boost::geometry::intersection<boost::geometry::model::segment<cxy>, boost::geometry::model::segment<cxy>, std::vector<cxy, std::allocator<cxy> > > (geometry1=..., geometry2=..., geometry_out=std::vector of length 0, capacity 0) at /home/sehe/custom/boost_1_73_0/boost/geometry/algorithms/detail/intersection/interface.hpp:403
#4  0x0000555555554eab in main () at /home/sehe/Projects/stackoverflow/test.cpp:40

我查看了Boost地质测量的OGC简单特性规范

图书馆遵循现有的公约:

  • 来自boost的会议
  • 科技促进发展图书馆公约和
  • 名称来自OGC几何学标准之一,更确切地说是来自OGC简单特征规范

它在概念上建模算法,没有返回值:

我检查了算法/细节/交叉(areal_areal.hpp、box_box.hpp、implementation.hpp、interface.hpp、multi.hpp)中的所有实现,没有任何返回为false。

TL;DR综述

返回值是明确无文档化的,换句话说:它是一个您可能不依赖的实现细节。

在库接口方面,文档化的接口不能在新版本中更改(没有警告)。许多通过标头“可发现”的东西都是没有文档的--最常见的是detail::名称空间和/或detail/头文件夹。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63118550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档