Fix of ThickPolyline::clip_end()
This commit is contained in:
parent
6734ad6c3c
commit
9ecf1e4134
2 changed files with 26 additions and 20 deletions
|
@ -267,29 +267,34 @@ ThickLines ThickPolyline::thicklines() const
|
|||
// Removes the given distance from the end of the ThickPolyline
|
||||
void ThickPolyline::clip_end(double distance)
|
||||
{
|
||||
while (distance > 0) {
|
||||
Vec2d last_point = this->last_point().cast<double>();
|
||||
coordf_t last_width = this->width.back();
|
||||
this->points.pop_back();
|
||||
this->width.pop_back();
|
||||
if (this->points.empty())
|
||||
break;
|
||||
|
||||
Vec2d vec = this->last_point().cast<double>() - last_point;
|
||||
coordf_t width_diff = this->width.back() - last_width;
|
||||
double vec_length_sqr = vec.squaredNorm();
|
||||
if (vec_length_sqr > distance * distance) {
|
||||
double t = (distance / std::sqrt(vec_length_sqr));
|
||||
this->points.emplace_back((last_point + vec * t).cast<coord_t>());
|
||||
this->width.emplace_back(last_width + width_diff * t);
|
||||
assert(this->width.size() == (this->points.size() - 1) * 2);
|
||||
return;
|
||||
} else
|
||||
if (! this->empty()) {
|
||||
assert(this->width.size() == (this->points.size() - 1) * 2);
|
||||
while (distance > 0) {
|
||||
Vec2d last_point = this->last_point().cast<double>();
|
||||
this->points.pop_back();
|
||||
if (this->points.empty()) {
|
||||
assert(this->width.empty());
|
||||
break;
|
||||
}
|
||||
coordf_t last_width = this->width.back();
|
||||
this->width.pop_back();
|
||||
|
||||
distance -= std::sqrt(vec_length_sqr);
|
||||
Vec2d vec = this->last_point().cast<double>() - last_point;
|
||||
coordf_t width_diff = this->width.back() - last_width;
|
||||
double vec_length_sqr = vec.squaredNorm();
|
||||
if (vec_length_sqr > distance * distance) {
|
||||
double t = (distance / std::sqrt(vec_length_sqr));
|
||||
this->points.emplace_back((last_point + vec * t).cast<coord_t>());
|
||||
this->width.emplace_back(last_width + width_diff * t);
|
||||
assert(this->width.size() == (this->points.size() - 1) * 2);
|
||||
return;
|
||||
} else
|
||||
this->width.pop_back();
|
||||
|
||||
distance -= std::sqrt(vec_length_sqr);
|
||||
}
|
||||
}
|
||||
assert(this->width.size() == (this->points.size() - 1) * 2);
|
||||
assert(this->points.empty() ? this->width.empty() : this->width.size() == (this->points.size() - 1) * 2);
|
||||
}
|
||||
|
||||
void ThickPolyline::start_at_index(int index)
|
||||
|
|
|
@ -187,6 +187,7 @@ struct ThickPolyline {
|
|||
const Point& last_point() const { return this->points.back(); }
|
||||
size_t size() const { return this->points.size(); }
|
||||
bool is_valid() const { return this->points.size() >= 2; }
|
||||
bool empty() const { return this->points.empty(); }
|
||||
double length() const { return Slic3r::length(this->points); }
|
||||
|
||||
void clear() { this->points.clear(); this->width.clear(); }
|
||||
|
|
Loading…
Reference in a new issue