From 4084e670ec521ca0711f527c3bd0a52c7a2a451b Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 16 May 2017 12:02:37 +0000 Subject: [PATCH 1/6] fix closing polygons on reprojection --- include/mapnik/transform_path_adapter.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mapnik/transform_path_adapter.hpp b/include/mapnik/transform_path_adapter.hpp index 52a68e918..17acb0e6b 100644 --- a/include/mapnik/transform_path_adapter.hpp +++ b/include/mapnik/transform_path_adapter.hpp @@ -86,7 +86,7 @@ struct transform_path_adapter while (!ok) { command = geom_.vertex(x,y); - if (command == SEG_END) + if (command == SEG_END || command == SEG_CLOSE) { return command; } From 8d980d434eb43bbba1a0dca99ad6a8ac05fad3a4 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Thu, 18 May 2017 14:49:48 +0000 Subject: [PATCH 2/6] unit tests - closing polygon on reprojection --- .../vertex_adapter/transform_path_adapter.cpp | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 test/unit/vertex_adapter/transform_path_adapter.cpp diff --git a/test/unit/vertex_adapter/transform_path_adapter.cpp b/test/unit/vertex_adapter/transform_path_adapter.cpp new file mode 100644 index 000000000..01de4ee0c --- /dev/null +++ b/test/unit/vertex_adapter/transform_path_adapter.cpp @@ -0,0 +1,117 @@ +#include "catch.hpp" + +#include +#include +#include +#include +#include +#include +#include + +TEST_CASE("transform_path_adapter") { + +SECTION("polygon closing - epsg 2330") { + mapnik::geometry::polygon g; + g.emplace_back(); + auto & exterior = g.back(); + + exterior.emplace_back(88.1844308217992, 69.3553916041731); + exterior.emplace_back(88.1846166524913, 69.3552821191223); + exterior.emplace_back(88.1845090893871, 69.3553454342903); + exterior.emplace_back(88.1844308217992, 69.3553916041731); + + using va_type = mapnik::geometry::polygon_vertex_adapter; + using path_type = mapnik::transform_path_adapter; + + va_type va(g); + mapnik::box2d extent(16310607, 7704513, 16310621, 7704527); + mapnik::view_transform tr(512, 512, extent); + mapnik::projection proj1("+init=epsg:2330"); + mapnik::projection proj2("+init=epsg:4326"); + mapnik::proj_transform prj_trans(proj1, proj2); + path_type path(tr, va, prj_trans); + + double x,y; + unsigned cmd; + + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_MOVETO ); + CHECK( x == Approx(110.4328050613) ); + CHECK( y == Approx(20.2204537392) ); + + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_LINETO ); + CHECK( x == Approx(342.1220560074) ); + CHECK( y == Approx(486.732225963) ); + + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_LINETO ); + CHECK( x == Approx(207.9962329183) ); + CHECK( y == Approx(216.9376912798) ); + + // close + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_CLOSE ); + CHECK( x == 0 ); + CHECK( y == 0 ); + + // end + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_END ); + CHECK( x == 0 ); + CHECK( y == 0 ); +} + +SECTION("polygon closing - epsg 32633") { + mapnik::geometry::polygon g; + g.emplace_back(); + auto & exterior = g.back(); + + exterior.emplace_back(13, 13); + exterior.emplace_back(14, 13); + exterior.emplace_back(14, 14); + exterior.emplace_back(14, 14); + + using va_type = mapnik::geometry::polygon_vertex_adapter; + using path_type = mapnik::transform_path_adapter; + + va_type va(g); + mapnik::box2d extent(166022, 0, 833978, 9329005); + mapnik::view_transform tr(512, 512, extent); + mapnik::projection proj1("+init=epsg:32633"); + mapnik::projection proj2("+init=epsg:4326"); + mapnik::proj_transform prj_trans(proj1, proj2); + path_type path(tr, va, prj_trans); + + double x,y; + unsigned cmd; + + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_MOVETO ); + CHECK( x == Approx(89.7250280748) ); + CHECK( y == Approx(433.0795069885) ); + + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_LINETO ); + CHECK( x == Approx(172.873973465) ); + CHECK( y == Approx(433.1145779929) ); + + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_LINETO ); + CHECK( x == Approx(173.2194366775) ); + CHECK( y == Approx(427.0442504759) ); + + // close + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_CLOSE ); + CHECK( x == 0 ); + CHECK( y == 0 ); + + // end + cmd = path.vertex(&x, &y); + CHECK( cmd == mapnik::SEG_END ); + CHECK( x == 0 ); + CHECK( y == 0 ); +} + +} From 0781f230bed1e6a5af7a694b15f04fd3f5627331 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Wed, 24 May 2017 13:59:44 +0000 Subject: [PATCH 3/6] fix polygon handling --- .../markers_placements/vertext_last.hpp | 65 +++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/include/mapnik/markers_placements/vertext_last.hpp b/include/mapnik/markers_placements/vertext_last.hpp index ff2c8c285..9e7867450 100644 --- a/include/mapnik/markers_placements/vertext_last.hpp +++ b/include/mapnik/markers_placements/vertext_last.hpp @@ -41,42 +41,67 @@ public: return false; } - double x0, y0; - unsigned command0 = this->locator_.vertex(&x0, &y0); + geometry::point p0; + geometry::point p1; + geometry::point p_next; + geometry::point move_to; + unsigned cmd0 = SEG_END; + unsigned cmd1 = SEG_END; + unsigned cmd_next = SEG_END; - if (agg::is_stop(command0)) + while ((cmd_next = this->locator_.vertex(&p_next.x, &p_next.y)) != SEG_END) + { + switch (cmd_next) + { + case SEG_MOVETO: + move_to = p_next; + p0 = p_next; + cmd0 = cmd_next; + break; + case SEG_LINETO: + p1 = p0; + cmd1 = cmd0; + p0 = p_next; + cmd0 = cmd_next; + break; + case SEG_CLOSE: + p1 = p0; + cmd1 = cmd0; + p0 = move_to; + cmd0 = cmd_next; + break; + } + } + + // Empty geometry + if (cmd0 == SEG_END) { this->done_ = true; return false; } - double next_x, next_y; - double x1 = x0, y1 = y0; - unsigned command1 = command0; + // Last point + x = p0.x; + y = p0.y; - while (!agg::is_stop(command0 = this->locator_.vertex(&next_x, &next_y))) + // Line or polygon + if (cmd0 == SEG_LINETO || cmd0 == SEG_CLOSE) { - command1 = command0; - x1 = x0; - y1 = y0; - x0 = next_x; - y0 = next_y; - } - - x = x0; - y = y0; - - if (agg::is_line_to(command1)) - { - angle = std::atan2(y0 - y1, x0 - x1); + angle = std::atan2(p0.y - p1.y, p0.x - p1.x); if (!this->set_direction(angle)) { + this->done_ = true; return false; } } + else + { + angle = 0.0; + } if (!this->push_to_detector(x, y, angle, ignore_placement)) { + this->done_ = true; return false; } From c7561c1dc98aca0bf9daa5074e8c4d8b50ef8bfb Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Wed, 24 May 2017 11:56:11 +0000 Subject: [PATCH 4/6] unit test - vertex-last marker placement --- .../marker_placement_vertex_last.cpp | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 test/unit/symbolizer/marker_placement_vertex_last.cpp diff --git a/test/unit/symbolizer/marker_placement_vertex_last.cpp b/test/unit/symbolizer/marker_placement_vertex_last.cpp new file mode 100644 index 000000000..6bb8d84b6 --- /dev/null +++ b/test/unit/symbolizer/marker_placement_vertex_last.cpp @@ -0,0 +1,126 @@ + +#include "catch.hpp" + +#include +#include +#include + +using namespace mapnik; + +TEST_CASE("marker placement vertex last") { + +SECTION("empty geometry") { + + mapnik::geometry::line_string g; + using va_type = mapnik::geometry::line_string_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_vertex_last_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO }; + + placement_type placement(va, detector, params); + + double x, y, angle; + CHECK( !placement.get_point(x, y, angle, true) ); +} + +SECTION("point") { + + mapnik::geometry::point g(2.0, 3.0); + using va_type = mapnik::geometry::point_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_vertex_last_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO }; + + placement_type placement(va, detector, params); + + double x, y, angle; + + CHECK( placement.get_point(x, y, angle, true) ); + CHECK( x == Approx(2.0) ); + CHECK( y == Approx(3.0) ); + CHECK( angle == Approx(0.0) ); + + CHECK( !placement.get_point(x, y, angle, true) ); +} + +SECTION("line string") { + + mapnik::geometry::line_string g; + g.emplace_back(1.0, 1.0); + g.emplace_back(2.0, 3.0); + using va_type = mapnik::geometry::line_string_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_vertex_last_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO }; + + placement_type placement(va, detector, params); + + double x, y, angle; + + CHECK( placement.get_point(x, y, angle, true) ); + CHECK( x == Approx(2.0) ); + CHECK( y == Approx(3.0) ); + CHECK( angle == Approx(1.1071487178) ); + + CHECK( !placement.get_point(x, y, angle, true) ); +} + +SECTION("polygon") { + + mapnik::geometry::polygon g; + g.emplace_back(); + auto & exterior = g.back(); + exterior.emplace_back(2.0, 3.0); + exterior.emplace_back(1.0, 1.0); + exterior.emplace_back(0.0, 2.0); + exterior.emplace_back(2.0, 3.0); + using va_type = mapnik::geometry::polygon_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_vertex_last_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO }; + + placement_type placement(va, detector, params); + + double x, y, angle; + + CHECK( placement.get_point(x, y, angle, true) ); + CHECK( x == Approx(2.0) ); + CHECK( y == Approx(3.0) ); + CHECK( angle == Approx(0.463647609) ); + + CHECK( !placement.get_point(x, y, angle, true) ); +} + +} From 7590cdabb052bf8cb11aa98ef952df5dc453ce33 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Wed, 24 May 2017 12:04:00 +0000 Subject: [PATCH 5/6] fix typo in file name --- include/mapnik/markers_placement.hpp | 4 ++-- .../{vertext_first.hpp => vertex_first.hpp} | 0 .../markers_placements/{vertext_last.hpp => vertex_last.hpp} | 0 test/unit/symbolizer/marker_placement_vertex_last.cpp | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename include/mapnik/markers_placements/{vertext_first.hpp => vertex_first.hpp} (100%) rename include/mapnik/markers_placements/{vertext_last.hpp => vertex_last.hpp} (100%) diff --git a/include/mapnik/markers_placement.hpp b/include/mapnik/markers_placement.hpp index 1c08bff6a..bdb716f7c 100644 --- a/include/mapnik/markers_placement.hpp +++ b/include/mapnik/markers_placement.hpp @@ -26,8 +26,8 @@ #include #include #include -#include -#include +#include +#include #include namespace mapnik diff --git a/include/mapnik/markers_placements/vertext_first.hpp b/include/mapnik/markers_placements/vertex_first.hpp similarity index 100% rename from include/mapnik/markers_placements/vertext_first.hpp rename to include/mapnik/markers_placements/vertex_first.hpp diff --git a/include/mapnik/markers_placements/vertext_last.hpp b/include/mapnik/markers_placements/vertex_last.hpp similarity index 100% rename from include/mapnik/markers_placements/vertext_last.hpp rename to include/mapnik/markers_placements/vertex_last.hpp diff --git a/test/unit/symbolizer/marker_placement_vertex_last.cpp b/test/unit/symbolizer/marker_placement_vertex_last.cpp index 6bb8d84b6..611385c3a 100644 --- a/test/unit/symbolizer/marker_placement_vertex_last.cpp +++ b/test/unit/symbolizer/marker_placement_vertex_last.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include using namespace mapnik; From 7f11a7ab3087e24b646aab54cd6ed24b396fc476 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Wed, 24 May 2017 12:20:02 +0000 Subject: [PATCH 6/6] update visual test data --- test/data-visual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data-visual b/test/data-visual index 75ecac5c3..85a94e315 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 75ecac5c3bd44f1c9111d9b3fba785a1713f2444 +Subproject commit 85a94e315d0c2d4b3c7248ee9a7fc0197cac2002