Я пытаюсь вычислить расстояние между точкой и отрезком.Но следующий код завершается во время выполнения внезапно (@comparable_distance).
using namespace std;
namespace bg = boost::geometry;
class Vertex {
public:
Vertex(int px, int py):x(px), y(py){}
int x;
int y;
};
BOOST_GEOMETRY_REGISTER_POINT_2D(Vertex, double, cs::cartesian, x, y)
typedef Vertex* vertref;
typedef bg::model::segment<vertref> segment_type;
std::vector<segment_type> segments;
int main()
{
segment_type l(new Vertex(1,2), new Vertex(2,2));
Vertex p(4,5);
double comp_dist = 0;
comp_dist = bg::comparable_distance(p, l);
cout<<comp_dist<<endl;
return 0;
}
Если я заменю bg :: model :: сегмент на linestring;добавьте два пункта к нему, он работает без ошибок, как показано ниже ...
using namespace std;
namespace bg = boost::geometry;
class Vertex {
public:
Vertex(int px, int py):x(px), y(py){}
int x;
int y;
};
BOOST_GEOMETRY_REGISTER_POINT_2D(Vertex, double, cs::cartesian, x, y)
typedef Vertex* vertref;
typedef bg::model::linestring<vertref> segment_type;
std::vector<segment_type> segments;
int main()
{
segment_type l;
l.push_back(new Vertex(1,2));
l.push_back(new Vertex(2,2));
Vertex p(4,5);
double comp_dist = 0;
comp_dist = bg::comparable_distance(p, l);
cout<<comp_dist<<endl;
return 0;
}
Есть идеи, что я делаю неправильно в первом коде с использованием сегмента?
Спасибо!
Стек вызовов ...
#0 0x40486f boost::geometry::traits::access<Vertex, 0u, void>::set(p=..., value=@0x63fde8: 1) (C:\Projects\test\main.cpp:17)
#1 0x403e14 boost::geometry::core_dispatch::access<boost::geometry::point_tag, Vertex, double, 0u, boost::integral_constant<bool, true> >::set(p=0x77b12580, value=@0x63fde8: 1) (C:/boost_1_68_0/boost/geometry/core/access.hpp:187)
#2 0x404182 boost::geometry::set<0u, Vertex*>(geometry=@0x63fe34: 0x77b12580, value=@0x63fde8: 1, dummy=0x0) (C:/boost_1_68_0/boost/geometry/core/access.hpp:321)
#3 0x40469a boost::geometry::detail::assign::assign_point_from_index<boost::geometry::model::segment<Vertex*>, Vertex*, 0u, 0u, 2u>::apply(geometry=..., point=@0x63fe34: 0x77b12580) (C:/boost_1_68_0/boost/geometry/algorithms/detail/assign_values.hpp:195)
#4 0x4045de boost::geometry::detail::assign_point_from_index<0u, Vertex*, boost::geometry::model::segment<Vertex*> >(geometry=..., point=@0x63fe34: 0x77b12580) (C:/boost_1_68_0/boost/geometry/algorithms/detail/assign_indexed_point.hpp:80)
#5 0x4049fc boost::geometry::dispatch::distance<Vertex, boost::geometry::model::segment<Vertex*>, boost::geometry::strategy::distance::projected_point<void, boost::geometry::strategy::distance::comparable::pythagoras<void> >, boost::geometry::point_tag, boost::geometry::segment_tag, boost::geometry::strategy_tag_distance_point_segment, false>::apply(point=..., segment=..., strategy=...) (C:/boost_1_68_0/boost/geometry/algorithms/detail/distance/point_to_geometry.hpp:419)
#6 0x403f9b boost::geometry::resolve_strategy::comparable_distance::apply<Vertex, boost::geometry::model::segment<Vertex*> >(geometry1=..., geometry2=...) (C:/boost_1_68_0/boost/geometry/algorithms/detail/comparable_distance/interface.hpp:83)
#7 0x403f38 boost::geometry::resolve_variant::comparable_distance<Vertex, boost::geometry::model::segment<Vertex*> >::apply<boost::geometry::default_strategy>(geometry1=..., geometry2=..., strategy=...) (C:/boost_1_68_0/boost/geometry/algorithms/detail/comparable_distance/interface.hpp:106)
#8 0x403ff5 boost::geometry::comparable_distance<Vertex, boost::geometry::model::segment<Vertex*>, boost::geometry::default_strategy>(geometry1=..., geometry2=..., strategy=...) (C:/boost_1_68_0/boost/geometry/algorithms/detail/comparable_distance/interface.hpp:328)
#9 0x403fc9 boost::geometry::comparable_distance<Vertex, boost::geometry::model::segment<Vertex*> >(geometry1=..., geometry2=...) (C:/boost_1_68_0/boost/geometry/algorithms/detail/comparable_distance/interface.hpp:356)
#10 0x401518 main() (C:\Projects\test\main.cpp:30)