fix angle calculation

Conflicts:
	src/text/vertex_cache.cpp
This commit is contained in:
Jiri Drbalek 2014-08-27 13:09:20 +00:00 committed by Dane Springmeyer
parent 21d213a653
commit 67d8f41a1b
2 changed files with 22 additions and 10 deletions

View file

@ -138,6 +138,7 @@ private:
void rewind_subpath(); void rewind_subpath();
bool next_segment(); bool next_segment();
bool previous_segment(); bool previous_segment();
double current_segment_angle();
// Position as calculated by last move/forward/next call. // Position as calculated by last move/forward/next call.
pixel_position current_position_; pixel_position current_position_;
// First pixel of current segment. // First pixel of current segment.

View file

@ -29,29 +29,40 @@
namespace mapnik 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) double vertex_cache::angle(double width)
{ {
/* IMPORTANT NOTE: See note about coordinate systems in placement_finder::find_point_placement() // IMPORTANT NOTE: See note about coordinate systems in placement_finder::find_point_placement()
* for imformation about why the y axis is inverted! */ // for imformation about why the y axis is inverted!
double tmp = width + position_in_segment_; double tmp = width + position_in_segment_;
if ((tmp <= current_segment_->length) && (tmp >= 0)) if ((tmp <= current_segment_->length) && (tmp >= 0))
{ {
//Only calculate angle on request as it is expensive //Only calculate angle on request as it is expensive
if (!angle_valid_) if (!angle_valid_)
{ {
angle_ = std::atan2(-(current_segment_->pos.y - segment_starting_point_.y), angle_ = current_segment_angle();
current_segment_->pos.x - segment_starting_point_.x);
} }
return width >= 0 ? angle_ : angle_ + M_PI;
} else } else
{ {
scoped_state s(*this); scoped_state s(*this);
if (move(width))
{
pixel_position const& old_pos = s.get_state().position(); pixel_position const& old_pos = s.get_state().position();
move(width); return std::atan2(-(current_position_.y - old_pos.y),
double angle = std::atan2(-(current_position_.y - old_pos.y),
current_position_.x - old_pos.x); current_position_.x - old_pos.x);
return angle;
} }
else
{
s.restore();
angle_ = current_segment_angle();
}
}
return width >= 0 ? angle_ : angle_ + M_PI;
} }
bool vertex_cache::next_subpath() bool vertex_cache::next_subpath()