From 92cecaa0f51bcbf8401ccfd58468fd2760a88703 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Sun, 5 Dec 2010 21:47:08 +0000 Subject: [PATCH] Added Boost.Polygon support (point, box, ring) [SVN r67042] --- .../geometries/adapted/boost_polygon_box.hpp | 113 ++++++++++++++ .../adapted/boost_polygon_point.hpp | 97 ++++++++++++ .../geometries/adapted/boost_polygon_ring.hpp | 145 ++++++++++++++++++ .../geometries/adapted/std_as_ring.hpp | 2 + 4 files changed, 357 insertions(+) create mode 100644 include/boost/geometry/geometries/adapted/boost_polygon_box.hpp create mode 100644 include/boost/geometry/geometries/adapted/boost_polygon_point.hpp create mode 100644 include/boost/geometry/geometries/adapted/boost_polygon_ring.hpp diff --git a/include/boost/geometry/geometries/adapted/boost_polygon_box.hpp b/include/boost/geometry/geometries/adapted/boost_polygon_box.hpp new file mode 100644 index 000000000..4f7ad864c --- /dev/null +++ b/include/boost/geometry/geometries/adapted/boost_polygon_box.hpp @@ -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 + +#include + +#include +#include +#include +#include +#include + +#include + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS +namespace traits +{ + + + +template +struct tag > +{ + typedef box_tag type; +}; + +template +struct point_type > +{ + // Not sure what to do here. Boost.Polygon's rectangle does NOT define its + // point_type (but uses it...) + typedef boost::polygon::point_data type; +}; + +template +struct indexed_access, min_corner, 0> +{ + static inline CoordinateType get(boost::polygon::rectangle_data const& b) + { + return boost::polygon::xl(b); + } + + static inline void set(boost::polygon::rectangle_data& b, CoordinateType const& value) + { + boost::polygon::xl(b, value); + } +}; + + +template +struct indexed_access, min_corner, 1> +{ + static inline CoordinateType get(boost::polygon::rectangle_data const& b) + { + return boost::polygon::yl(b); + } + + static inline void set(boost::polygon::rectangle_data& b, CoordinateType const& value) + { + boost::polygon::yl(b, value); + } +}; + +template +struct indexed_access, max_corner, 0> +{ + static inline CoordinateType get(boost::polygon::rectangle_data const& b) + { + return boost::polygon::xh(b); + } + + static inline void set(boost::polygon::rectangle_data& b, CoordinateType const& value) + { + boost::polygon::xh(b, value); + } +}; + +template +struct indexed_access, max_corner, 1> +{ + static inline CoordinateType get(boost::polygon::rectangle_data const& b) + { + return boost::polygon::yh(b); + } + + static inline void set(boost::polygon::rectangle_data& 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 + diff --git a/include/boost/geometry/geometries/adapted/boost_polygon_point.hpp b/include/boost/geometry/geometries/adapted/boost_polygon_point.hpp new file mode 100644 index 000000000..56984f3f6 --- /dev/null +++ b/include/boost/geometry/geometries/adapted/boost_polygon_point.hpp @@ -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 + +#include + +#include +#include +#include +#include +#include + +#include + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS +namespace traits +{ + + + +// Assign the point-tag, preventing arrays of points getting a point-tag +template +struct tag > +{ + typedef point_tag type; +}; + + +template +struct coordinate_type > +{ + typedef CoordinateType type; +}; + +template +struct coordinate_system > +{ + typedef cs::cartesian type; +}; + + +template +struct dimension >: boost::mpl::int_<2> {}; + + +template +struct access, 0> +{ + static inline CoordinateType get(boost::polygon::point_data const& p) + { + return p.x(); + } + + static inline void set(boost::polygon::point_data& p, + CoordinateType const& value) + { + p.x(value); + } +}; + +template +struct access, 1> +{ + static inline CoordinateType get(boost::polygon::point_data const& p) + { + return p.y(); + } + + static inline void set(boost::polygon::point_data& 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 + diff --git a/include/boost/geometry/geometries/adapted/boost_polygon_ring.hpp b/include/boost/geometry/geometries/adapted/boost_polygon_ring.hpp new file mode 100644 index 000000000..7d544e42c --- /dev/null +++ b/include/boost/geometry/geometries/adapted/boost_polygon_ring.hpp @@ -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 + + +#include +#include +#include +#include +#include + +#include + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS +namespace traits +{ + +template +struct tag > +{ + 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 +struct point_type > +{ + typedef typename boost::polygon::polygon_traits + < + boost::polygon::polygon_data + >::point_type type; +}; + +} // namespace core_dispatch + + +}} // namespace boost::geometry + + +// 2. iterators, adapt Boost.Polygon to Boost.Range +namespace boost +{ + template + struct range_iterator > + { + typedef typename boost::polygon::polygon_traits + < + boost::polygon::polygon_data + >::iterator_type type; + }; + + template + struct range_const_iterator > + { + typedef typename boost::polygon::polygon_traits + < + boost::polygon::polygon_data + >::iterator_type type; + }; + + // RangeEx + template + struct range_size > + { + typedef std::size_t type; + }; + +} // namespace 'boost' + + +// 2b. free-standing function for Boost.Range ADP +template +inline typename boost::polygon::polygon_traits + < + boost::polygon::polygon_data + >::iterator_type range_begin(boost::polygon::polygon_data& polygon) +{ + return polygon.begin(); +} + +template +inline typename boost::polygon::polygon_traits + < + boost::polygon::polygon_data + >::iterator_type range_begin(boost::polygon::polygon_data const& polygon) +{ + return polygon.begin(); +} + +template +inline typename boost::polygon::polygon_traits + < + boost::polygon::polygon_data + >::iterator_type range_end(boost::polygon::polygon_data& polygon) +{ + return polygon.end(); +} + +template +inline typename boost::polygon::polygon_traits + < + boost::polygon::polygon_data + >::iterator_type range_end(boost::polygon::polygon_data const& polygon) +{ + return polygon.end(); +} + +// RangeEx +template +inline std::size_t range_size(boost::polygon::polygon_data const& polygon) +{ + return polygon.size(); +} + + +#endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP + diff --git a/include/boost/geometry/geometries/adapted/std_as_ring.hpp b/include/boost/geometry/geometries/adapted/std_as_ring.hpp index 1aa61dac8..2dfc4cf8b 100644 --- a/include/boost/geometry/geometries/adapted/std_as_ring.hpp +++ b/include/boost/geometry/geometries/adapted/std_as_ring.hpp @@ -23,6 +23,8 @@ #include #include +#include + namespace boost { namespace geometry {