From 67d8f41a1b272518f85cf296a3c8f6bd27149df2 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Wed, 27 Aug 2014 13:09:20 +0000 Subject: [PATCH] fix angle calculation Conflicts: src/text/vertex_cache.cpp --- include/mapnik/text/vertex_cache.hpp | 1 + src/text/vertex_cache.cpp | 31 +++++++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/mapnik/text/vertex_cache.hpp b/include/mapnik/text/vertex_cache.hpp index 6069d03e7..532e74f62 100644 --- a/include/mapnik/text/vertex_cache.hpp +++ b/include/mapnik/text/vertex_cache.hpp @@ -138,6 +138,7 @@ private: void rewind_subpath(); bool next_segment(); bool previous_segment(); + double current_segment_angle(); // Position as calculated by last move/forward/next call. pixel_position current_position_; // First pixel of current segment. diff --git a/src/text/vertex_cache.cpp b/src/text/vertex_cache.cpp index 942efd98d..5ccc923cc 100644 --- a/src/text/vertex_cache.cpp +++ b/src/text/vertex_cache.cpp @@ -29,29 +29,40 @@ namespace mapnik { +double vertex_cache::current_segment_angle() +{ + return std::atan2(-(current_segment_->pos.y - segment_starting_point_.y), + current_segment_->pos.x - segment_starting_point_.x); +} + double vertex_cache::angle(double width) { - /* IMPORTANT NOTE: See note about coordinate systems in placement_finder::find_point_placement() - * for imformation about why the y axis is inverted! */ + // IMPORTANT NOTE: See note about coordinate systems in placement_finder::find_point_placement() + // for imformation about why the y axis is inverted! double tmp = width + position_in_segment_; if ((tmp <= current_segment_->length) && (tmp >= 0)) { //Only calculate angle on request as it is expensive if (!angle_valid_) { - angle_ = std::atan2(-(current_segment_->pos.y - segment_starting_point_.y), - current_segment_->pos.x - segment_starting_point_.x); + angle_ = current_segment_angle(); } - return width >= 0 ? angle_ : angle_ + M_PI; } else { scoped_state s(*this); - pixel_position const& old_pos = s.get_state().position(); - move(width); - double angle = std::atan2(-(current_position_.y - old_pos.y), - current_position_.x - old_pos.x); - return angle; + if (move(width)) + { + pixel_position const& old_pos = s.get_state().position(); + return std::atan2(-(current_position_.y - old_pos.y), + current_position_.x - old_pos.x); + } + else + { + s.restore(); + angle_ = current_segment_angle(); + } } + return width >= 0 ? angle_ : angle_ + M_PI; } bool vertex_cache::next_subpath()