Added Boost.Polygon support (point, box, ring)

[SVN r67042]
This commit is contained in:
Barend Gehrels
2010-12-05 21:47:08 +00:00
parent a9dac9f234
commit 92cecaa0f5
4 changed files with 357 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_BOX_HPP
#define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_BOX_HPP
#include <cstddef>
#include <boost/polygon/polygon.hpp>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/polygon/polygon.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
namespace traits
{
template <typename CoordinateType>
struct tag<boost::polygon::rectangle_data<CoordinateType> >
{
typedef box_tag type;
};
template <typename CoordinateType>
struct point_type<boost::polygon::rectangle_data<CoordinateType> >
{
// Not sure what to do here. Boost.Polygon's rectangle does NOT define its
// point_type (but uses it...)
typedef boost::polygon::point_data<CoordinateType> type;
};
template <typename CoordinateType>
struct indexed_access<boost::polygon::rectangle_data<CoordinateType>, min_corner, 0>
{
static inline CoordinateType get(boost::polygon::rectangle_data<CoordinateType> const& b)
{
return boost::polygon::xl(b);
}
static inline void set(boost::polygon::rectangle_data<CoordinateType>& b, CoordinateType const& value)
{
boost::polygon::xl(b, value);
}
};
template <typename CoordinateType>
struct indexed_access<boost::polygon::rectangle_data<CoordinateType>, min_corner, 1>
{
static inline CoordinateType get(boost::polygon::rectangle_data<CoordinateType> const& b)
{
return boost::polygon::yl(b);
}
static inline void set(boost::polygon::rectangle_data<CoordinateType>& b, CoordinateType const& value)
{
boost::polygon::yl(b, value);
}
};
template <typename CoordinateType>
struct indexed_access<boost::polygon::rectangle_data<CoordinateType>, max_corner, 0>
{
static inline CoordinateType get(boost::polygon::rectangle_data<CoordinateType> const& b)
{
return boost::polygon::xh(b);
}
static inline void set(boost::polygon::rectangle_data<CoordinateType>& b, CoordinateType const& value)
{
boost::polygon::xh(b, value);
}
};
template <typename CoordinateType>
struct indexed_access<boost::polygon::rectangle_data<CoordinateType>, max_corner, 1>
{
static inline CoordinateType get(boost::polygon::rectangle_data<CoordinateType> const& b)
{
return boost::polygon::yh(b);
}
static inline void set(boost::polygon::rectangle_data<CoordinateType>& b, CoordinateType const& value)
{
boost::polygon::yh(b, value);
}
};
} // namespace traits
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_BOX_HPP

View File

@@ -0,0 +1,97 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_POINT_HPP
#define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_POINT_HPP
#include <cstddef>
#include <boost/polygon/polygon.hpp>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/polygon/polygon.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
namespace traits
{
// Assign the point-tag, preventing arrays of points getting a point-tag
template <typename CoordinateType>
struct tag<boost::polygon::point_data<CoordinateType> >
{
typedef point_tag type;
};
template <typename CoordinateType>
struct coordinate_type<boost::polygon::point_data<CoordinateType> >
{
typedef CoordinateType type;
};
template <typename CoordinateType>
struct coordinate_system<boost::polygon::point_data<CoordinateType> >
{
typedef cs::cartesian type;
};
template <typename CoordinateType>
struct dimension<boost::polygon::point_data<CoordinateType> >: boost::mpl::int_<2> {};
template <typename CoordinateType>
struct access<boost::polygon::point_data<CoordinateType>, 0>
{
static inline CoordinateType get(boost::polygon::point_data<CoordinateType> const& p)
{
return p.x();
}
static inline void set(boost::polygon::point_data<CoordinateType>& p,
CoordinateType const& value)
{
p.x(value);
}
};
template <typename CoordinateType>
struct access<boost::polygon::point_data<CoordinateType>, 1>
{
static inline CoordinateType get(boost::polygon::point_data<CoordinateType> const& p)
{
return p.y();
}
static inline void set(boost::polygon::point_data<CoordinateType>& p,
CoordinateType const& value)
{
p.y(value);
}
};
} // namespace traits
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_POINT_HPP

View File

@@ -0,0 +1,145 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP
#define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP
// Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
#include <cstddef>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/polygon/polygon.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
namespace traits
{
template <typename CoordinateType>
struct tag<boost::polygon::polygon_data<CoordinateType> >
{
typedef ring_tag type;
};
} // namespace traits
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
// ----------------------------------------------------------------------------
// Boost.Polygon's polygon is not Boost.Range compatible so we have to add support here
// 1. range_value<...>::type
// 2. iterators
// ----------------------------------------------------------------------------
// range_value<...>::type -> avoid this to provide direct support within Boost.Geometry
namespace core_dispatch
{
template <typename CoordinateType>
struct point_type<ring_tag, boost::polygon::polygon_data<CoordinateType> >
{
typedef typename boost::polygon::polygon_traits
<
boost::polygon::polygon_data<CoordinateType>
>::point_type type;
};
} // namespace core_dispatch
}} // namespace boost::geometry
// 2. iterators, adapt Boost.Polygon to Boost.Range
namespace boost
{
template<typename CoordinateType>
struct range_iterator<boost::polygon::polygon_data<CoordinateType> >
{
typedef typename boost::polygon::polygon_traits
<
boost::polygon::polygon_data<CoordinateType>
>::iterator_type type;
};
template<typename CoordinateType>
struct range_const_iterator<boost::polygon::polygon_data<CoordinateType> >
{
typedef typename boost::polygon::polygon_traits
<
boost::polygon::polygon_data<CoordinateType>
>::iterator_type type;
};
// RangeEx
template<typename CoordinateType>
struct range_size<boost::polygon::polygon_data<CoordinateType> >
{
typedef std::size_t type;
};
} // namespace 'boost'
// 2b. free-standing function for Boost.Range ADP
template<typename CoordinateType>
inline typename boost::polygon::polygon_traits
<
boost::polygon::polygon_data<CoordinateType>
>::iterator_type range_begin(boost::polygon::polygon_data<CoordinateType>& polygon)
{
return polygon.begin();
}
template<typename CoordinateType>
inline typename boost::polygon::polygon_traits
<
boost::polygon::polygon_data<CoordinateType>
>::iterator_type range_begin(boost::polygon::polygon_data<CoordinateType> const& polygon)
{
return polygon.begin();
}
template<typename CoordinateType>
inline typename boost::polygon::polygon_traits
<
boost::polygon::polygon_data<CoordinateType>
>::iterator_type range_end(boost::polygon::polygon_data<CoordinateType>& polygon)
{
return polygon.end();
}
template<typename CoordinateType>
inline typename boost::polygon::polygon_traits
<
boost::polygon::polygon_data<CoordinateType>
>::iterator_type range_end(boost::polygon::polygon_data<CoordinateType> const& polygon)
{
return polygon.end();
}
// RangeEx
template<typename CoordinateType>
inline std::size_t range_size(boost::polygon::polygon_data<CoordinateType> const& polygon)
{
return polygon.size();
}
#endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP

View File

@@ -23,6 +23,8 @@
#include <list>
#include <utility>
#include <boost/geometry/core/tags.hpp>
namespace boost { namespace geometry
{