make all mapnik::geometries aliases to mapbox::geometry and attempt to adapt new polygon model (one std::vector)

NOTE: some boost.geometry algorithms are broken as a result
This commit is contained in:
artemp 2016-06-29 12:37:32 +01:00
parent 71496e7828
commit efabcc8081
42 changed files with 477 additions and 508 deletions

View file

@ -35,7 +35,7 @@ benchmarks = [
#"test_to_double.cpp",
#"test_to_int.cpp",
#"test_utf_encoding.cpp"
"test_polygon_clipping.cpp",
#"test_polygon_clipping.cpp",
#"test_polygon_clipping_rendering.cpp",
"test_proj_transform1.cpp",
"test_expression_parse.cpp",

View file

@ -128,7 +128,7 @@ public:
}
ring.emplace_back(x,y);
}
poly2.set_exterior_ring(std::move(ring));
poly2.push_back(std::move(ring));
// interior rings
ring.clear();
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END)
@ -140,7 +140,7 @@ public:
else if (cmd == mapnik::SEG_CLOSE)
{
ring.emplace_back(x0,y0);
poly2.add_hole(std::move(ring));
poly2.push_back(std::move(ring));
ring.clear();
continue;
}
@ -520,7 +520,7 @@ int main(int argc, char** argv)
// RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106))
// OUT (expected)
// POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))
#if 0
mapnik::box2d<double> clipping_box(181,106,631,470);
std::string filename_("./benchmark/data/polygon.wkt");
std::ifstream in(filename_.c_str(),std::ios_base::in | std::ios_base::binary);
@ -543,5 +543,6 @@ int main(int argc, char** argv)
return_value = return_value | run(test_runner,"clipping polygon with clipper_tree");
}
*/
return return_value;
#endif
return 0;// return_value;
}

View file

@ -23,18 +23,13 @@
#ifndef MAPNIK_GEOMETRY_MULTI_LINE_STRING_HPP
#define MAPNIK_GEOMETRY_MULTI_LINE_STRING_HPP
// mapnik
#include <mapnik/geometry/line_string.hpp>
// stl
#include <vector>
// geometry
#include <mapbox/geometry/multi_line_string.hpp>
namespace mapnik { namespace geometry {
template <typename T, template <typename...> class Cont = std::vector>
struct multi_line_string : Cont<line_string<T>>
{
using coordinate_type = T;
};
template <typename T>
using multi_line_string = mapbox::geometry::multi_line_string<T>;
}}

View file

@ -23,25 +23,13 @@
#ifndef MAPNIK_GEOMETRY_MULTI_POINT_HPP
#define MAPNIK_GEOMETRY_MULTI_POINT_HPP
// mapnik
#include <mapnik/geometry/point.hpp>
// stl
#include <vector>
// geometry
#include <mapbox/geometry/multi_point.hpp>
namespace mapnik { namespace geometry {
template <typename T, template <typename...> class Cont = std::vector>
struct multi_point : Cont<point<T>>
{
using coordinate_type = T;
using point_type = point<coordinate_type>;
using container_type = Cont<point_type>;
multi_point() = default;
explicit multi_point(std::size_t size)
: container_type(size) {}
inline std::size_t num_points() const { return container_type::size(); }
inline void add_coord(T x, T y) { container_type::template emplace_back(x, y);}
};
template <typename T>
using multi_point = mapbox::geometry::multi_point<T>;
}}

View file

@ -23,18 +23,13 @@
#ifndef MAPNIK_GEOMETRY_MULTI_POLYGON_HPP
#define MAPNIK_GEOMETRY_MULTI_POLYGON_HPP
// mapnik
#include <mapnik/geometry/polygon.hpp>
// stl
#include <vector>
// geometry
#include <mapbox/geometry/multi_polygon.hpp>
namespace mapnik { namespace geometry {
template <typename T, template <typename...> class Cont = std::vector>
struct multi_polygon : Cont<polygon<T>>
{
using coordinate_type = T;
};
template <typename T>
using multi_polygon = mapbox::geometry::multi_polygon<T>;
}}

View file

@ -27,13 +27,18 @@
#include <mapbox/geometry/polygon.hpp>
// stl
#include <vector>
//#include <vector>
namespace mapnik { namespace geometry {
template <typename T>
using linear_ring = mapbox::geometry::linear_ring<T>;
template <typename T>
using polygon = mapbox::geometry::polygon<T>;
/*
template <typename T>
using rings_container = std::vector<linear_ring<T>>;
@ -62,6 +67,7 @@ struct polygon
return 1 + interior_rings.size();
}
};
*/
}}

View file

