-
-
Save jfirebaugh/98e961c9be11990ac6aadea21bc1683e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mapbox/geometry.hpp> | |
#pragma GCC diagnostic push | |
#pragma GCC diagnostic ignored "-Wunused-function" | |
#pragma GCC diagnostic ignored "-Wunused-parameter" | |
#pragma GCC diagnostic ignored "-Wunused-variable" | |
#pragma GCC diagnostic ignored "-Wshadow" | |
#ifdef __clang__ | |
#pragma GCC diagnostic ignored "-Wunknown-pragmas" | |
#endif | |
#pragma GCC diagnostic ignored "-Wpragmas" | |
#pragma GCC diagnostic ignored "-Wdeprecated-register" | |
#pragma GCC diagnostic ignored "-Wshorten-64-to-32" | |
#pragma GCC diagnostic ignored "-Wunused-local-typedefs" | |
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" | |
#include <boost/geometry.hpp> | |
#pragma GCC diagnostic pop | |
#include <boost/range/iterator_range_core.hpp> | |
#include <cassert> | |
template <class Polygon> | |
struct interior_wrapper : boost::iterator_range<decltype(Polygon().begin())> { | |
using base = boost::iterator_range<decltype(Polygon().begin())>; | |
Polygon& polygon; | |
interior_wrapper(Polygon& p) | |
: base(p.begin() + 1, p.end()), polygon(p) {} | |
void resize(std::size_t size) { | |
polygon.resize(size + 1); | |
} | |
}; | |
namespace boost { | |
namespace geometry { | |
namespace traits { | |
template <typename CoordinateType> | |
struct tag<mapbox::geometry::point<CoordinateType>> | |
{ | |
using type = point_tag; | |
}; | |
template <typename CoordinateType> | |
struct coordinate_type<mapbox::geometry::point<CoordinateType>> | |
{ | |
using type = CoordinateType; | |
}; | |
template <typename CoordinateType> | |
struct coordinate_system<mapbox::geometry::point<CoordinateType>> | |
{ | |
using type = boost::geometry::cs::cartesian; | |
}; | |
template <typename CoordinateType> | |
struct dimension<mapbox::geometry::point<CoordinateType>> | |
: boost::mpl::int_<2> | |
{ | |
}; | |
template <typename CoordinateType> | |
struct access<mapbox::geometry::point<CoordinateType>, 0> | |
{ | |
static auto get(mapbox::geometry::point<CoordinateType> const& p) | |
{ | |
return p.x; | |
} | |
static void set(mapbox::geometry::point<CoordinateType>& p, CoordinateType x) | |
{ | |
p.x = x; | |
} | |
}; | |
template <typename CoordinateType> | |
struct access<mapbox::geometry::point<CoordinateType>, 1> | |
{ | |
static auto get(mapbox::geometry::point<CoordinateType> const& p) | |
{ | |
return p.y; | |
} | |
static void set(mapbox::geometry::point<CoordinateType>& p, CoordinateType y) | |
{ | |
p.y = y; | |
} | |
}; | |
template <typename CoordinateType> | |
struct tag<mapbox::geometry::linear_ring<CoordinateType>> | |
{ | |
using type = ring_tag; | |
}; | |
template <typename CoordinateType> | |
struct tag<mapbox::geometry::polygon<CoordinateType>> | |
{ | |
using type = polygon_tag; | |
}; | |
template <typename CoordinateType> | |
struct ring_mutable_type<mapbox::geometry::polygon<CoordinateType>> | |
{ | |
using type = mapbox::geometry::linear_ring<CoordinateType>&; | |
}; | |
template <typename CoordinateType> | |
struct ring_const_type<mapbox::geometry::polygon<CoordinateType>> | |
{ | |
using type = mapbox::geometry::linear_ring<CoordinateType> const&; | |
}; | |
template <typename CoordinateType> | |
struct interior_mutable_type<mapbox::geometry::polygon<CoordinateType>> | |
{ | |
using type = interior_wrapper<mapbox::geometry::polygon<CoordinateType>>; | |
}; | |
template <typename CoordinateType> | |
struct interior_const_type<mapbox::geometry::polygon<CoordinateType>> | |
{ | |
using type = interior_wrapper<mapbox::geometry::polygon<CoordinateType> const>; | |
}; | |
template <typename CoordinateType> | |
struct exterior_ring<mapbox::geometry::polygon<CoordinateType>> | |
{ | |
static auto& get(mapbox::geometry::polygon<CoordinateType>& p) | |
{ | |
return p.at(0); | |
} | |
static auto const& get(mapbox::geometry::polygon<CoordinateType> const& p) | |
{ | |
return p.at(0); | |
} | |
}; | |
template <typename CoordinateType> | |
struct interior_rings<mapbox::geometry::polygon<CoordinateType> > | |
{ | |
static auto get(mapbox::geometry::polygon<CoordinateType>& p) | |
{ | |
return interior_wrapper<mapbox::geometry::polygon<CoordinateType>>(p); | |
} | |
static auto get(mapbox::geometry::polygon<CoordinateType> const& p) | |
{ | |
return interior_wrapper<mapbox::geometry::polygon<CoordinateType> const>(p); | |
} | |
}; | |
} | |
} | |
} | |
void testBoost() { | |
mapbox::geometry::polygon<double> a; | |
mapbox::geometry::polygon<double> b; | |
std::vector<mapbox::geometry::polygon<double>> result; | |
boost::geometry::intersection(a, b, result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment