I am trying to use boost geometry algorithms with my own custom polygon type. But I getting compiler errors (in Visual Studio 2019 Windows 10).
I have simplified what I am trying to do into the following code.
In my_custom_polygon.hpp
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
using point = boost::geometry::model::d2::point_xy<double>;
using ring = boost::geometry::model::ring<point>;
struct MyPoly
{
ring exteriorRing;
std::vector<ring> interiorRings;
};
using polygon = MyPoly;
using multipolygon = std::vector<MyPoly>;
//using polygon = boost::geometry::model::polygon<point>;
//using multipolygon = boost::geometry::model::multi_polygon<polygon>;
namespace boost::geometry::traits
{
template<> struct tag<MyPoly> { using type = polygon_tag; };
template<> struct tag<std::vector<MyPoly>> { using type = multi_polygon_tag; };
template<> struct ring_const_type<MyPoly> { using type = const ring; };
template<> struct ring_mutable_type<MyPoly> { using type = ring; };
template<> struct interior_const_type<MyPoly> { using type = const std::vector<ring>; };
template<> struct interior_mutable_type<MyPoly> { using type = std::vector<ring>; };
template<> struct exterior_ring<MyPoly>
{
static ring& get(MyPoly& poly) { return poly.exteriorRing; }
static const ring& get(const MyPoly& poly) { return poly.exteriorRing; }
};
template<> struct interior_rings<MyPoly>
{
static std::vector<ring>& get(MyPoly& poly) { return poly.interiorRings; }
static const std::vector<ring>& get(const MyPoly& poly) { return poly.interiorRings; }
};
}
In my_custom_polygon.cpp
int main(int argc, const char** argv)
{
const double buffer_distance = 1.0;
const int points_per_circle = 36;
boost::geometry::strategy::buffer::distance_symmetric<double> distance_strategy(buffer_distance);
boost::geometry::strategy::buffer::join_round join_strategy(points_per_circle);
boost::geometry::strategy::buffer::end_round end_strategy(points_per_circle);
boost::geometry::strategy::buffer::point_circle circle_strategy(points_per_circle);
boost::geometry::strategy::buffer::side_straight side_strategy;
multipolygon result;
point p{0.0, 0.0};
boost::geometry::buffer(p, result,
distance_strategy, side_strategy,
join_strategy, end_strategy, circle_strategy);
return 0
}
This fails to compile with an error C2664 in boost/geometry/algorithms/detail/overlay/convert_ring.hpp on line 70
It says it cannot convert argument 2 from 'boost::geometry::model::ring<point,true,true,std::vector,std::allocator>' to 'Geometry2 &'
But if I use the commented out lines in the .hpp file for the polygon and multipolygon types it compiles and runs just fine.
I am obviously not adapting the polygon correctly.
Anybody have any ideas?
Thanks