@ -37,7 +37,7 @@
// and once we do that the compile time is == to just including boost/geometry.hpp
#include <boost/geometry.hpp>
#pragma GCC diagnostic pop
#include <boost/range/iterator_range_core.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/coord.hpp>
#include <mapnik/box2d.hpp>
@ -82,7 +82,9 @@ template <typename CoordinateType>
inline typename mapnik::geometry::line_string<CoordinateType>::const_iterator
range_end(mapnik::geometry::line_string<CoordinateType> const& line) {return line.end();}
namespace geometry { namespace traits {
namespace geometry {
namespace traits {
// register mapnik::box2d<double>
template<> struct tag<mapnik::box2d<double> > { using type = box_tag; };
@ -175,13 +177,13 @@ struct ring_mutable_type<mapnik::geometry::polygon<CoordinateType> >
template <typename CoordinateType>
struct interior_const_type<mapnik::geometry::polygon<CoordinateType> >
{
using type = typename mapnik::geometry::polygon<CoordinateType>::rings_container const&;
using type = boost::iterator_range<typename mapbox::geometry::polygon<CoordinateType>::const_iterator>;
};
template <typename CoordinateType>
struct interior_mutable_type<mapnik::geometry::polygon<CoordinateType> >
{
using type = typename mapnik::geometry::polygon<CoordinateType>::rings_container&;
using type = boost::iterator_range<typename mapbox::geometry::polygon<CoordinateType>::iterator>;
};
// exterior
@ -190,27 +192,33 @@ struct exterior_ring<mapnik::geometry::polygon<CoordinateType> >
{
static mapnik::geometry::linear_ring<CoordinateType> & get(mapnik::geometry::polygon<CoordinateType> & p)
{
return p.exterior_ring;
if (p.empty()) p.emplace_back();
return p.at(0);
}
static mapnik::geometry::linear_ring<CoordinateType> const& get(mapnik::geometry::polygon<CoordinateType> const& p)
{
return p.exterior_ring;
return p.at(0);
}
};
template <typename CoordinateType>
struct interior_rings<mapnik::geometry::polygon<CoordinateType> >
{
using holes_type = typename mapnik::geometry::polygon<CoordinateType>::rings_container;
static holes_type& get(mapnik::geometry::polygon<CoordinateType> & p)
using ring_iterator = typename mapbox::geometry::polygon<CoordinateType>::iterator;
using const_ring_iterator = typename mapbox::geometry::polygon<CoordinateType>::const_iterator;
using holes_type = boost::iterator_range<ring_iterator>;
using const_holes_type = boost::iterator_range<const_ring_iterator>;
static holes_type get(mapnik::geometry::polygon<CoordinateType> & p)
// -> decltype(boost::make_iterator_range(p.begin() + 1, p.end()))
{
return p.interior_rings;
return boost::make_iterator_range(p.begin() + 1, p.end());
}
static holes_type const& get(mapnik::geometry::polygon<CoordinateType> const& p)
static const_holes_type get(mapnik::geometry::polygon<CoordinateType> const& p)
// -> decltype(boost::make_iterator_range(p.begin() + 1, p.end())) const
{
return p.interior_rings;
return boost::make_iterator_range(p.begin() + 1, p.end());
}
};

View file

@ -67,7 +67,7 @@ struct geometry_envelope
void operator() (mapnik::geometry::polygon<T> const& poly) const
{
_envelope_impl(poly.exterior_ring, bbox);
if (!poly.empty()) _envelope_impl(poly[0], bbox);
}
void operator() (mapnik::geometry::multi_point<T> const& multi_point) const

View file

@ -39,14 +39,14 @@ BOOST_FUSION_ADAPT_STRUCT(
(std::int64_t, y)
)
BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::polygon<double>,
(mapnik::geometry::linear_ring<double> const&, exterior_ring)
(mapnik::geometry::polygon<double>::rings_container const& , interior_rings))
//BOOST_FUSION_ADAPT_STRUCT(
// mapnik::geometry::polygon<double>,
// (mapnik::geometry::linear_ring<double> const&, exterior_ring)
// (mapnik::geometry::polygon<double>::rings_container const& , interior_rings))
BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::polygon<std::int64_t>,
(mapnik::geometry::linear_ring<std::int64_t> const&, exterior_ring)
(mapnik::geometry::polygon<std::int64_t>::rings_container const& , interior_rings))
//BOOST_FUSION_ADAPT_STRUCT(
// mapnik::geometry::polygon<std::int64_t>,
// (mapnik::geometry::linear_ring<std::int64_t> const&, exterior_ring)
// (mapnik::geometry::polygon<std::int64_t>::rings_container const& , interior_rings))
#endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP

View file

@ -47,6 +47,11 @@ struct geometry_is_empty
return geom.empty();
}
bool operator() (mapnik::geometry::linear_ring<T> const& geom) const
{
return geom.empty();
}
bool operator() (mapnik::geometry::polygon<T> const& geom) const
{
return geom.empty();
@ -103,6 +108,11 @@ struct geometry_has_empty
return false;
}
bool operator() (mapnik::geometry::linear_ring<T> const&) const
{
return false;
}
bool operator() (mapnik::geometry::polygon<T> const&) const
{
return false;

View file

@ -20,8 +20,7 @@
*
*****************************************************************************/
// mapnik
#include <mapnik/geometry_reprojection.hpp>
// mapnik <mapnik/geometry_reprojection.hpp>
#include <mapnik/geometry.hpp>
namespace mapnik {
@ -63,31 +62,22 @@ template <typename T>
polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj_trans, unsigned int & n_err)
{
polygon<T> new_poly;
linear_ring<T> new_ext(poly.exterior_ring);
unsigned int err = proj_trans.forward(new_ext);
// If the exterior ring doesn't transform don't bother with the holes.
if (err > 0 || new_ext.empty())
{
n_err += err;
}
else
{
new_poly.set_exterior_ring(std::move(new_ext));
new_poly.interior_rings.reserve(poly.interior_rings.size());
for (auto const& lr : poly.interior_rings)
new_poly.reserve(poly.size());
bool exterior = true;
for (auto const& lr : poly)
{
linear_ring<T> new_lr(lr);
err = proj_trans.forward(new_lr);
unsigned int err = proj_trans.forward(new_lr);
if (err > 0 || new_lr.empty())
{
n_err += err;
// If there is an error in interior ring drop
// it from polygon.
continue;
}
new_poly.add_hole(std::move(new_lr));
if (!exterior) continue;
}
if (exterior) exterior = false;
new_poly.push_back(std::move(new_lr));
}
return new_poly;
}
@ -146,7 +136,7 @@ multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transfo
for (auto const& poly : mpoly)
{
polygon<T> new_poly = reproject_internal(poly, proj_trans, n_err);
if (!new_poly.exterior_ring.empty())
if (new_poly.size() > 0 && !new_poly[0].empty())
{
new_mpoly.emplace_back(std::move(new_poly));
}
@ -208,7 +198,7 @@ struct geom_reproj_copy_visitor
{
geometry<T> geom; // default empty
polygon<T> new_poly = reproject_internal(poly, proj_trans_, n_err_);
if (new_poly.exterior_ring.empty()) return geom;
if (new_poly.size() == 0 || new_poly[0].size() == 0) return geom;
geom = std::move(new_poly);
return geom;
}
@ -316,12 +306,7 @@ struct geom_reproj_visitor {
template <typename T>
bool operator() (polygon<T> & poly) const
{
if (proj_trans_.forward(poly.exterior_ring) > 0)
{
return false;
}
for (auto & lr : poly.interior_rings)
for (auto & lr : poly)
{
if (proj_trans_.forward(lr) > 0)
{

View file

@ -67,9 +67,11 @@ struct geometry_to_path
// polygon
void operator() (polygon<T> const& poly) const
{
// exterior
// rings: exterior *interior
for (auto const& ring : poly)
{
bool first = true;
for (auto const& pt : poly.exterior_ring)
for (auto const& pt : ring)
{
if (first)
{
@ -85,25 +87,6 @@ struct geometry_to_path
{
p_.close_path();
}
// interior
for (auto const& ring : poly.interior_rings)
{
first = true;
for (auto const& pt : ring)
{
if (first) {
p_.move_to(pt.x, pt.y);
first=false;
}
else
{
p_.line_to(pt.x, pt.y);
}
}
if (!first)
{
p_.close_path();
}
}
}

View file

@ -89,31 +89,37 @@ struct hit_test_visitor
}
return false;
}
bool operator() (geometry::polygon<double> const& geom) const
bool operator() (geometry::polygon<double> const& poly) const
{
auto const& exterior = geom.exterior_ring;
std::size_t num_points = exterior.size();
if (num_points < 4) return false;
bool inside = false;
for (std::size_t i = 1; i < num_points; ++i)
{
auto const& pt0 = exterior[i-1];
auto const& pt1 = exterior[i];
//auto const& exterior = geom.exterior_ring;
//std::size_t num_points = exterior.size();
//if (num_points < 4) return false;
//for (std::size_t i = 1; i < num_points; ++i)
//{
// auto const& pt0 = exterior[i-1];
// auto const& pt1 = exterior[i];
// todo - account for tolerance
if (pip(pt0.x,pt0.y,pt1.x,pt1.y,x_,y_))
// if (pip(pt0.x,pt0.y,pt1.x,pt1.y,x_,y_))
// {
// inside = !inside;
// }
//}
//if (!inside) return false;
//// FIXME !!!
bool inside = false;
bool exterior = true;
for (auto const& ring : poly)
{
inside = !inside;
}
}
if (!inside) return false;
for (auto const& ring : geom.interior_rings)
std::size_t num_points = ring.size();
if (num_points < 4)
{
std::size_t num_interior_points = ring.size();
if (num_interior_points < 4)
{
continue;
if (exterior) return false;
else continue;
}
for (std::size_t j = 1; j < num_interior_points; ++j)
for (std::size_t j = 1; j < num_points; ++j)
{
auto const& pt0 = ring[j - 1];
auto const& pt1 = ring[j];
@ -124,6 +130,7 @@ struct hit_test_visitor
}
}
}
////////////////////////////
return inside;
}
bool operator() (geometry::multi_polygon<double> const& geom) const

View file

@ -96,11 +96,11 @@ struct geometry_generator_grammar :
karma::rule<OutputIterator, geometry::geometry<double> const&()> point;
karma::rule<OutputIterator, geometry::point<double> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<double> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::line_string<double>::container_type const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<double> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<double> const&()> exterior_ring_coord;
karma::rule<OutputIterator, geometry::polygon<double>::rings_container const&()> interior_ring_coord;
//karma::rule<OutputIterator, geometry::linear_ring<double> const&()> exterior_ring_coord;
//karma::rule<OutputIterator, geometry::polygon<double> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<double> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_linestring;

View file

@ -98,12 +98,12 @@ geometry_generator_grammar<OutputIterator, Geometry>::geometry_generator_grammar
;
linestring_coord = point_coord % lit(',')
;
polygon_coord = lit('[') << exterior_ring_coord << lit(']') << interior_ring_coord
;
exterior_ring_coord = linestring_coord.alias()
;
interior_ring_coord = *(lit(",[") << exterior_ring_coord << lit(']'))
polygon_coord = (lit('[') << linestring_coord << lit(']')) % lit(',') //<< interior_ring_coord
;
//exterior_ring_coord = linestring_coord.alias()
// ;
//interior_ring_coord = *(lit(",[") << exterior_ring_coord << lit(']'))
// ;
multi_point_coord = linestring_coord.alias()
;
multi_linestring_coord = (lit('[') << linestring_coord << lit(']')) % lit(',')

View file

@ -84,10 +84,7 @@ struct create_polygon
{
mapnik::geometry::polygon<double> poly;
std::size_t num_rings = rings.size();
if (num_rings > 1)
{
poly.interior_rings.reserve(num_rings - 1);
}
poly.reserve(num_rings);
for ( std::size_t i = 0; i < num_rings; ++i)
{
@ -98,8 +95,7 @@ struct create_polygon
{
ring.emplace_back(std::move(pt));
}
if (i == 0) poly.set_exterior_ring(std::move(ring));
else poly.add_hole(std::move(ring));
poly.push_back(std::move(ring));
}
geom_ = std::move(poly);
mapnik::geometry::correct(geom_);
@ -179,9 +175,7 @@ struct create_multipolygon
{
mapnik::geometry::polygon<double> poly;
std::size_t num_rings = rings.size();
if ( num_rings > 1)
poly.interior_rings.reserve(num_rings - 1);
poly.reserve(num_rings);
for ( std::size_t i = 0; i < num_rings; ++i)
{
std::size_t size = rings[i].size();
@ -191,8 +185,8 @@ struct create_multipolygon
{
ring.emplace_back(std::move(pt));
}
if (i == 0) poly.set_exterior_ring(std::move(ring));
else poly.add_hole(std::move(ring));
poly.push_back(std::move(ring));
}
multi_poly.emplace_back(std::move(poly));
}

View file

@ -406,8 +406,7 @@ struct feature_generator
{
std::vector<mapnik::topojson::coordinate> processed_coords;
mapnik::geometry::polygon<double> polygon;
if (poly.rings.size() > 1) polygon.interior_rings.reserve(poly.rings.size() - 1);
bool first = true;
polygon.reserve(poly.rings.size());
bool hit = false;
for (auto const& ring : poly.rings)
{
@ -454,15 +453,7 @@ struct feature_generator
}
}
}
if (first)
{
first = false;
polygon.set_exterior_ring(std::move(linear_ring));
}
else
{
polygon.add_hole(std::move(linear_ring));
}
polygon.push_back(std::move(linear_ring));
}
if (hit)
{
@ -485,9 +476,8 @@ struct feature_generator
bool hit = false;
for (auto const& poly : multi_poly.polygons)
{
bool first = true;
mapnik::geometry::polygon<double> polygon;
if (poly.size() > 1) polygon.interior_rings.reserve(poly.size() - 1);
polygon.reserve(poly.size());
for (auto const& ring : poly)
{
@ -536,15 +526,7 @@ struct feature_generator
}
}
}
if (first)
{
first = false;
polygon.set_exterior_ring(std::move(linear_ring));
}
else
{
polygon.add_hole(std::move(linear_ring));
}
polygon.push_back(std::move(linear_ring));
}
multi_polygon.push_back(std::move(polygon));
}

View file

@ -133,7 +133,7 @@ using wkb_buffer_ptr = std::unique_ptr<wkb_buffer>;
wkb_buffer_ptr point_wkb( geometry::point<double> const& pt, wkbByteOrder byte_order)
{
std::size_t size = 1 + 4 + 8 * 2 ; // byteOrder + wkbType + Point
std::size_t const size = 1 + 4 + 8 * 2 ; // byteOrder + wkbType + Point
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
wkb_stream ss(wkb->buffer(), wkb->size());
ss.write(reinterpret_cast<char*>(&byte_order),1);
@ -148,7 +148,7 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string<double> const& line, wkbByt
{
std::size_t num_points = line.size();
assert(num_points > 1);
std::size_t size = 1 + 4 + 4 + 8 * 2 * num_points ; // byteOrder + wkbType + numPoints + Point*numPoints
std::size_t const size = 1 + 4 + 4 + 8 * 2 * num_points ; // byteOrder + wkbType + numPoints + Point*numPoints
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
wkb_stream ss(wkb->buffer(), wkb->size());
ss.write(reinterpret_cast<char*>(&byte_order),1);
@ -167,10 +167,8 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string<double> const& line, wkbByt
wkb_buffer_ptr polygon_wkb( geometry::polygon<double> const& poly, wkbByteOrder byte_order)
{
std::size_t size = 1 + 4 + 4 ; // byteOrder + wkbType + numRings
size += 4 + 2 * 8 * poly.exterior_ring.size();
for ( auto const& ring : poly.interior_rings)
for ( auto const& ring : poly)
{
size += 4 + 2 * 8 * ring.size();
}
@ -178,17 +176,10 @@ wkb_buffer_ptr polygon_wkb( geometry::polygon<double> const& poly, wkbByteOrder
wkb_stream ss(wkb->buffer(), wkb->size());
ss.write(reinterpret_cast<char*>(&byte_order),1);
write(ss, static_cast<int>(mapnik::geometry::geometry_types::Polygon), 4, byte_order);
write(ss, poly.num_rings(), 4, byte_order);
write(ss, poly.size(), 4, byte_order);
// exterior
write(ss, poly.exterior_ring.size(), 4, byte_order);
for (auto const& pt : poly.exterior_ring)
{
write(ss, pt.x, 8, byte_order);
write(ss, pt.y, 8, byte_order);
}
// interiors
for (auto const& ring : poly.interior_rings)
// exterior *interior
for (auto const& ring : poly)
{
write(ss, ring.size(), 4, byte_order);
for ( auto const& pt : ring)

View file

@ -68,16 +68,16 @@ namespace boost { namespace spirit { namespace traits {
}
};
template <>
struct transform_attribute<mapnik::geometry::polygon<double> const,
mapnik::geometry::polygon<double>::rings_container const&, karma::domain>
{
using type = mapnik::geometry::polygon<double>::rings_container const&;
static type pre(mapnik::geometry::polygon<double> const& poly)
{
return poly.interior_rings;
}
};
//template <>
// struct transform_attribute<mapnik::geometry::polygon<double> const,
// mapnik::geometry::polygon<double>::rings_container const&, karma::domain>
// {
// using type = mapnik::geometry::polygon<double>::rings_container const&;
// static type pre(mapnik::geometry::polygon<double> const& poly)
// {
// return poly.interior_rings;
// }
// };
template <>
struct transform_attribute<mapnik::geometry::geometry<double> const,
@ -156,16 +156,16 @@ namespace boost { namespace spirit { namespace traits {
}
};
template <>
struct transform_attribute<mapnik::geometry::polygon<std::int64_t> const,
mapnik::geometry::polygon<std::int64_t>::rings_container const&, karma::domain>
{
using type = mapnik::geometry::polygon<std::int64_t>::rings_container const&;
static type pre(mapnik::geometry::polygon<std::int64_t> const& poly)
{
return poly.interior_rings;
}
};
//template <>
// struct transform_attribute<mapnik::geometry::polygon<std::int64_t> const,
// mapnik::geometry::polygon<std::int64_t>::rings_container const&, karma::domain>
// {
// using type = mapnik::geometry::polygon<std::int64_t>::rings_container const&;
// static type pre(mapnik::geometry::polygon<std::int64_t> const& poly)
// {
// return poly.interior_rings;
// }
// };
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,

View file

@ -115,8 +115,8 @@ struct wkt_generator_grammar :
karma::rule<OutputIterator, geometry::line_string<coordinate_type> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<coordinate_type> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<coordinate_type> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<coordinate_type> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::linear_ring<coordinate_type> const&()> ring;
//karma::rule<OutputIterator, std::vector<geometry::linear_ring<coordinate_type> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<coordinate_type> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const& ()> multi_linestring;

View file

@ -100,11 +100,9 @@ wkt_generator_grammar<OutputIterator, Geometry>::wkt_generator_grammar()
;
linestring_coord = point_coord % lit(',')
;
polygon_coord = lit('(') << exterior_ring_coord << lit(')') << interior_ring_coord
polygon_coord = ring % lit(',')//<< interior_ring_coord
;
exterior_ring_coord = linestring_coord.alias()
;
interior_ring_coord = *(lit(",(") << exterior_ring_coord << lit(')'))
ring = lit('(') << linestring_coord << lit(')')
;
multi_point_coord = linestring_coord.alias()
;

View file

@ -60,23 +60,14 @@ struct move_part
}
};
struct set_exterior
{
using result_type = void;
template <typename Polygon, typename Ring>
void operator() (Polygon & poly, Ring && ring) const
{
poly.set_exterior_ring(std::move(ring));
}
};
struct add_hole
struct set_ring
{
using result_type = void;
template <typename Polygon, typename Ring>
void operator() (Polygon & poly, Ring && ring) const
{
poly.add_hole(std::move(ring));
poly.push_back(std::move(ring));
}
};
@ -109,8 +100,7 @@ struct wkt_grammar : qi::grammar<Iterator, void(mapnik::geometry::geometry<doubl
qi::rule<Iterator,ascii::space_type> empty_set;
boost::phoenix::function<detail::assign> assign;
boost::phoenix::function<detail::move_part> move_part;
boost::phoenix::function<detail::set_exterior> set_exterior;
boost::phoenix::function<detail::add_hole> add_hole;
boost::phoenix::function<detail::set_ring> set_ring;
};
}}

View file

@ -86,12 +86,14 @@ wkt_grammar<Iterator>::wkt_grammar()
// <polygon text> ::= <empty set> | <left paren> <linestring text> {<comma> <linestring text>}* <right paren>
polygon_text =
(lit('(') >> linearring_text[set_exterior(_val,_1)] >> *(lit(',') >> linearring_text[add_hole(_val,_1)]) >> lit(')'))
lit('(') >> linearring_text[set_ring(_val,_1)] % lit(',') >> lit(')')
|
empty_set
;
linearring_text = ring_points | empty_set
linearring_text = ring_points
|
empty_set
;
//<multipoint tagged text> ::= multipoint <multipoint text>
multipoint_tagged_text = no_case[lit("MULTIPOINT")]

View file

@ -127,7 +127,7 @@ mapnik::geometry::polygon<double> ogr_converter::convert_polygon(OGRPolygon* ogr
{
exterior.emplace_back(ogr_exterior->getX(i), ogr_exterior->getY(i));
}
geom.set_exterior_ring(std::move(exterior));
geom.push_back(std::move(exterior));
int num_interior = ogr_geom->getNumInteriorRings();
for (int r = 0; r < num_interior; ++r)
@ -140,7 +140,7 @@ mapnik::geometry::polygon<double> ogr_converter::convert_polygon(OGRPolygon* ogr
{
interior.emplace_back(ogr_interior->getX(i), ogr_interior->getY(i));
}
geom.add_hole(std::move(interior));
geom.push_back(std::move(interior));
}
return geom;
}

View file

@ -210,17 +210,17 @@ mapnik::geometry::geometry<double> shape_io::read_polygon(shape_file::record_typ
}
if (k == 0)
{
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
}
else if (mapnik::util::is_clockwise(ring))
{
multi_poly.emplace_back(std::move(poly));
poly.interior_rings.clear();
poly.set_exterior_ring(std::move(ring));
poly.clear();
poly.push_back(std::move(ring));
}
else
{
poly.add_hole(std::move(ring));
poly.push_back(std::move(ring));
}
}
@ -260,17 +260,17 @@ mapnik::geometry::geometry<double> shape_io::read_polygon_parts(shape_file::reco
}
if (k == 0)
{
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
}
else if (mapnik::util::is_clockwise(ring))
{
multi_poly.emplace_back(std::move(poly));
poly.interior_rings.clear();
poly.set_exterior_ring(std::move(ring));
poly.clear();
poly.push_back(std::move(ring));
}
else
{
poly.add_hole(std::move(ring));
poly.push_back(std::move(ring));
}
}

View file

@ -180,17 +180,24 @@ struct render_ring_visitor
}
}
void operator()(mapnik::geometry::polygon<double> const& geom) const
void operator()(mapnik::geometry::polygon<double> const& poly) const
{
agg::rgba8 red(255,0,0,255);
agg::rgba8 green(0,255,255,255);
agg::rgba8 black(0,0,0,255);
renderer_.draw_ring(geom.exterior_ring,red);
if (mapnik::util::is_clockwise(geom.exterior_ring))
bool exterior = true;
for (auto const& ring : poly)
{
renderer_.draw_outline(geom.exterior_ring,black);
if (exterior)
{
exterior = false;
renderer_.draw_ring(ring, red);
if (mapnik::util::is_clockwise(ring))
{
renderer_.draw_outline(ring,black);
}
for (auto const& ring : geom.interior_rings)
}
else
{
renderer_.draw_ring(ring,green);
if (!mapnik::util::is_clockwise(ring))
@ -199,6 +206,7 @@ struct render_ring_visitor
}
}
}
}
template<typename GeomType>
void operator()(GeomType const&) const {}

View file

@ -328,11 +328,7 @@ private:
{
unsigned int num_rings = read_unsigned_integer();
mapnik::geometry::polygon<double> poly;
if (num_rings > 1)
{
poly.interior_rings.reserve(num_rings - 1);
}
poly.reserve(num_rings);
for (unsigned int i = 0; i < num_rings; ++i)
{
mapnik::geometry::linear_ring<double> ring;
@ -342,8 +338,7 @@ private:
ring.reserve(num_points);
read_coords<mapnik::geometry::linear_ring<double>>(ring, num_points);
}
if ( i == 0) poly.set_exterior_ring(std::move(ring));
else poly.add_hole(std::move(ring));
poly.push_back(std::move(ring));
}
return poly;
}

View file

@ -102,18 +102,18 @@ template <typename T>
polygon_vertex_adapter<T>::polygon_vertex_adapter(polygon<T> const& poly)
: poly_(poly),
rings_itr_(0),
rings_end_(poly_.interior_rings.size() + 1),
rings_end_(poly_.size()),
current_index_(0),
end_index_((rings_itr_ < rings_end_) ? poly_.exterior_ring.size() : 0),
end_index_(poly_.empty() ? 0 : poly_[0].size()),
start_loop_(true) {}
template <typename T>
void polygon_vertex_adapter<T>::rewind(unsigned) const
{
rings_itr_ = 0;
rings_end_ = poly_.interior_rings.size() + 1;
rings_end_ = poly_.size();
current_index_ = 0;
end_index_ = (rings_itr_ < rings_end_) ? poly_.exterior_ring.size() : 0;
end_index_ = poly_.empty() ? 0 : poly_[0].size();
start_loop_ = true;
}
template <typename T>
@ -125,8 +125,7 @@ unsigned polygon_vertex_adapter<T>::vertex(coordinate_type * x, coordinate_type
}
if (current_index_ < end_index_)
{
point<T> const& coord = (rings_itr_ == 0) ?
poly_.exterior_ring[current_index_++] : poly_.interior_rings[rings_itr_- 1][current_index_++];
point<T> const& coord = poly_[rings_itr_][current_index_++];
*x = coord.x;
*y = coord.y;
if (start_loop_)
@ -145,8 +144,8 @@ unsigned polygon_vertex_adapter<T>::vertex(coordinate_type * x, coordinate_type
else if (++rings_itr_ != rings_end_)
{
current_index_ = 0;
end_index_ = poly_.interior_rings[rings_itr_ - 1].size();
point<T> const& coord = poly_.interior_rings[rings_itr_ - 1][current_index_++];
end_index_ = poly_[rings_itr_].size();
point<T> const& coord = poly_[rings_itr_][current_index_++];
*x = coord.x;
*y = coord.y;
return mapnik::SEG_MOVETO;

View file

@ -329,11 +329,7 @@ private:
{
int num_rings = read_integer();
mapnik::geometry::polygon<double> poly;
if (num_rings > 1)
{
poly.interior_rings.reserve(num_rings - 1);
}
poly.reserve(num_rings);
for (int i = 0; i < num_rings; ++i)
{
mapnik::geometry::linear_ring<double> ring;
@ -343,8 +339,7 @@ private:
ring.reserve(num_points);
read_coords<mapnik::geometry::linear_ring<double>, M, Z>(ring, num_points);
}
if ( i == 0) poly.set_exterior_ring(std::move(ring));
else poly.add_hole(std::move(ring));
poly.push_back(std::move(ring));
}
return poly;
}

View file

@ -152,10 +152,9 @@ TEST_CASE("geojson") {
auto const& geometry = feature->get_geometry();
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::Polygon);
auto const& poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geometry);
REQUIRE(poly.num_rings() == 2);
REQUIRE(poly.exterior_ring.size() == 5);
REQUIRE(poly.interior_rings.size() == 1);
REQUIRE(poly.interior_rings[0].size() == 5);
REQUIRE(poly.size() == 2);
REQUIRE(poly[0].size() == 5);
REQUIRE(poly[1].size() == 5);
REQUIRE(mapnik::geometry::envelope(poly) == mapnik::box2d<double>(100,0,101,1));
}
@ -209,8 +208,8 @@ TEST_CASE("geojson") {
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::MultiPolygon);
auto const& multi_poly = mapnik::util::get<mapnik::geometry::multi_polygon<double> >(geometry);
REQUIRE(multi_poly.size() == 2);
REQUIRE(multi_poly[0].num_rings() == 1);
REQUIRE(multi_poly[1].num_rings() == 2);
REQUIRE(multi_poly[0].size() == 1);
REQUIRE(multi_poly[1].size() == 2);
REQUIRE(mapnik::geometry::envelope(multi_poly) == mapnik::box2d<double>(100,0,103,3));
}

