boost::geometry::intersection return 是什么意思
What does boost::geometry::intersection return
boost::geometry::intersection
(https://www.boost.org/doc/libs/1_73_0/libs/geometry/doc/html/geometry/reference/algorithms/intersection/intersection_3.html) 的文档说函数 return 是一个布尔值。但是文档没有说明 return 值表示什么。我猜如果找到交集,它会 return 正确。
错了!!!
这个代码
#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;
}
产出
no intersection point!
true表示的return是什么?
return 值为真,表示没有错误。例如。深入调用链:
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;
}
那是在
#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/Whosebug/test.cpp:40
的 OGC 简单特征规范
The library follows existing conventions:
- conventions from boost
- conventions from the std library conventions and
- names from one of the OGC standards on geometry and, more
specificly, from the OGC Simple Feature Specification
它在概念上模拟了没有 return 值的算法:
我检查了 algorithms/detail/intersection 中的所有实现(areal_areal.hpp、box_box.hpp、implementation.hpp、interface.hpp、multi.hpp),但没有 returns false.
TL;DR 总结
return-value 具体 未记录,换句话说:它是您可能不依赖的实现细节。
就库界面而言,文档化的界面在新版本中可能不会更改(没有警告)。很多 'discoverable' 到 header 的东西都是 未记录的 - 通常由 detail::
命名空间 and/or detail/
header 个文件夹。
boost::geometry::intersection
(https://www.boost.org/doc/libs/1_73_0/libs/geometry/doc/html/geometry/reference/algorithms/intersection/intersection_3.html) 的文档说函数 return 是一个布尔值。但是文档没有说明 return 值表示什么。我猜如果找到交集,它会 return 正确。
错了!!!
这个代码
#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;
}
产出
no intersection point!
true表示的return是什么?
return 值为真,表示没有错误。例如。深入调用链:
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;
}
那是在
#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/Whosebug/test.cpp:40
的 OGC 简单特征规范
The library follows existing conventions:
- conventions from boost
- conventions from the std library conventions and
- names from one of the OGC standards on geometry and, more specificly, from the OGC Simple Feature Specification
它在概念上模拟了没有 return 值的算法:
我检查了 algorithms/detail/intersection 中的所有实现(areal_areal.hpp、box_box.hpp、implementation.hpp、interface.hpp、multi.hpp),但没有 returns false.
TL;DR 总结
return-value 具体 未记录,换句话说:它是您可能不依赖的实现细节。
就库界面而言,文档化的界面在新版本中可能不会更改(没有警告)。很多 'discoverable' 到 header 的东西都是 未记录的 - 通常由 detail::
命名空间 and/or detail/
header 个文件夹。