From 225362b3f66c46b364727825b8c5c02eb5ccd2bc Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 24 Jan 2013 13:32:43 +0000 Subject: [PATCH 1/4] + fix to compile in c++11/libc++ mode (clang++ 3.3) --- include/mapnik/transform_expression.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/mapnik/transform_expression.hpp b/include/mapnik/transform_expression.hpp index 0b9ed99ad..7b5b55c75 100644 --- a/include/mapnik/transform_expression.hpp +++ b/include/mapnik/transform_expression.hpp @@ -71,7 +71,7 @@ struct translate_node translate_node(expr_node const& tx, boost::optional const& ty) : tx_(tx) - , ty_(ty ? *ty : value_null()) {} + , ty_(ty ? expr_node(*ty) : value_null()) {} }; struct scale_node @@ -82,7 +82,7 @@ struct scale_node scale_node(expr_node const& sx, boost::optional const& sy) : sx_(sx) - , sy_(sy ? *sy : value_null()) {} + , sy_(sy ? expr_node(*sy) : value_null()) {} }; struct rotate_node @@ -104,8 +104,8 @@ struct rotate_node boost::optional const& cx, boost::optional const& cy) : angle_(angle) - , cx_(cx ? *cx : value_null()) - , cy_(cy ? *cy : value_null()) {} + , cx_(cx ? expr_node(*cx) : value_null()) + , cy_(cy ? expr_node(*cy) : value_null()) {} rotate_node(expr_node const& angle, boost::optional const& center) From 57c8b550791f38ea6aada4c8cc6fd05bf770ae2f Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 24 Jan 2013 13:34:00 +0000 Subject: [PATCH 2/4] + add geometry conversions tests (clipping,smothing...) --- tests/cpp_tests/geometry_converters_test.cpp | 176 +++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tests/cpp_tests/geometry_converters_test.cpp diff --git a/tests/cpp_tests/geometry_converters_test.cpp b/tests/cpp_tests/geometry_converters_test.cpp new file mode 100644 index 000000000..d77af1cc4 --- /dev/null +++ b/tests/cpp_tests/geometry_converters_test.cpp @@ -0,0 +1,176 @@ +#include + +#include +#include +#include +#include +#include +#include +#include + +#if BOOST_VERSION >= 104700 +#include +#include +#include +#endif + +#include +#include + +struct output_geometry_backend +{ + output_geometry_backend(boost::ptr_vector & paths, mapnik::eGeomType type) + : paths_(paths), + type_(type) {} + + template + void add_path(T & path) + { + mapnik::vertex2d vtx(mapnik::vertex2d::no_init); + path.rewind(0); + std::auto_ptr geom_ptr(new mapnik::geometry_type(type_)); + + while ((vtx.cmd = path.vertex(&vtx.x, &vtx.y)) != mapnik::SEG_END) + { + //std::cerr << vtx.x << "," << vtx.y << " cmd=" << vtx.cmd << std::endl; + geom_ptr->push_vertex(vtx.x, vtx.y, (mapnik::CommandType)vtx.cmd); + } + paths_.push_back(geom_ptr); + } + boost::ptr_vector & paths_; + mapnik::eGeomType type_; +}; + +boost::optional linestring_bbox_clipping(mapnik::box2d bbox, + std::string wkt_in) +{ + using namespace mapnik; + agg::trans_affine tr; + projection src; + projection dst; + proj_transform prj_trans(src,dst); + line_symbolizer sym; + CoordTransform t(bbox.width(),bbox.height(), bbox); + boost::ptr_vector output_paths; + output_geometry_backend backend(output_paths, mapnik::LineString); + + typedef boost::mpl::vector conv_types; + vertex_converter, output_geometry_backend, line_symbolizer, + CoordTransform, proj_transform, agg::trans_affine, conv_types> + converter(bbox, backend, sym, t, prj_trans, tr, 1.0); + + converter.template set(); + + boost::ptr_vector p; + if (!mapnik::from_wkt(wkt_in , p)) + { + throw std::runtime_error("Failed to parse WKT"); + } + + BOOST_FOREACH( geometry_type & geom, p) + { + converter.apply(geom); + } + + std::string wkt_out; + if (mapnik::util::to_wkt(wkt_out, output_paths)) + { + return boost::optional(wkt_out); + } + + return boost::optional(); +} + +boost::optional polygon_bbox_clipping(mapnik::box2d bbox, + std::string wkt_in) +{ + using namespace mapnik; + agg::trans_affine tr; + projection src; + projection dst; + proj_transform prj_trans(src,dst); + polygon_symbolizer sym; + CoordTransform t(bbox.width(),bbox.height(), bbox); + boost::ptr_vector output_paths; + output_geometry_backend backend(output_paths, mapnik::Polygon); + + typedef boost::mpl::vector conv_types; + vertex_converter, output_geometry_backend, polygon_symbolizer, + CoordTransform, proj_transform, agg::trans_affine, conv_types> + converter(bbox, backend, sym, t, prj_trans, tr, 1.0); + + converter.template set(); + + boost::ptr_vector p; + if (!mapnik::from_wkt(wkt_in , p)) + { + throw std::runtime_error("Failed to parse WKT"); + } + + BOOST_FOREACH( geometry_type & geom, p) + { + converter.apply(geom); + } + + std::string wkt_out; + if (mapnik::util::to_wkt(wkt_out, output_paths)) + { + return boost::optional(wkt_out); + } + + return boost::optional(); +} + +int main( int, char*[] ) +{ + // LineString/bbox clipping + { + std::string wkt_in("LineString(0 0,200 200)"); + boost::optional result = linestring_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); + BOOST_TEST(result); + BOOST_TEST_EQ(*result,std::string("LineString(50 50,150 150)")); + } + // Polygon/bbox clipping +#if 0 + // these tests will fail + { + std::string wkt_in("Polygon((50 50,150 50,150 150,50 150,50 50))"); + boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); + BOOST_TEST(result); + BOOST_TEST_EQ(*result,std::string("Polygon((50 50,150 50,150 150,50 150,50 50))")); + } + + { + std::string wkt_in("Polygon((60 60,140 60,140 160,60 140,60 60))"); + boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); + BOOST_TEST(result); + BOOST_TEST_EQ(*result,std::string("Polygon((60 60,140 60,140 160,60 140,60 60))")); + } + + { + std::string wkt_in("Polygon((0 0, 10 0,10 10, 0 10,0 0))"); + boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); + BOOST_TEST(result); + BOOST_TEST_EQ(*result,std::string("Polygon EMPTY")); + } +#endif + { + std::string wkt_in("Polygon((0 0, 100 200, 200 0, 0 0 ))"); + boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); + BOOST_TEST(result); + BOOST_TEST_EQ(*result,std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50,50 50))")); + } + + + if (!::boost::detail::test_errors()) + { + std::clog << "C++ geometry conversions: \x1b[1;32m✓ \x1b[0m\n"; +#if BOOST_VERSION >= 104600 + ::boost::detail::report_errors_remind().called_report_errors_function = true; +#endif + } + else + { + return ::boost::report_errors(); + } +} From 7c229b457dcfe49772dc8e48202a569aba8b8175 Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 24 Jan 2013 13:44:17 +0000 Subject: [PATCH 3/4] + fix formatting --- tests/cpp_tests/geometry_converters_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cpp_tests/geometry_converters_test.cpp b/tests/cpp_tests/geometry_converters_test.cpp index d77af1cc4..8a0125cb9 100644 --- a/tests/cpp_tests/geometry_converters_test.cpp +++ b/tests/cpp_tests/geometry_converters_test.cpp @@ -148,14 +148,14 @@ int main( int, char*[] ) } { - std::string wkt_in("Polygon((0 0, 10 0,10 10, 0 10,0 0))"); + std::string wkt_in("Polygon((0 0,10 0,10 10,0 10,0 0))"); boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); BOOST_TEST(result); - BOOST_TEST_EQ(*result,std::string("Polygon EMPTY")); + BOOST_TEST_EQ(*result, std::string("GeometryCollection EMPTY")); } #endif { - std::string wkt_in("Polygon((0 0, 100 200, 200 0, 0 0 ))"); + std::string wkt_in("Polygon((0 0,100 200,200 0,0 0 ))"); boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); BOOST_TEST(result); BOOST_TEST_EQ(*result,std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50,50 50))")); From 730f07fbd6bbc6cf86303387a78b1f0f7051b46a Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 24 Jan 2013 17:28:32 +0000 Subject: [PATCH 4/4] + fix #1700 --- tests/cpp_tests/geometry_converters_test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/cpp_tests/geometry_converters_test.cpp b/tests/cpp_tests/geometry_converters_test.cpp index 8a0125cb9..a549f9aa2 100644 --- a/tests/cpp_tests/geometry_converters_test.cpp +++ b/tests/cpp_tests/geometry_converters_test.cpp @@ -59,7 +59,7 @@ boost::optional linestring_bbox_clipping(mapnik::box2d bbox CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(bbox, backend, sym, t, prj_trans, tr, 1.0); - converter.template set(); + converter.set(); boost::ptr_vector p; if (!mapnik::from_wkt(wkt_in , p)) @@ -99,7 +99,7 @@ boost::optional polygon_bbox_clipping(mapnik::box2d bbox, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(bbox, backend, sym, t, prj_trans, tr, 1.0); - converter.template set(); + converter.set(); boost::ptr_vector p; if (!mapnik::from_wkt(wkt_in , p)) @@ -161,7 +161,6 @@ int main( int, char*[] ) BOOST_TEST_EQ(*result,std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50,50 50))")); } - if (!::boost::detail::test_errors()) { std::clog << "C++ geometry conversions: \x1b[1;32m✓ \x1b[0m\n";