Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@16: // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP Chris@16: #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP Chris@16: Chris@16: // Adapts Geometries from Boost.Polygon for usage in Boost.Geometry Chris@16: // boost::polygon::polygon_data -> boost::geometry::ring Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: namespace traits Chris@16: { Chris@16: Chris@16: template Chris@16: struct tag > Chris@16: { Chris@16: typedef ring_tag type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct clear > Chris@16: { Chris@16: static inline void apply(boost::polygon::polygon_data& data) Chris@16: { Chris@16: // There is no "clear" function but we can assign Chris@16: // a newly (and therefore empty) constructed polygon Chris@16: boost::polygon::assign(data, boost::polygon::polygon_data()); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct push_back > Chris@16: { Chris@16: typedef boost::polygon::point_data point_type; Chris@16: Chris@16: static inline void apply(boost::polygon::polygon_data& data, Chris@16: point_type const& point) Chris@16: { Chris@16: // Boost.Polygon's polygons are not appendable. So create a temporary vector, Chris@16: // add a record and set it to the original. Of course: this is not efficient. Chris@16: // But there seems no other way (without using a wrapper) Chris@16: std::vector temporary_vector Chris@16: ( Chris@16: boost::polygon::begin_points(data), Chris@16: boost::polygon::end_points(data) Chris@16: ); Chris@16: temporary_vector.push_back(point); Chris@16: data.set(temporary_vector.begin(), temporary_vector.end()); Chris@16: } Chris@16: }; Chris@16: Chris@101: template Chris@101: struct resize > Chris@101: { Chris@101: typedef boost::polygon::point_data point_type; Chris@16: Chris@101: static inline void apply(boost::polygon::polygon_data& data, Chris@101: std::size_t new_size) Chris@101: { Chris@101: // Boost.Polygon's polygons are not resizable. So create a temporary vector, Chris@101: // resize it and set it to the original. Of course: this is not efficient. Chris@101: // But there seems no other way (without using a wrapper) Chris@101: std::vector temporary_vector Chris@101: ( Chris@101: boost::polygon::begin_points(data), Chris@101: boost::polygon::end_points(data) Chris@101: ); Chris@101: temporary_vector.resize(new_size); Chris@101: data.set(temporary_vector.begin(), temporary_vector.end()); Chris@101: } Chris@101: }; Chris@16: Chris@16: Chris@16: } // namespace traits Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: Chris@16: // Adapt Boost.Polygon's polygon_data to Boost.Range Chris@16: // This just translates to Chris@16: // polygon_data.begin() and polygon_data.end() Chris@16: namespace boost Chris@16: { Chris@16: template Chris@16: struct range_mutable_iterator > Chris@16: { Chris@16: typedef typename boost::polygon::polygon_traits Chris@16: < Chris@16: boost::polygon::polygon_data Chris@16: >::iterator_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct range_const_iterator > Chris@16: { Chris@16: typedef typename boost::polygon::polygon_traits Chris@16: < Chris@16: boost::polygon::polygon_data Chris@16: >::iterator_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct range_size > Chris@16: { Chris@16: typedef std::size_t type; Chris@16: }; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: // Support Boost.Polygon's polygon_data for Boost.Range ADP Chris@16: namespace boost { namespace polygon Chris@16: { Chris@16: Chris@16: template Chris@16: inline typename polygon_traits Chris@16: < Chris@16: polygon_data Chris@16: >::iterator_type range_begin(polygon_data& polygon) Chris@16: { Chris@16: return polygon.begin(); Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename polygon_traits Chris@16: < Chris@16: polygon_data Chris@16: >::iterator_type range_begin(polygon_data const& polygon) Chris@16: { Chris@16: return polygon.begin(); Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename polygon_traits Chris@16: < Chris@16: polygon_data Chris@16: >::iterator_type range_end(polygon_data& polygon) Chris@16: { Chris@16: return polygon.end(); Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename polygon_traits Chris@16: < Chris@16: polygon_data Chris@16: >::iterator_type range_end(polygon_data const& polygon) Chris@16: { Chris@16: return polygon.end(); Chris@16: } Chris@16: Chris@16: template Chris@16: inline std::size_t range_calculate_size(polygon_data const& polygon) Chris@16: { Chris@16: return polygon.size(); Chris@16: } Chris@16: Chris@16: }} Chris@16: Chris@16: #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS Chris@16: Chris@16: Chris@16: #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP