簡體   English   中英

boost :: geometry :: intersects對不同的幾何類型不起作用?

[英]boost::geometry::intersects doesn't work for different geometry types?

我正在嘗試使用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

那是一個錯誤還是我忘記了什么?

這個問題有點老了,但另一個答案並不好。 我的解決方案是將它們都轉換為線串,然后找出它們是否相交(如果您考慮過,結果應該是相同的,但不適用於相交)

#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;
}

您似乎認為“也許他們沒有對所有可能的對都實施”確實是問題所在。 boost::geometry::intersects在引擎蓋下調用boost::geometry::disjoint ,確實存在模板專業化,用於測試不同模型類型(包括Segment + BoxLinestring + Box不相交,但似乎並沒有一個對於Segment + Ring (盡管Linestring + Segment也有一個),盡管模板有些棘手,但似乎確實存在一個中間人模板,該模板將切換類型參數的順序以匹配它們,這意味着如果您這兩個人可能有更深層次的問題)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM