From fef3d2215436c579a0077a1851a297f44dc77fe9 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 5 Sep 2014 16:33:20 +0100 Subject: [PATCH] support avoid-edges in all markers placements --- include/mapnik/markers_placements/interior.hpp | 5 ++++- include/mapnik/markers_placements/line.hpp | 5 +++++ include/mapnik/markers_placements/vertext_first.hpp | 5 ++++- include/mapnik/markers_placements/vertext_last.hpp | 9 +++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/mapnik/markers_placements/interior.hpp b/include/mapnik/markers_placements/interior.hpp index efd52d392..6d36c44ae 100644 --- a/include/mapnik/markers_placements/interior.hpp +++ b/include/mapnik/markers_placements/interior.hpp @@ -69,7 +69,10 @@ public: angle = 0; box2d box = this->perform_transform(angle, x, y); - + if (this->params_.avoid_edges && !this->detector_.extent().contains(box)) + { + return false; + } if (!this->params_.allow_overlap && !this->detector_.has_placement(box)) { return false; diff --git a/include/mapnik/markers_placements/line.hpp b/include/mapnik/markers_placements/line.hpp index 66cb88603..3c829e787 100644 --- a/include/mapnik/markers_placements/line.hpp +++ b/include/mapnik/markers_placements/line.hpp @@ -172,6 +172,11 @@ public: x = last_x + dx * (spacing_left_ / segment_length); y = last_y + dy * (spacing_left_ / segment_length); box2d box = this->perform_transform(angle, x, y); + if (this->params_.avoid_edges && !this->detector_.extent().contains(box)) + { + set_spacing_left(spacing_left_ + spacing_ * this->params_.max_error / 10.0); + continue; + } if (!this->params_.allow_overlap && !this->detector_.has_placement(box)) { //10.0 is the approxmiate number of positions tried and choosen arbitrarily diff --git a/include/mapnik/markers_placements/vertext_first.hpp b/include/mapnik/markers_placements/vertext_first.hpp index 2c562a8f3..8ac11e2b4 100644 --- a/include/mapnik/markers_placements/vertext_first.hpp +++ b/include/mapnik/markers_placements/vertext_first.hpp @@ -68,7 +68,10 @@ public: } box2d box = this->perform_transform(angle, x, y); - + if (this->params_.avoid_edges && !this->detector_.extent().contains(box)) + { + return false; + } if (!this->params_.allow_overlap && !this->detector_.has_placement(box)) { return false; diff --git a/include/mapnik/markers_placements/vertext_last.hpp b/include/mapnik/markers_placements/vertext_last.hpp index 883e5b6b8..3268c7c64 100644 --- a/include/mapnik/markers_placements/vertext_last.hpp +++ b/include/mapnik/markers_placements/vertext_last.hpp @@ -32,9 +32,7 @@ class markers_vertex_last_placement : public markers_point_placement(locator, detector, params) - { - } + : markers_point_placement(locator, detector, params) {} bool get_point(double &x, double &y, double &angle, bool ignore_placement) { @@ -74,7 +72,10 @@ public: } box2d box = this->perform_transform(angle, x, y); - + if (this->params_.avoid_edges && !this->detector_.extent().contains(box)) + { + return false; + } if (!this->params_.allow_overlap && !this->detector_.has_placement(box)) { return false;