我正在尝试使用boost::geometry::intersects
来检查某个线段是否与多边形相交。以下代码效果很好:
#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <iostream>
namespace bg = boost::geometry;
int main(int argc, char** argv) {
typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
bg::model::ring<Point> poly1, poly2;
bg::model::segment<Point> s1, s2;
bg::read_wkt("POLYGON((0.0 0.0, 1.0 1.0, 0.0 2.0, 2.0 1.0))", poly1);
bg::correct(poly1);
bg::read_wkt("POLYGON((1.5 0.0, 1.5 2.0, 3.0 1.0))", poly2);
bg::correct(poly2);
bg::read_wkt("SEGMENT(0.0 0.0,0.0 2.0)", s1);
bg::read_wkt("SEGMENT(-1.0 1.0,2.0 1.0)", s2);
std::cout << "Polygons intersect " << bg::intersects(poly1, poly2) << std::endl;
std::cout << "Segments intersect " << bg::intersects(s1, s2) << std::endl;
//std::cout << "Polygon and segment intersect " << bg::intersects(poly1, s1) << std::endl;
return 0;
}
但是,如果我使用bg::intersects(poly1, s1)
取消注释该行,则会收到以下编译错误:
g++ -c -g -I/opt/local/include -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.cpp
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:36:
In file included from /opt/local/include/boost/geometry/algorithms/disjoint.hpp:33:
In file included from /opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:56:
/opt/local/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp:542:5: error: no matching function for call to 'assertion_failed'
BOOST_MPL_ASSERT_MSG
^~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:434:48: note: expanded from macro 'BOOST_MPL_ASSERT_MSG'
#define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
^
/opt/local/include/boost/mpl/assert.hpp:428:9: note: expanded from macro '\
BOOST_MPL_ASSERT_MSG_IMPL'
boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:59:58: note: expanded from macro '\
BOOST_MPL_AUX_ASSERT_CONSTANT'
# define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr }
^
/opt/local/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp:661:5: note: in instantiation of template class 'boost::geometry::dispatch::sectionalize<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, false, boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, 2, 10>' requested here
sectionalizer_type::apply(geometry, sections, ring_id);
^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:453:9: note: in instantiation of function template specialization 'boost::geometry::sectionalize<false, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2> >' requested here
geometry::sectionalize<Reverse1>(geometry1, sec1, 0);
^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:877:18: note: in instantiation of member function 'boost::geometry::detail::get_turns::get_turns_generic<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy>::apply' requested here
>::type::apply(
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:118:9: note: in instantiation of function template specialization 'boost::geometry::get_turns<false, false, boost::geometry::detail::disjoint::assign_disjoint_policy, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::disjoint::disjoint_interrupt_policy>' requested here
geometry::get_turns
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:159:54: note: in instantiation of member function 'boost::geometry::detail::disjoint::disjoint_linear<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
if (! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2))
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:261:16: note: in instantiation of member function 'boost::geometry::detail::disjoint::general_areal<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
>::apply(g2, g1);
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:344:54: note: in instantiation of member function 'boost::geometry::dispatch::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2, boost::geometry::ring_tag, boost::geometry::segment_tag, true>::apply' requested here
return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
^
/opt/local/include/boost/geometry/algorithms/intersects.hpp:99:14: note: in instantiation of function template specialization 'boost::geometry::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
return ! geometry::disjoint(geometry1, geometry2);
^
main.cpp:49:52: note: in instantiation of function template specialization 'boost::geometry::intersects<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
std::cout << "Polygon and segment intersect " << bg::intersects(poly1,s1) << std::endl;
^
/opt/local/include/boost/mpl/assert.hpp:82:5: note: candidate function [with C = false] not viable: no known conversion from 'boost::mpl::failed ************(boost::geometry::dispatch::sectionalize<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, false, boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, 2, 10>::NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE::************)(types<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >)' to 'typename assert<false>::type' (aka 'mpl_::assert<false>') for 1st argument
int assertion_failed( typename assert<C>::type );
^
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:36:
In file included from /opt/local/include/boost/geometry/algorithms/disjoint.hpp:33:
In file included from /opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:35:
/opt/local/include/boost/geometry/views/detail/range_type.hpp:39:5: error: no matching function for call to 'assertion_failed'
BOOST_MPL_ASSERT_MSG
^~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:434:48: note: expanded from macro 'BOOST_MPL_ASSERT_MSG'
#define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
^
/opt/local/include/boost/mpl/assert.hpp:428:9: note: expanded from macro '\
BOOST_MPL_ASSERT_MSG_IMPL'
boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:59:58: note: expanded from macro '\
BOOST_MPL_AUX_ASSERT_CONSTANT'
# define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr }
^
/opt/local/include/boost/geometry/views/detail/range_type.hpp:94:32: note: in instantiation of template class 'boost::geometry::dispatch::range_type<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
typedef typename dispatch::range_type
^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:104:22: note: in instantiation of template class 'boost::geometry::detail::range_type<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
typename range_type<Geometry1>::type const,
^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:408:20: note: in instantiation of template class 'boost::geometry::detail::get_turns::get_turns_in_sections<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, boost::geometry::section<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, boost::geometry::section<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy>' requested here
return get_turns_in_sections
^
/opt/local/include/boost/geometry/algorithms/detail/partition.hpp:415:29: note: in instantiation of function template specialization 'boost::geometry::detail::get_turns::section_visitor<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy>::apply<boost::geometry::section<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2> >' requested here
visitor.apply(*it1, *it2);
^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:464:9: note: in instantiation of function template specialization 'boost::geometry::partition<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::detail::get_turns::get_section_box, boost::geometry::detail::get_turns::ovelaps_section_box, boost::geometry::visit_no_policy>::apply<boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, boost::geometry::detail::get_turns::section_visitor<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy> >' requested here
geometry::partition
^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:877:18: note: (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
>::type::apply(
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:159:54: note: in instantiation of member function 'boost::geometry::detail::disjoint::disjoint_linear<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
if (! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2))
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:261:16: note: in instantiation of member function 'boost::geometry::detail::disjoint::general_areal<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
>::apply(g2, g1);
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:344:54: note: in instantiation of member function 'boost::geometry::dispatch::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2, boost::geometry::ring_tag, boost::geometry::segment_tag, true>::apply' requested here
return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
^
/opt/local/include/boost/geometry/algorithms/intersects.hpp:99:14: note: in instantiation of function template specialization 'boost::geometry::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
return ! geometry::disjoint(geometry1, geometry2);
^
main.cpp:49:52: note: in instantiation of function template specialization 'boost::geometry::intersects<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
std::cout << "Polygon and segment intersect " << bg::intersects(poly1,s1) << std::endl;
^
/opt/local/include/boost/mpl/assert.hpp:82:5: note: candidate function [with C = false] not viable: no known conversion from 'boost::mpl::failed ************(boost::geometry::dispatch::range_type<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >::NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE::************)(types<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >)' to 'typename assert<false>::type' (aka 'mpl_::assert<false>') for 1st argument
int assertion_failed( typename assert<C>::type );
^
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:23:
In file included from /opt/local/include/boost/range.hpp:26:
In file included from /opt/local/include/boost/range/functions.hpp:18:
In file included from /opt/local/include/boost/range/begin.hpp:24:
In file included from /opt/local/include/boost/range/iterator.hpp:23:
/opt/local/include/boost/mpl/eval_if.hpp:60:26: error: no type named 'type' in 'boost::range_const_iterator<int>'
typedef typename f_::type type;
~~~~~~~~~~~~~^~~~
/opt/local/include/boost/range/iterator.hpp:61:18: note: in instantiation of template class 'boost::mpl::eval_if_c<true, boost::range_const_iterator<int>, boost::range_mutable_iterator<const int> >' requested here
mpl::eval_if_c< is_const<C>::value,
^
/opt/local/include/boost/geometry/views/identity_view.hpp:38:29: note: in instantiation of template class 'boost::range_iterator<const int>' requested here
typedef typename boost::range_iterator<Range const>::type const_iterator;
^
/opt/local/include/boost/range/const_iterator.hpp:36:9: note: in instantiation of template class 'boost::geometry::identity_view<const int>' requested here
BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( const_iterator )
^
/opt/local/include/boost/range/detail/extract_optional_type.hpp:45:82: note: expanded from macro 'BOOST_RANGE_EXTRACT_OPTIONAL_TYPE'
, BOOST_DEDUCED_TYPENAME boost::range_detail::exists< BOOST_DEDUCED_TYPENAME C::a_typedef >::type \
^
/opt/local/include/boost/range/const_iterator.hpp:36:9: note: during template argument deduction for class template partial specialization 'extract_const_iterator<type-parameter-0-0, typename exists<typename type-parameter-0-0::const_iterator>::type>' [with C = boost::geometry::identity_view<const int>]
BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( const_iterator )
^
/opt/local/include/boost/range/detail/extract_optional_type.hpp:44:12: note: expanded from macro 'BOOST_RANGE_EXTRACT_OPTIONAL_TYPE'
struct extract_ ## a_typedef< C \
^
<scratch space>:16:1: note: expanded from here
extract_const_iterator
^
/opt/local/include/boost/mpl/eval_if.hpp:60:22: note: in instantiation of template class 'boost::range_const_iterator<boost::geometry::identity_view<const int> >' requested here
typedef typename f_::type type;
^
/opt/local/include/boost/range/iterator.hpp:61:18: note: (skipping 7 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
mpl::eval_if_c< is_const<C>::value,
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:159:54: note: in instantiation of member function 'boost::geometry::detail::disjoint::disjoint_linear<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
if (! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2))
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:261:16: note: in instantiation of member function 'boost::geometry::detail::disjoint::general_areal<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
>::apply(g2, g1);
^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:344:54: note: in instantiation of member function 'boost::geometry::dispatch::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2, boost::geometry::ring_tag, boost::geometry::segment_tag, true>::apply' requested here
return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
^
/opt/local/include/boost/geometry/algorithms/intersects.hpp:99:14: note: in instantiation of function template specialization 'boost::geometry::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
return ! geometry::disjoint(geometry1, geometry2);
^
main.cpp:49:52: note: in instantiation of function template specialization 'boost::geometry::intersects<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
std::cout << "Polygon and segment intersect " << bg::intersects(poly1,s1) << std::endl;
^
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:23:
In file included from /opt/local/include/boost/range.hpp:26:
In file included from /opt/local/include/boost/range/functions.hpp:18:
In file included from /opt/local/include/boost/range/begin.hpp:24:
In file included from /opt/local/include/boost/range/iterator.hpp:23:
/opt/local/include/boost/mpl/eval_if.hpp:60:26: error: no type named 'type' in 'boost::range_const_iterator<boost::geometry::identity_view<const int> >'
typedef typename f_::type type;
~~~~~~~~~~~~~^~~~
/opt/local/include/boost/range/iterator.hpp:61:18: note: in instantiation of template class 'boost::mpl::eval_if_c<true, boost::range_const_iterator<boost::geometry::identity_view<const int> >, boost::range_mutable_iterator<const boost::geometry::identity_view<const int> > >' requested here
mpl::eval_if_c< is_const<C>::value,
^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:124:29: note: in instantiation of template class 'boost::range_iterator<const boost::geometry::identity_view<const int> >' requested here
typedef typename boost::range_iterator
^
...
8 errors generated.
make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
这是一个错误还是我遗忘了什么?
答案 0 :(得分:2)
这个问题有点陈旧,但另一个答案并不是很好。我的解决方案是将它们转换为线串,然后找出它们是否相交(如果你考虑它,结果应该是相同的,但它不适用于交叉)
#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <iostream>
namespace bg = boost::geometry;
int main(int argc, char** argv) {
typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
typedef bg::model::linestring<Point> linestring;
bg::model::ring<Point> poly1, poly2;
bg::model::segment<Point> s1, s2;
bg::read_wkt("POLYGON((0.0 0.0, 1.0 1.0, 0.0 2.0, 2.0 1.0))", poly1);
bg::correct(poly1);
bg::read_wkt("POLYGON((1.5 0.0, 1.5 2.0, 3.0 1.0))", poly2);
bg::correct(poly2);
bg::read_wkt("SEGMENT(0.0 0.0,0.0 2.0)", s1);
bg::read_wkt("SEGMENT(-1.0 1.0,2.0 1.0)", s2);
std::cout << "Polygons intersect " << bg::intersects(poly1, poly2) << std::endl;
std::cout << "Segments intersect " << bg::intersects(s1, s2) << std::endl;
std::vector<Point> v{s1.first,s1.second};
std::cout << "Polygon and segment intersect " << bg::intersects(linestring(poly1.begin(),poly1.end()), linestring(v.begin(),v.end())) << std::endl;
return 0;
}
答案 1 :(得分:1)
似乎你的想法“也许他们没有为所有可能的对实现它”确实是问题。 boost::geometry::intersects
调用了boost::geometry::disjoint
,确实存在模板专精,用于测试不同模型类型的不相交,包括Segment
+ Box
和Linestring
+ {{ 1}},但似乎没有一个用于Box
+ Segment
(虽然Ring
+ Linestring
也有一个,虽然模板有点看起来似乎是一个中间人模板,它会将类型参数的顺序切换为匹配,这意味着如果你遇到这两个问题可能会有更深层次的问题。)