Improve angle calculation.
This commit is contained in:
parent
53fa3ff1e1
commit
f20e90a524
2 changed files with 21 additions and 8 deletions
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
pixel_position const& current_position() const { return current_position_; }
|
||||
|
||||
double angle() const;
|
||||
double angle(double width);
|
||||
|
||||
bool next_subpath();
|
||||
bool next_segment();
|
||||
|
@ -154,8 +154,10 @@ vertex_cache::vertex_cache(T &path)
|
|||
}
|
||||
}
|
||||
|
||||
double vertex_cache::angle() const
|
||||
double vertex_cache::angle(double width)
|
||||
{
|
||||
if (width + position_in_segment_ < current_segment_->length)
|
||||
{
|
||||
//Only calculate angle on request as it is expensive
|
||||
if (!angle_valid_)
|
||||
{
|
||||
|
@ -163,6 +165,17 @@ double vertex_cache::angle() const
|
|||
current_segment_->pos.x - segment_starting_point_.x);
|
||||
}
|
||||
return angle_;
|
||||
} else
|
||||
{
|
||||
pixel_position old_pos = current_position_;
|
||||
state s = save_state();
|
||||
forward(width);
|
||||
double angle = atan2(current_position_.y - old_pos.y,
|
||||
current_position_.x - old_pos.x);
|
||||
restore_state(s);
|
||||
current_position_ = old_pos;
|
||||
return angle;
|
||||
}
|
||||
}
|
||||
|
||||
bool vertex_cache::next_subpath()
|
||||
|
|
|
@ -334,7 +334,7 @@ bool placement_finder_ng::single_line_placement(vertex_cache &pp, signed orienta
|
|||
text_line::const_iterator glyph_itr = (*line_itr)->begin(), glyph_end = (*line_itr)->end();
|
||||
for (; glyph_itr != glyph_end; glyph_itr++)
|
||||
{
|
||||
double angle = pp.angle();
|
||||
double angle = pp.angle(glyph_itr->width);
|
||||
std::cout << "angle:" << angle / (2 * M_PI) * 360 << "\n";
|
||||
double sina = sin(angle);
|
||||
double cosa = cos(angle);
|
||||
|
|
Loading…
Reference in a new issue