View file

@ -55,7 +55,7 @@ SECTION("polygon") {
ring.emplace_back(1, 1);
ring.emplace_back(0, 1);
ring.emplace_back(0, 0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::point<double> centroid;
REQUIRE(mapnik::geometry::centroid(poly, centroid));
@ -67,7 +67,7 @@ SECTION("polygon with empty exterior ring") {
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::point<double> centroid;
REQUIRE(!mapnik::geometry::centroid(poly, centroid));
@ -76,6 +76,7 @@ SECTION("polygon with empty exterior ring") {
SECTION("empty polygon") {
mapnik::geometry::polygon<double> poly;
poly.emplace_back();
mapnik::geometry::point<double> centroid;
REQUIRE(!mapnik::geometry::centroid(poly, centroid));
}
@ -155,7 +156,7 @@ SECTION("multi-polygon") {
ring.emplace_back(1, 1);
ring.emplace_back(0, 1);
ring.emplace_back(0, 0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
}
{
@ -166,7 +167,7 @@ SECTION("multi-polygon") {
ring.emplace_back(2, 2);
ring.emplace_back(1, 2);
ring.emplace_back(1, 1);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
}
@ -186,10 +187,10 @@ SECTION("multi-polygon: one component empty") {
ring.emplace_back(1, 1);
ring.emplace_back(0, 1);
ring.emplace_back(0, 0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
geom.emplace_back();
geom.back().emplace_back();
mapnik::geometry::point<double> centroid;
REQUIRE(mapnik::geometry::centroid(geom, centroid));
REQUIRE(centroid.x == 0.5);

View file

@ -64,7 +64,7 @@ void envelope_test()
ring.emplace_back(-10,10);
ring.emplace_back(0,10);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geometry<coord_type> geom(poly);
mapnik::box2d<coord_type> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == -10 );
@ -107,14 +107,14 @@ void envelope_test()
ring.emplace_back(-10,10);
ring.emplace_back(0,10);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
linear_ring<coord_type> hole;
hole.emplace_back(-7,7);
hole.emplace_back(-7,3);
hole.emplace_back(-3,3);
hole.emplace_back(-3,7);
hole.emplace_back(-7,7);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
geometry<coord_type> geom(poly);
mapnik::box2d<coord_type> bbox = mapnik::geometry::envelope(poly);
REQUIRE( bbox.minx() == -10 );
@ -129,7 +129,7 @@ void envelope_test()
fill.emplace_back(-4,6);
fill.emplace_back(-4,4);
fill.emplace_back(-6,4);
poly.add_hole(std::move(fill));
poly.push_back(std::move(fill));
bbox = mapnik::geometry::envelope(poly);
REQUIRE( bbox.minx() == -10 );
REQUIRE( bbox.miny() == 0 );

View file

@ -137,15 +137,12 @@ struct geometry_equal_visitor
template <typename T>
void operator() (polygon<T> const& p1, polygon<T> const& p2) const
{
(*this)(static_cast<std::vector<point<T>> const&>(p1.exterior_ring),
static_cast<std::vector<point<T>> const&>(p2.exterior_ring));
if (p1.interior_rings.size() != p2.interior_rings.size())
if (p1.size() != p2.size())
{
REQUIRE(false);
}
for (auto const& p : zip_crange(p1.interior_rings, p2.interior_rings))
for (auto const& p : zip_crange(p1, p2))
{
(*this)(static_cast<std::vector<point<T>> const&>(p.template get<0>()),
static_cast<std::vector<point<T>> const&>(p.template get<1>()));

View file

@ -50,7 +50,7 @@ SECTION("hit_test_filter - double") {
ring.emplace_back(-10,10);
ring.emplace_back(0,10);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geometry<double> geom(poly);
REQUIRE( mapnik::hit_test(geom,-5,5,0) );
@ -82,14 +82,14 @@ SECTION("hit_test_filter - double") {
ring.emplace_back(-10,10);
ring.emplace_back(0,10);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
linear_ring<double> hole;
hole.emplace_back(-7,7);
hole.emplace_back(-7,3);
hole.emplace_back(-3,3);
hole.emplace_back(-3,7);
hole.emplace_back(-7,7);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
geometry<double> geom(poly);
REQUIRE( !mapnik::hit_test(geom,-5,5,0) );
// add another hole inside the first hole
@ -100,7 +100,7 @@ SECTION("hit_test_filter - double") {
fill.emplace_back(-4,6);
fill.emplace_back(-4,4);
fill.emplace_back(-6,4);
poly.add_hole(std::move(fill));
poly.push_back(std::move(fill));
REQUIRE( mapnik::hit_test(geometry<double>(poly),-5,5,0) );
}
}

View file

@ -117,7 +117,7 @@ SECTION("polygon") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( mapnik::geometry::is_simple(poly) );
}
@ -129,7 +129,7 @@ SECTION("polygon invalid winding order") {
ring.emplace_back(1,1);
ring.emplace_back(1,0);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( mapnik::geometry::is_simple(poly) );
}
@ -144,7 +144,7 @@ SECTION("polygon 2 repeated points") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( !mapnik::geometry::is_simple(poly) );
}
// repeated points are not considered invalid in a polygon
@ -159,7 +159,7 @@ SECTION("polygon 3 repeated points") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( !mapnik::geometry::is_simple(poly) );
}
@ -167,13 +167,14 @@ SECTION("polygon 3 repeated points") {
SECTION("polygon that is empty") {
mapnik::geometry::polygon<double> poly;
poly.emplace_back();
CHECK( !mapnik::geometry::is_simple(poly) );
}
SECTION("polygon that has empty exterior ring") {
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( !mapnik::geometry::is_simple(poly) );
}
@ -185,9 +186,9 @@ SECTION("polygon that has empty interior ring") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> ring2;
poly.add_hole(std::move(ring2));
poly.push_back(std::move(ring2));
CHECK( !mapnik::geometry::is_simple(poly) );
}
@ -201,7 +202,7 @@ SECTION("polygon that is empty") {
SECTION("polygon that has empty exterior ring") {
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( mapnik::geometry::is_simple(poly) );
}
@ -213,9 +214,9 @@ SECTION("polygon that has empty interior ring") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> ring2;
poly.add_hole(std::move(ring2));
poly.push_back(std::move(ring2));
CHECK( mapnik::geometry::is_simple(poly) );
}
@ -232,7 +233,7 @@ SECTION("polygon with spike") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( mapnik::geometry::is_simple(poly) );
}
@ -244,14 +245,14 @@ SECTION("polygon with hole") {
ring.emplace_back(3,3);
ring.emplace_back(0,3);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> hole;
hole.emplace_back(1,1);
hole.emplace_back(1,2);
hole.emplace_back(2,2);
hole.emplace_back(2,1);
hole.emplace_back(1,1);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
CHECK( mapnik::geometry::is_simple(poly) );
}
@ -264,14 +265,14 @@ SECTION("polygon with hole with invalid winding order") {
ring.emplace_back(3,3);
ring.emplace_back(0,3);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> hole;
hole.emplace_back(1,1);
hole.emplace_back(2,1);
hole.emplace_back(2,2);
hole.emplace_back(1,2);
hole.emplace_back(1,1);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
CHECK( mapnik::geometry::is_simple(poly) );
}
@ -284,7 +285,7 @@ SECTION("multi polygon") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring<double> ring2;
ring2.emplace_back(0,0);
@ -292,7 +293,7 @@ SECTION("multi polygon") {
ring2.emplace_back(-1,-1);
ring2.emplace_back(0,-1);
ring2.emplace_back(0,0);
poly2.set_exterior_ring(std::move(ring2));
poly2.push_back(std::move(ring2));
mp.emplace_back(poly);
mp.emplace_back(poly2);
CHECK( mapnik::geometry::is_simple(mp) );
@ -307,14 +308,14 @@ SECTION("multi polygon with hole") {
ring.emplace_back(3,3);
ring.emplace_back(0,3);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> hole;
hole.emplace_back(1,1);
hole.emplace_back(1,2);
hole.emplace_back(2,2);
hole.emplace_back(2,1);
hole.emplace_back(1,1);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring<double> ring2;
ring2.emplace_back(0,0);
@ -322,14 +323,14 @@ SECTION("multi polygon with hole") {
ring2.emplace_back(-3,-3);
ring2.emplace_back(0,-3);
ring2.emplace_back(0,0);
poly2.set_exterior_ring(std::move(ring2));
poly2.push_back(std::move(ring2));
mapnik::geometry::linear_ring<double> hole2;
hole2.emplace_back(-1,-1);
hole2.emplace_back(-1,-2);
hole2.emplace_back(-2,-2);
hole2.emplace_back(-2,-1);
hole2.emplace_back(-1,-1);
poly2.add_hole(std::move(hole2));
poly2.push_back(std::move(hole2));
mp.emplace_back(poly);
mp.emplace_back(poly2);
CHECK( mapnik::geometry::is_simple(mp) );

View file

@ -224,7 +224,7 @@ SECTION("polygon") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( mapnik::geometry::is_valid(poly, message) );
@ -242,7 +242,7 @@ SECTION("polygon invalid winding order") {
ring.emplace_back(1,1);
ring.emplace_back(1,0);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( !mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( !mapnik::geometry::is_valid(poly, message) );
@ -262,7 +262,7 @@ SECTION("polygon 2 repeated points") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( mapnik::geometry::is_valid(poly, message) );
@ -282,7 +282,7 @@ SECTION("polygon 3 repeated points") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( mapnik::geometry::is_valid(poly, message) );
@ -294,6 +294,7 @@ SECTION("polygon 3 repeated points") {
SECTION("polygon that is empty") {
mapnik::geometry::polygon<double> poly;
poly.emplace_back();
CHECK( !mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( !mapnik::geometry::is_valid(poly, message) );
@ -313,7 +314,7 @@ SECTION("polygon with spike") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
CHECK( !mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( !mapnik::geometry::is_valid(poly, message) );
@ -331,14 +332,14 @@ SECTION("polygon with hole") {
ring.emplace_back(3,3);
ring.emplace_back(0,3);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> hole;
hole.emplace_back(1,1);
hole.emplace_back(1,2);
hole.emplace_back(2,2);
hole.emplace_back(2,1);
hole.emplace_back(1,1);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
CHECK( mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( mapnik::geometry::is_valid(poly, message) );
@ -356,9 +357,9 @@ SECTION("polygon with empty hole") {
ring.emplace_back(3,3);
ring.emplace_back(0,3);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> hole;
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
CHECK( !mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( !mapnik::geometry::is_valid(poly, message) );
@ -377,14 +378,14 @@ SECTION("polygon with hole with invalid winding order") {
ring.emplace_back(3,3);
ring.emplace_back(0,3);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> hole;
hole.emplace_back(1,1);
hole.emplace_back(2,1);
hole.emplace_back(2,2);
hole.emplace_back(1,2);
hole.emplace_back(1,1);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
CHECK( !mapnik::geometry::is_valid(poly) );
std::string message;
CHECK( !mapnik::geometry::is_valid(poly, message) );
@ -403,7 +404,7 @@ SECTION("multi polygon") {
ring.emplace_back(1,1);
ring.emplace_back(0,1);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring<double> ring2;
ring2.emplace_back(0,0);
@ -411,7 +412,7 @@ SECTION("multi polygon") {
ring2.emplace_back(-1,-1);
ring2.emplace_back(0,-1);
ring2.emplace_back(0,0);
poly2.set_exterior_ring(std::move(ring2));
poly2.push_back(std::move(ring2));
mp.emplace_back(poly);
mp.emplace_back(poly2);
CHECK( mapnik::geometry::is_valid(mp) );
@ -432,14 +433,14 @@ SECTION("multi polygon with hole") {
ring.emplace_back(3,3);
ring.emplace_back(0,3);
ring.emplace_back(0,0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
mapnik::geometry::linear_ring<double> hole;
hole.emplace_back(1,1);
hole.emplace_back(1,2);
hole.emplace_back(2,2);
hole.emplace_back(2,1);
hole.emplace_back(1,1);
poly.add_hole(std::move(hole));
poly.push_back(std::move(hole));
mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring<double> ring2;
ring2.emplace_back(0,0);
@ -447,14 +448,14 @@ SECTION("multi polygon with hole") {
ring2.emplace_back(-3,-3);
ring2.emplace_back(0,-3);
ring2.emplace_back(0,0);
poly2.set_exterior_ring(std::move(ring2));
poly2.push_back(std::move(ring2));
mapnik::geometry::linear_ring<double> hole2;
hole2.emplace_back(-1,-1);
hole2.emplace_back(-1,-2);
hole2.emplace_back(-2,-2);
hole2.emplace_back(-2,-1);
hole2.emplace_back(-1,-1);
poly2.add_hole(std::move(hole2));
poly2.push_back(std::move(hole2));
mp.emplace_back(poly);
mp.emplace_back(poly2);
CHECK( mapnik::geometry::is_valid(mp) );

View file

@ -321,43 +321,49 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Object") {
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1;
geom1.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1.exterior_ring.emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1.exterior_ring.emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1.exterior_ring.emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1.interior_rings.emplace_back();
geom1.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1.interior_rings.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1.interior_rings.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1.interior_rings.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
// exterior
geom1.emplace_back();
geom1.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1.back().emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1.back().emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1.back().emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
// interior
geom1.emplace_back();
geom1.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
polygon<double> geom2;
geom2.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2.exterior_ring.emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2.exterior_ring.emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2.exterior_ring.emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2.interior_rings.emplace_back();
geom2.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2.interior_rings.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2.interior_rings.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2.interior_rings.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
// interior
geom2.emplace_back();
geom2.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2.back().emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2.back().emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2.back().emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
// exterior
geom2.emplace_back();
geom2.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
unsigned int err = 0;
{
// Test Standard Transform
// Add extra vector to outer ring.
geom1.interior_rings.emplace_back();
REQUIRE(geom1.interior_rings.size() == 2);
geom1.emplace_back();
REQUIRE(geom1.size() == 3);
polygon<double> new_geom = reproject_copy(geom1, proj_trans1, err);
REQUIRE(err == 0);
// Should remove the empty ring added to back of geom1
REQUIRE(new_geom.interior_rings.size() == 1);
REQUIRE(new_geom.size() == 2);
assert_g_equal(new_geom, geom2);
// Remove extra ring for future validity tests.
geom1.interior_rings.pop_back();
REQUIRE(geom1.interior_rings.size() == 1);
geom1.pop_back();
REQUIRE(geom1.size() == 2);
}
{
// Transform in reverse
@ -380,13 +386,13 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Object") {
{
// Transform in place
polygon<double> geom3(geom1);
geom3.interior_rings.emplace_back();
geom3.emplace_back();
REQUIRE(reproject(geom3, proj_trans1));
// Should NOT remove the empty ring added to back of geom1
REQUIRE(geom3.interior_rings.size() == 2);
REQUIRE(geom3.size() == 3);
// Remove so asserts that geometries are the same
geom3.interior_rings.pop_back();
REQUIRE(geom3.interior_rings.size() == 1);
geom3.pop_back();
REQUIRE(geom3.size() == 2);
assert_g_equal(geom3, geom2);
// Transform in place reverse
REQUIRE(reproject(geom3, proj_trans2));
@ -410,29 +416,36 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Variant Object") {
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1_;
geom1_.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1_.exterior_ring.emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1_.exterior_ring.emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1_.exterior_ring.emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1_.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1_.interior_rings.emplace_back();
geom1_.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1_.interior_rings.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1_.interior_rings.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1_.interior_rings.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1_.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
// exterior
geom1_.emplace_back();
geom1_.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1_.back().emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1_.back().emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1_.back().emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1_.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
// interior
geom1_.emplace_back();
geom1_.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1_.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1_.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1_.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1_.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
polygon<double> geom2_;
geom2_.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2_.exterior_ring.emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2_.exterior_ring.emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2_.exterior_ring.emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2_.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2_.interior_rings.emplace_back();
geom2_.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2_.interior_rings.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2_.interior_rings.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2_.interior_rings.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2_.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
// exterior
geom2_.emplace_back();
geom2_.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2_.back().emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2_.back().emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2_.back().emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2_.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
// interior
geom2_.emplace_back();
geom2_.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2_.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2_.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2_.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2_.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
polygon<double> geom0_;
geometry<double> geom0(geom0_);
geometry<double> geom1(geom1_);
@ -791,31 +804,37 @@ SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Object") {
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a;
geom1a.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a.exterior_ring.emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a.exterior_ring.emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a.exterior_ring.emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a.interior_rings.emplace_back();
geom1a.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a.interior_rings.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a.interior_rings.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a.interior_rings.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
// exterior
geom1a.emplace_back();
geom1a.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a.back().emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a.back().emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a.back().emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
// interior
geom1a.emplace_back();
geom1a.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
multi_polygon<double> geom1;
geom1.emplace_back(geom1a);
polygon<double> geom2a;
geom2a.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a.exterior_ring.emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a.exterior_ring.emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a.exterior_ring.emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a.interior_rings.emplace_back();
geom2a.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a.interior_rings.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a.interior_rings.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a.interior_rings.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
// exterior
geom2a.emplace_back();
geom2a.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a.back().emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a.back().emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a.back().emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
// interior
geom2a.emplace_back();
geom2a.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
multi_polygon<double> geom2;
geom2.emplace_back(geom2a);
unsigned int err = 0;
@ -884,31 +903,37 @@ SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Variant Object") {
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a_;
geom1a_.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a_.exterior_ring.emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a_.exterior_ring.emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a_.exterior_ring.emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a_.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a_.interior_rings.emplace_back();
geom1a_.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
// exterior
geom1a_.emplace_back();
geom1a_.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a_.back().emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a_.back().emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a_.back().emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a_.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
// interior
geom1a_.emplace_back();
geom1a_.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a_.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a_.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a_.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a_.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
multi_polygon<double> geom1_;
geom1_.emplace_back(geom1a_);
polygon<double> geom2a_;
geom2a_.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a_.exterior_ring.emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a_.exterior_ring.emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a_.exterior_ring.emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a_.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a_.interior_rings.emplace_back();
geom2a_.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a_.interior_rings.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a_.interior_rings.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a_.interior_rings.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a_.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
// exterior
geom2a_.emplace_back();
geom2a_.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a_.back().emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a_.back().emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a_.back().emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a_.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
// interior
geom2a_.emplace_back();
geom2a_.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a_.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a_.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a_.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a_.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
multi_polygon<double> geom2_;
geom2_.emplace_back(geom2a_);
multi_polygon<double> geom0_;
@ -973,31 +998,37 @@ SECTION("test_projection_4326_3857 - Geometry Collection Object") {
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a;
geom1a.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a.exterior_ring.emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a.exterior_ring.emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a.exterior_ring.emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a.interior_rings.emplace_back();
geom1a.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a.interior_rings.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a.interior_rings.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a.interior_rings.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
// exterior
geom1a.emplace_back();
geom1a.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a.back().emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a.back().emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a.back().emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
// interior
geom1a.emplace_back();
geom1a.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geometry_collection<double> geom1;
geom1.emplace_back(geometry<double>(geom1a));
polygon<double> geom2a;
geom2a.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a.exterior_ring.emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a.exterior_ring.emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a.exterior_ring.emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a.interior_rings.emplace_back();
geom2a.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a.interior_rings.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a.interior_rings.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a.interior_rings.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
// exerior
geom2a.emplace_back();
geom2a.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a.back().emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a.back().emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a.back().emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
// interior
geom2a.emplace_back();
geom2a.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geometry_collection<double> geom2;
geom2.emplace_back(geometry<double>(geom2a));
unsigned int err = 0;
@ -1066,31 +1097,37 @@ SECTION("test_projection_4326_3857 - Geometry Collection Variant Object") {
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a_;
geom1a_.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a_.exterior_ring.emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a_.exterior_ring.emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a_.exterior_ring.emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a_.exterior_ring.emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a_.interior_rings.emplace_back();
geom1a_.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a_.interior_rings.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
// exterior
geom1a_.emplace_back();
geom1a_.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
geom1a_.back().emplace_back(point<double>(-97.79067993164062, 35.43941441533686));
geom1a_.back().emplace_back(point<double>(-97.60391235351562, 35.34425514918409));
geom1a_.back().emplace_back(point<double>(-97.42813110351562, 35.48191987272801));
geom1a_.back().emplace_back(point<double>(-97.62588500976562, 35.62939577711732));
// interior
geom1a_.emplace_back();
geom1a_.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geom1a_.back().emplace_back(point<double>(-97.61489868164062, 35.54116627999813));
geom1a_.back().emplace_back(point<double>(-97.53799438476562, 35.459551379037606));
geom1a_.back().emplace_back(point<double>(-97.62451171875, 35.42598697382711));
geom1a_.back().emplace_back(point<double>(-97.66571044921875, 35.46849952318069));
geometry_collection<double> geom1_;
geom1_.emplace_back(geometry<double>(geom1a_));
polygon<double> geom2a_;
geom2a_.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a_.exterior_ring.emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a_.exterior_ring.emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a_.exterior_ring.emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a_.exterior_ring.emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a_.interior_rings.emplace_back();
geom2a_.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a_.interior_rings.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a_.interior_rings.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a_.interior_rings.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a_.interior_rings.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
// exterior
geom2a_.emplace_back();
geom2a_.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
geom2a_.back().emplace_back(point<double>(-10886008.694318, 4223757.308982));
geom2a_.back().emplace_back(point<double>(-10865217.822625, 4210763.014174));
geom2a_.back().emplace_back(point<double>(-10845649.943384, 4229566.523132));
geom2a_.back().emplace_back(point<double>(-10867663.807530, 4249745.898599));
// interior
geom2a_.emplace_back();
geom2a_.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geom2a_.back().emplace_back(point<double>(-10866440.815077, 4237668.848130));
geom2a_.back().emplace_back(point<double>(-10857879.867909, 4226509.042001));
geom2a_.back().emplace_back(point<double>(-10867510.933473, 4221922.820303));
geom2a_.back().emplace_back(point<double>(-10872097.155170, 4227732.034453));
geometry_collection<double> geom2_;
geom2_.emplace_back(geometry<double>(geom2a_));
multi_polygon<double> geom0_;

View file

@ -1,4 +1,3 @@
#include "catch.hpp"
#include "geometry_equal.hpp"
@ -12,7 +11,7 @@
#include <mapnik/view_strategy.hpp>
TEST_CASE("geometry strategy tests") {
#if 0
SECTION("proj and view strategy") {
using namespace mapnik::geometry;
mapnik::box2d<double> e(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
@ -184,5 +183,5 @@ SECTION("scaling strategies - double to int64") {
assert_g_equal(r, o);
}
} // END SECTION
#endif
} // END TEST CASE

View file

@ -71,7 +71,7 @@ SECTION("polygon") {
{
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
REQUIRE(!mapnik::geometry::has_empty(poly));
}
{
@ -82,7 +82,7 @@ SECTION("polygon") {
ring.emplace_back(1, 1);
ring.emplace_back(0, 1);
ring.emplace_back(0, 0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
REQUIRE(!mapnik::geometry::has_empty(poly));
}
}
@ -133,16 +133,16 @@ SECTION("multi-polygon") {
mapnik::geometry::multi_polygon<double> geom;
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
REQUIRE(mapnik::geometry::has_empty(geom));
//REQUIRE(mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::multi_polygon<double> geom;
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
ring.emplace_back(0, 0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
REQUIRE(!mapnik::geometry::has_empty(geom));
}

View file

@ -54,8 +54,8 @@ SECTION("polygon") {
{
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.set_exterior_ring(std::move(ring));
REQUIRE(mapnik::geometry::is_empty(poly));
poly.push_back(std::move(ring));
//REQUIRE(mapnik::geometry::is_empty(poly));
}
{
mapnik::geometry::polygon<double> poly;
@ -65,7 +65,7 @@ SECTION("polygon") {
ring.emplace_back(1, 1);
ring.emplace_back(0, 1);
ring.emplace_back(0, 0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
REQUIRE(!mapnik::geometry::is_empty(poly));
}
}
@ -109,7 +109,7 @@ SECTION("multi-polygon") {
mapnik::geometry::multi_polygon<double> geom;
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
REQUIRE(!mapnik::geometry::is_empty(geom));
}

View file

@ -41,13 +41,13 @@ SECTION("multi-polygon") {
ring.emplace_back(1, 1);
ring.emplace_back(0, 1);
ring.emplace_back(0, 0);
poly.set_exterior_ring(std::move(ring));
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
geom.emplace_back();
//geom.back().emplace_back(); //add an empty exterior ring
REQUIRE(geom.size() == 2);
geom_type geom2 = mapnik::geometry::remove_empty(geom);
REQUIRE(geom2.size() == 1);
REQUIRE(geom2[0].exterior_ring.size() == 5);
REQUIRE(geom2.front().front().size() == 5);
}
}

View file

@ -7,10 +7,11 @@ TEST_CASE("vertex_adapters") {
SECTION("polygon") {
mapnik::geometry::polygon<double> g;
g.exterior_ring.emplace_back(1,1);
g.exterior_ring.emplace_back(2,2);
g.exterior_ring.emplace_back(100,100);
g.exterior_ring.emplace_back(1,1);
g.emplace_back();
g.back().emplace_back(1,1);
g.back().emplace_back(2,2);
g.back().emplace_back(100,100);
g.back().emplace_back(1,1);
mapnik::geometry::polygon_vertex_adapter<double> va(g);
double x,y;
@ -46,11 +47,12 @@ SECTION("polygon") {
SECTION("polygon with hole") {
mapnik::geometry::polygon<double> g;
g.exterior_ring.emplace_back(0,0);
g.exterior_ring.emplace_back(-10,0);
g.exterior_ring.emplace_back(-10,10);
g.exterior_ring.emplace_back(0,10);
g.exterior_ring.emplace_back(0,0);
g.emplace_back();
g.back().emplace_back(0,0);
g.back().emplace_back(-10,0);
g.back().emplace_back(-10,10);
g.back().emplace_back(0,10);
g.back().emplace_back(0,0);
std::vector<mapnik::geometry::linear_ring<double> > interior_rings;
mapnik::geometry::linear_ring<double> hole;
hole.emplace_back(-7,7);
@ -58,7 +60,7 @@ SECTION("polygon with hole") {
hole.emplace_back(-3,3);
hole.emplace_back(-3,7);
hole.emplace_back(-7,7);
g.add_hole(std::move(hole));
g.push_back(std::move(hole));
mapnik::geometry::linear_ring<double> hole_in_hole;
hole_in_hole.emplace_back(-6,4);
@ -66,7 +68,7 @@ SECTION("polygon with hole") {
hole_in_hole.emplace_back(-4,6);
hole_in_hole.emplace_back(-4,4);
hole_in_hole.emplace_back(-6,4);
g.add_hole(std::move(hole_in_hole));
g.push_back(std::move(hole_in_hole));
mapnik::geometry::polygon_vertex_adapter<double> va(g);
double x,y;
@ -99,7 +101,7 @@ SECTION("polygon with hole") {
REQUIRE( y == 0 );
// exterior ring via ring_vertex_adapter
mapnik::geometry::ring_vertex_adapter<double> va2(g.exterior_ring);
mapnik::geometry::ring_vertex_adapter<double> va2(g.front());
cmd = va2.vertex(&x,&y);
REQUIRE( cmd == mapnik::SEG_MOVETO );
REQUIRE( x == 0 );