implement different strategy for adapting to boost::geometry using internal structure for accessing interior rings

This commit is contained in:
artemp 2016-07-06 17:43:45 +01:00
parent 710a9be5b0
commit c478849eba
4 changed files with 75 additions and 115 deletions

View file

@ -24,12 +24,19 @@
#define MAPNIK_GEOMETRY_MULTI_POLYGON_HPP #define MAPNIK_GEOMETRY_MULTI_POLYGON_HPP
// geometry // geometry
#include <mapbox/geometry/multi_polygon.hpp> #include <mapnik/geometry/polygon.hpp>
namespace mapnik { namespace geometry { namespace mapnik { namespace geometry {
template <typename T> template <typename T, template <typename...> class Cont = std::vector>
using multi_polygon = mapbox::geometry::multi_polygon<T>; struct multi_polygon : Cont<polygon<T>>
{
using coordinate_type = T;
using polygon_type = polygon<T>;
using container_type = Cont<polygon_type>;
using container_type::container_type;
};
}} }}

View file

@ -26,48 +26,82 @@
// geometry // geometry
#include <mapbox/geometry/polygon.hpp> #include <mapbox/geometry/polygon.hpp>
// stl
//#include <vector>
namespace mapnik { namespace geometry { namespace mapnik { namespace geometry {
template <typename T> template <typename T>
using linear_ring = mapbox::geometry::linear_ring<T>; using linear_ring = mapbox::geometry::linear_ring<T>;
template <typename T> template <typename T>
using polygon = mapbox::geometry::polygon<T>; struct polygon : mapbox::geometry::polygon<T>
/*
template <typename T>
using rings_container = std::vector<linear_ring<T>>;
template <typename T, template <typename> class InteriorRings = rings_container>
struct polygon
{ {
using coordinate_type = T; using coordinate_type = T;
using rings_container = InteriorRings<coordinate_type>; using base_type = mapbox::geometry::polygon<T>;
linear_ring<T> exterior_ring; using linear_ring_type = linear_ring<T>;
rings_container interior_rings; struct interior_rings
inline void set_exterior_ring(linear_ring<T> && ring)
{ {
exterior_ring = std::move(ring); using iterator = typename base_type::iterator;
using const_iterator = typename base_type::const_iterator;
using value_type = typename base_type::value_type;
interior_rings(polygon<coordinate_type> & poly)
: poly_(poly) {}
iterator begin()
{
auto itr = poly_.begin();
std::advance(itr, 1);
return itr;
}
iterator end() { return poly_.end();}
const_iterator begin() const
{
auto itr = poly_.begin();
std::advance(itr, 1);
return itr;
}
const_iterator end() const { return poly_.end();}
void clear()
{
poly_.resize(1);
}
void resize(std::size_t size)
{
poly_.resize(size + 1);
}
std::size_t size() const
{
return poly_.empty() ? 0 : poly_.size() - 1;
}
void push_back(value_type const& val) { poly_.push_back(val); }
value_type& back() { return poly_.back(); }
value_type const& back() const { return poly_.back(); }
polygon<coordinate_type> & poly_;
};
polygon()
: base_type(),
interior_(*this)
{
//this->resize(1); // explicit exterior ring ?
} }
inline void add_hole(linear_ring<T> && ring) polygon(polygon const& other)
{ : base_type(other),
interior_rings.emplace_back(std::move(ring)); interior_(*this) {}
}
inline bool empty() const { return exterior_ring.empty(); } interior_rings const& interior() const
inline std::size_t num_rings() const
{ {
return 1 + interior_rings.size(); return interior_;
} }
interior_rings & interior()
{
return interior_;
}
interior_rings interior_;
}; };
*/
}} }}

View file

@ -41,7 +41,6 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/coord.hpp> #include <mapnik/coord.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/polygon_interior.hpp>
#include <cstdint> #include <cstdint>
// register point // register point
@ -177,13 +176,13 @@ struct ring_mutable_type<mapnik::geometry::polygon<CoordinateType> >
template <typename CoordinateType> template <typename CoordinateType>
struct interior_const_type<mapnik::geometry::polygon<CoordinateType> > struct interior_const_type<mapnik::geometry::polygon<CoordinateType> >
{ {
using type = boost::iterator_range<typename mapbox::geometry::polygon<CoordinateType>::const_iterator> const; using type = typename mapnik::geometry::polygon<CoordinateType>::interior_rings const&;
}; };
template <typename CoordinateType> template <typename CoordinateType>
struct interior_mutable_type<mapnik::geometry::polygon<CoordinateType> > struct interior_mutable_type<mapnik::geometry::polygon<CoordinateType> >
{ {
using type = mapnik::detail::polygon_interior<CoordinateType>; using type = typename mapnik::geometry::polygon<CoordinateType>::interior_rings& ;
}; };
// exterior // exterior
@ -213,14 +212,13 @@ struct interior_rings<mapnik::geometry::polygon<CoordinateType> >
static interior_const_type get(mapnik::geometry::polygon<CoordinateType> const& p) static interior_const_type get(mapnik::geometry::polygon<CoordinateType> const& p)
{ {
return boost::make_iterator_range(p.begin() + 1, p.end()); return p.interior();
} }
static interior_mutable_type get(mapnik::geometry::polygon<CoordinateType>& p) static interior_mutable_type get(mapnik::geometry::polygon<CoordinateType>& p)
{ {
return mapnik::detail::polygon_interior<CoordinateType>(p); return p.interior();
} }
}; };
}}} }}}

View file

@ -1,79 +0,0 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2016 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_POLYGON_INTERIOR_HPP
#define MAPNIK_POLYGON_INTERIOR_HPP
#include <mapnik/geometry/polygon.hpp>
namespace mapnik { namespace detail {
template <typename T>
struct polygon_interior
{
using coordinate_type = T;
using iterator = typename geometry::polygon<coordinate_type>::iterator;
using const_iterator = typename geometry::polygon<coordinate_type>::const_iterator;
using value_type = typename geometry::polygon<coordinate_type>::value_type;
polygon_interior(geometry::polygon<coordinate_type> & poly)
: poly_(poly) {}
iterator begin()
{
auto itr = poly_.begin();
std::advance(itr, 1);
return itr;
}
iterator end() { return poly_.end();}
const_iterator begin() const
{
auto itr = poly_.begin();
std::advance(itr, 1);
return itr;
}
const_iterator end() const { return poly_.end();}
void clear()
{
poly_.resize(1);
}
void resize(std::size_t size)
{
poly_.resize(size + 1);
}
std::size_t size() const
{
return poly_.empty() ? 0 : poly_.size() - 1;
}
value_type& back() { return poly_.back(); }
value_type const& back() const { return poly_.back(); }
geometry::polygon<coordinate_type> & poly_;
};
}}
#endif // MAPNIK_POLYGON_INTERIOR_HPP