Skip to content

Instantly share code, notes, and snippets.

@jfirebaugh
Created June 28, 2016 14:40
Show Gist options
  • Save jfirebaugh/fceec9050a403e359180d9e323c42624 to your computer and use it in GitHub Desktop.
Save jfirebaugh/fceec9050a403e359180d9e323c42624 to your computer and use it in GitHub Desktop.
#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>
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 = boost::iterator_range<typename mapbox::geometry::polygon<CoordinateType>::iterator>;
};
template <typename CoordinateType>
struct interior_const_type<mapbox::geometry::polygon<CoordinateType>>
{
using type = boost::iterator_range<typename mapbox::geometry::polygon<CoordinateType>::const_iterator>;
};
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 boost::make_iterator_range(p.begin() + 1, p.end());
}
static auto get(mapbox::geometry::polygon<CoordinateType> const& p)
{
return boost::make_iterator_range(p.begin() + 1, p.end());
}
};
}
}
}
void testBoost() {
mapbox::geometry::polygon<double> a;
mapbox::geometry::polygon<double> b;
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