This commit is contained in:
Jiri Drbalek 2014-08-21 06:42:10 +00:00
parent 69708dc640
commit 1af6f5db10

View file

@ -45,7 +45,8 @@ double vertex_cache::angle(double width)
{ {
angle_ = current_segment_angle(); angle_ = current_segment_angle();
} }
} else }
else
{ {
scoped_state s(*this); scoped_state s(*this);
if (move(width)) if (move(width))
@ -69,7 +70,8 @@ bool vertex_cache::next_subpath()
{ {
current_subpath_ = subpaths_.begin(); current_subpath_ = subpaths_.begin();
initialized_ = true; initialized_ = true;
} else }
else
{ {
current_subpath_++; current_subpath_++;
} }
@ -130,7 +132,9 @@ vertex_cache & vertex_cache::get_offseted(double offset, double region_width)
if (pos != offseted_lines_.end()) if (pos != offseted_lines_.end())
{ {
offseted_line = pos->second; offseted_line = pos->second;
} else { }
else
{
offset_converter<vertex_cache> converter(*this); offset_converter<vertex_cache> converter(*this);
converter.set_offset(offset); converter.set_offset(offset);
offseted_line = vertex_cache_ptr(new vertex_cache(converter)); offseted_line = vertex_cache_ptr(new vertex_cache(converter));
@ -147,7 +151,8 @@ vertex_cache & vertex_cache::get_offseted(double offset, double region_width)
return *offseted_line; return *offseted_line;
} }
inline double dist_sq(pixel_position const &d) { inline double dist_sq(pixel_position const &d)
{
return d.x*d.x + d.y*d.y; return d.x*d.x + d.y*d.y;
} }
@ -161,26 +166,33 @@ double vertex_cache::position_closest_to(pixel_position const &target_pos)
// target position. would be good if there were some kind // target position. would be good if there were some kind
// of prior, or fast test to avoid calculating on each // of prior, or fast test to avoid calculating on each
// segment, but i can't think of one. // segment, but i can't think of one.
for (segment const &seg : current_subpath_->vector) { for (segment const &seg : current_subpath_->vector)
if (first) { {
if (first)
{
old_pos = seg.pos; old_pos = seg.pos;
min_pos = lin_pos; min_pos = lin_pos;
min_dist_sq = dist_sq(target_pos - old_pos); min_dist_sq = dist_sq(target_pos - old_pos);
first = false; first = false;
} else { }
else
{
new_pos = seg.pos; new_pos = seg.pos;
pixel_position d = new_pos - old_pos; pixel_position d = new_pos - old_pos;
if ((d.x != 0.0) || (d.y != 0)) { if ((d.x != 0.0) || (d.y != 0))
{
pixel_position c = target_pos - old_pos; pixel_position c = target_pos - old_pos;
double t = (c.x * d.x + c.y * d.y) / dist_sq(d); double t = (c.x * d.x + c.y * d.y) / dist_sq(d);
if ((t >= 0.0) && (t <= 1.0)) { if ((t >= 0.0) && (t <= 1.0))
{
pixel_position pt = (d * t) + old_pos; pixel_position pt = (d * t) + old_pos;
double pt_dist_sq = dist_sq(target_pos - pt); double pt_dist_sq = dist_sq(target_pos - pt);
if (pt_dist_sq < min_dist_sq) { if (pt_dist_sq < min_dist_sq)
{
min_dist_sq = pt_dist_sq; min_dist_sq = pt_dist_sq;
min_pos = lin_pos + seg.length * t; min_pos = lin_pos + seg.length * t;
} }
@ -191,7 +203,8 @@ double vertex_cache::position_closest_to(pixel_position const &target_pos)
lin_pos += seg.length; lin_pos += seg.length;
double end_dist_sq = dist_sq(target_pos - old_pos); double end_dist_sq = dist_sq(target_pos - old_pos);
if (end_dist_sq < min_dist_sq) { if (end_dist_sq < min_dist_sq)
{
min_dist_sq = end_dist_sq; min_dist_sq = end_dist_sq;
min_pos = lin_pos; min_pos = lin_pos;
} }