From 611eb6e7a3c7859e6ca673b0abb6997000d1ed68 Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Thu, 21 May 2015 11:23:32 -0500 Subject: [PATCH 1/5] Changed from numeric casts to static casts --- include/mapnik/geometry_strategy.hpp | 48 ++----------------- include/mapnik/proj_strategy.hpp | 24 +--------- include/mapnik/view_strategy.hpp | 4 +- test/unit/geometry/geometry_strategy_test.cpp | 2 +- 4 files changed, 9 insertions(+), 69 deletions(-) diff --git a/include/mapnik/geometry_strategy.hpp b/include/mapnik/geometry_strategy.hpp index 0a322ddc0..eaa19257b 100644 --- a/include/mapnik/geometry_strategy.hpp +++ b/include/mapnik/geometry_strategy.hpp @@ -155,28 +155,8 @@ struct scale_strategy using p2_type = typename boost::geometry::coordinate_type::type; double x = (boost::geometry::get<0>(p1) * scale_) + offset_; double y = (boost::geometry::get<1>(p1) * scale_) + offset_; - try { - boost::geometry::set<0>(p2, boost::numeric_cast(x)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::max()); - } - try { - boost::geometry::set<1>(p2, boost::numeric_cast(y)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::max()); - } + boost::geometry::set<0>(p2, static_cast(x)); + boost::geometry::set<1>(p2, static_cast(y)); return true; } @@ -205,28 +185,8 @@ struct scale_rounding_strategy using p2_type = typename boost::geometry::coordinate_type::type; double x = (boost::geometry::get<0>(p1) * scale_) + offset_; double y = (boost::geometry::get<1>(p1) * scale_) + offset_; - try { - boost::geometry::set<0>(p2, util::rounding_cast(x)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::max()); - } - try { - boost::geometry::set<1>(p2, util::rounding_cast(y)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::max()); - } + boost::geometry::set<0>(p2, static_cast(std::floor(x + 0.5))); + boost::geometry::set<1>(p2, static_cast(std::floor(y + 0.5))); return true; } diff --git a/include/mapnik/proj_strategy.hpp b/include/mapnik/proj_strategy.hpp index 69ef18a1c..3684ad988 100644 --- a/include/mapnik/proj_strategy.hpp +++ b/include/mapnik/proj_strategy.hpp @@ -108,28 +108,8 @@ struct proj_backward_strategy double y = boost::geometry::get<1>(p1); double z = 0.0; if (!prj_trans_.backward(x, y, z)) return false; - try { - boost::geometry::set<0>(p2, boost::numeric_cast(x)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::max()); - } - try { - boost::geometry::set<1>(p2, boost::numeric_cast(y)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::max()); - } + boost::geometry::set<0>(p2, static_cast(x)); + boost::geometry::set<1>(p2, static_cast(y)); return true; } diff --git a/include/mapnik/view_strategy.hpp b/include/mapnik/view_strategy.hpp index a984dc4d9..7bddb9b18 100644 --- a/include/mapnik/view_strategy.hpp +++ b/include/mapnik/view_strategy.hpp @@ -74,8 +74,8 @@ struct unview_strategy double x = boost::geometry::get<0>(p1); double y = boost::geometry::get<1>(p1); tr_.backward(&x,&y); - boost::geometry::set<0>(p2, boost::numeric_cast(x)); - boost::geometry::set<1>(p2, boost::numeric_cast(y)); + boost::geometry::set<0>(p2, static_cast(x)); + boost::geometry::set<1>(p2, static_cast(y)); return true; } diff --git a/test/unit/geometry/geometry_strategy_test.cpp b/test/unit/geometry/geometry_strategy_test.cpp index 124b343bf..74d3cb344 100644 --- a/test/unit/geometry/geometry_strategy_test.cpp +++ b/test/unit/geometry/geometry_strategy_test.cpp @@ -162,7 +162,7 @@ SECTION("scaling strategies - double to double") { // Not the rounding doesn't apply because not casting to ints scale_rounding_strategy ss(0.5, -2.0); point p(-90.3, 35.5); - point r(-47.15, 15.75); + point r(-47.0, 16.0); point o = transform(p, ss); assert_g_equal(r, o); } From 506d2f435f277942b51ac279b2d3326f015313ce Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Thu, 21 May 2015 14:01:06 -0500 Subject: [PATCH 2/5] Added vector tile strategy --- include/mapnik/proj_strategy.hpp | 24 +---- include/mapnik/vector_tile_strategy.hpp | 88 +++++++++++++++++++ test/unit/geometry/geometry_strategy_test.cpp | 12 +++ 3 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 include/mapnik/vector_tile_strategy.hpp diff --git a/include/mapnik/proj_strategy.hpp b/include/mapnik/proj_strategy.hpp index 3684ad988..688e6d331 100644 --- a/include/mapnik/proj_strategy.hpp +++ b/include/mapnik/proj_strategy.hpp @@ -59,28 +59,8 @@ struct proj_strategy double y = boost::geometry::get<1>(p1); double z = 0.0; if (!prj_trans_.forward(x, y, z)) return false; - try { - boost::geometry::set<0>(p2, boost::numeric_cast(x)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<0>(p2, std::numeric_limits::max()); - } - try { - boost::geometry::set<1>(p2, boost::numeric_cast(y)); - } - catch(boost::numeric::negative_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::min()); - } - catch(boost::numeric::positive_overflow&) - { - boost::geometry::set<1>(p2, std::numeric_limits::max()); - } + boost::geometry::set<0>(p2, static_cast(x)); + boost::geometry::set<1>(p2, static_cast(y)); return true; } diff --git a/include/mapnik/vector_tile_strategy.hpp b/include/mapnik/vector_tile_strategy.hpp new file mode 100644 index 000000000..2f7bafdcd --- /dev/null +++ b/include/mapnik/vector_tile_strategy.hpp @@ -0,0 +1,88 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 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_VECTOR_TILE_STRATEGY_HPP +#define MAPNIK_VECTOR_TILE_STRATEGY_HPP + +// mapnik +#include +#include +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-local-typedef" +#include +#include +#include +#pragma GCC diagnostic pop + + +namespace mapnik { + +namespace geometry { + +struct vector_tile_strategy +{ + vector_tile_strategy(proj_transform const& prj_trans, + view_transform const& tr, + double scaling) + : prj_trans_(prj_trans), + tr_(tr), + scaling_(scaling) {} + + template + inline bool apply(P1 const& p1, P2 & p2) const + { + using p2_type = typename boost::geometry::coordinate_type::type; + double x = boost::geometry::get<0>(p1); + double y = boost::geometry::get<1>(p1); + double z = 0.0; + if (!prj_trans_.backward(x, y, z)) return false; + tr_.forward(&x,&y); + x = x * scaling_; + y = y * scaling_; + x = std::floor(x + 0.5); + y = std::floor(y + 0.5); + boost::geometry::set<0>(p2, static_cast(x)); + boost::geometry::set<1>(p2, static_cast(y)); + return true; + } + + template + inline P2 execute(P1 const& p1, bool & status) const + { + P2 p2; + status = apply(p1, p2); + return p2; + } + + proj_transform const& prj_trans_; + view_transform const& tr_; + double const scaling_; +}; + +} +} + +#endif // MAPNIK_VECTOR_TILE_STRATEGY_HPP diff --git a/test/unit/geometry/geometry_strategy_test.cpp b/test/unit/geometry/geometry_strategy_test.cpp index 74d3cb344..be705ca82 100644 --- a/test/unit/geometry/geometry_strategy_test.cpp +++ b/test/unit/geometry/geometry_strategy_test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include TEST_CASE("geometry strategy tests") { @@ -99,6 +100,17 @@ SECTION("proj and view strategy") { //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } + { + // Test vector tile strategy + mapnik::geometry::vector_tile_strategy vs(proj_trans_rev, vt, 16); + geometry p1(std::move(point(-97.553098,35.523105))); + point r1(938 , 1615); + geometry p2 = transform(p1, vs); + REQUIRE(p2.is >()); + point p3 = mapnik::util::get >(p2); + //std::cout << p3.x << " , " << p3.y << std::endl; + assert_g_equal(r1, p3); + } { // Test the entire process in reverse! This would be like converting a vector tile coordinate to 4326. mapnik::geometry::scale_strategy ss(1.0/16.0); From 85e2b53490b3d7baa929b30c5a02e2341494a9a7 Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Tue, 26 May 2015 15:52:27 -0500 Subject: [PATCH 3/5] Changed from floor to round --- include/mapnik/geometry_strategy.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mapnik/geometry_strategy.hpp b/include/mapnik/geometry_strategy.hpp index eaa19257b..cc4121e60 100644 --- a/include/mapnik/geometry_strategy.hpp +++ b/include/mapnik/geometry_strategy.hpp @@ -185,8 +185,8 @@ struct scale_rounding_strategy using p2_type = typename boost::geometry::coordinate_type::type; double x = (boost::geometry::get<0>(p1) * scale_) + offset_; double y = (boost::geometry::get<1>(p1) * scale_) + offset_; - boost::geometry::set<0>(p2, static_cast(std::floor(x + 0.5))); - boost::geometry::set<1>(p2, static_cast(std::floor(y + 0.5))); + boost::geometry::set<0>(p2, static_cast(std::round(x))); + boost::geometry::set<1>(p2, static_cast(std::round(y))); return true; } From 3768702699e810b45b7bc197db4b06dd51acb356 Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Tue, 26 May 2015 16:03:25 -0500 Subject: [PATCH 4/5] Updated unit tests --- test/unit/geometry/geometry_strategy_test.cpp | 53 ------------------- 1 file changed, 53 deletions(-) diff --git a/test/unit/geometry/geometry_strategy_test.cpp b/test/unit/geometry/geometry_strategy_test.cpp index be705ca82..7f2caa10e 100644 --- a/test/unit/geometry/geometry_strategy_test.cpp +++ b/test/unit/geometry/geometry_strategy_test.cpp @@ -30,7 +30,6 @@ SECTION("proj and view strategy") { point p1(-97.553098,35.523105); point r1(-1.08596e+07, 4.2352e+06); point p3 = transform(p1, ps); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -38,7 +37,6 @@ SECTION("proj and view strategy") { point p1(-1.08596e+07, 4.2352e+06); point r1(58.6287 , 100.945); point p3 = transform(p1, vs); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } @@ -49,7 +47,6 @@ SECTION("proj and view strategy") { using sg_type = strategy_group; sg_type sg(vs); point p3 = transform(p1, sg); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } @@ -60,7 +57,6 @@ SECTION("proj and view strategy") { point p1(-97.553098,35.523105); point r1(58.6287 , 100.945); point p3 = transform(p1, sg); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -72,7 +68,6 @@ SECTION("proj and view strategy") { geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -84,7 +79,6 @@ SECTION("proj and view strategy") { geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -97,7 +91,6 @@ SECTION("proj and view strategy") { geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -108,7 +101,6 @@ SECTION("proj and view strategy") { geometry p2 = transform(p1, vs); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -121,7 +113,6 @@ SECTION("proj and view strategy") { geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -134,7 +125,6 @@ SECTION("proj and view strategy") { geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } { @@ -147,7 +137,6 @@ SECTION("proj and view strategy") { geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); - //std::cout << p3.x << " , " << p3.y << std::endl; assert_g_equal(r1, p3); } @@ -171,7 +160,6 @@ SECTION("scaling strategies - double to double") { assert_g_equal(r, o); } { - // Not the rounding doesn't apply because not casting to ints scale_rounding_strategy ss(0.5, -2.0); point p(-90.3, 35.5); point r(-47.0, 16.0); @@ -205,47 +193,6 @@ SECTION("scaling strategies - double to int64") { point o = transform(p, ss); assert_g_equal(r, o); } - { - // Test underflow and overflow - std::int64_t min = std::numeric_limits::min(); - std::int64_t max = std::numeric_limits::max(); - scale_strategy ss(1.0E100); - point p(-90.3, 35.5); - point r(min, max); - point o = transform(p, ss); - assert_g_equal(r, o); - } - { - // Test underflow and overflow - std::int64_t min = std::numeric_limits::min(); - std::int64_t max = std::numeric_limits::max(); - scale_rounding_strategy ss(1.0E100); - point p(-90.3, 35.5); - point r(min, max); - point o = transform(p, ss); - assert_g_equal(r, o); - } - { - // Test overrflow and underflow - std::int64_t min = std::numeric_limits::min(); - std::int64_t max = std::numeric_limits::max(); - scale_strategy ss(1.0E100); - point p(90.3, -35.5); - point r(max, min); - point o = transform(p, ss); - assert_g_equal(r, o); - } - { - // Test overflow and underflow - std::int64_t min = std::numeric_limits::min(); - std::int64_t max = std::numeric_limits::max(); - scale_rounding_strategy ss(1.0E100); - point p(90.3, -35.5); - point r(max, min); - point o = transform(p, ss); - assert_g_equal(r, o); - } - } // END SECTION } // END TEST CASE From ee551cd949ac1f9e5e66d99f8ad6ead55ae05d8c Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Tue, 26 May 2015 16:18:10 -0500 Subject: [PATCH 5/5] Removed vector tile strategy --- include/mapnik/vector_tile_strategy.hpp | 88 ------------------- test/unit/geometry/geometry_strategy_test.cpp | 11 --- 2 files changed, 99 deletions(-) delete mode 100644 include/mapnik/vector_tile_strategy.hpp diff --git a/include/mapnik/vector_tile_strategy.hpp b/include/mapnik/vector_tile_strategy.hpp deleted file mode 100644 index 2f7bafdcd..000000000 --- a/include/mapnik/vector_tile_strategy.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2014 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_VECTOR_TILE_STRATEGY_HPP -#define MAPNIK_VECTOR_TILE_STRATEGY_HPP - -// mapnik -#include -#include -#include -#include - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wunused-local-typedef" -#include -#include -#include -#pragma GCC diagnostic pop - - -namespace mapnik { - -namespace geometry { - -struct vector_tile_strategy -{ - vector_tile_strategy(proj_transform const& prj_trans, - view_transform const& tr, - double scaling) - : prj_trans_(prj_trans), - tr_(tr), - scaling_(scaling) {} - - template - inline bool apply(P1 const& p1, P2 & p2) const - { - using p2_type = typename boost::geometry::coordinate_type::type; - double x = boost::geometry::get<0>(p1); - double y = boost::geometry::get<1>(p1); - double z = 0.0; - if (!prj_trans_.backward(x, y, z)) return false; - tr_.forward(&x,&y); - x = x * scaling_; - y = y * scaling_; - x = std::floor(x + 0.5); - y = std::floor(y + 0.5); - boost::geometry::set<0>(p2, static_cast(x)); - boost::geometry::set<1>(p2, static_cast(y)); - return true; - } - - template - inline P2 execute(P1 const& p1, bool & status) const - { - P2 p2; - status = apply(p1, p2); - return p2; - } - - proj_transform const& prj_trans_; - view_transform const& tr_; - double const scaling_; -}; - -} -} - -#endif // MAPNIK_VECTOR_TILE_STRATEGY_HPP diff --git a/test/unit/geometry/geometry_strategy_test.cpp b/test/unit/geometry/geometry_strategy_test.cpp index 7f2caa10e..a5fe01ffe 100644 --- a/test/unit/geometry/geometry_strategy_test.cpp +++ b/test/unit/geometry/geometry_strategy_test.cpp @@ -9,7 +9,6 @@ #include #include #include -#include TEST_CASE("geometry strategy tests") { @@ -93,16 +92,6 @@ SECTION("proj and view strategy") { point p3 = mapnik::util::get >(p2); assert_g_equal(r1, p3); } - { - // Test vector tile strategy - mapnik::geometry::vector_tile_strategy vs(proj_trans_rev, vt, 16); - geometry p1(std::move(point(-97.553098,35.523105))); - point r1(938 , 1615); - geometry p2 = transform(p1, vs); - REQUIRE(p2.is >()); - point p3 = mapnik::util::get >(p2); - assert_g_equal(r1, p3); - } { // Test the entire process in reverse! This would be like converting a vector tile coordinate to 4326. mapnik::geometry::scale_strategy ss(1.0/16.0);