Fix of ThickPolyline::clip_end()

This commit is contained in:
Vojtech Bubnik 2023-03-09 14:46:15 +01:00
parent 6734ad6c3c
commit 9ecf1e4134
2 changed files with 26 additions and 20 deletions

View File

@ -267,13 +267,17 @@ ThickLines ThickPolyline::thicklines() const
// Removes the given distance from the end of the ThickPolyline
void ThickPolyline::clip_end(double distance)
{
if (! this->empty()) {
assert(this->width.size() == (this->points.size() - 1) * 2);
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())
if (this->points.empty()) {
assert(this->width.empty());
break;
}
coordf_t last_width = this->width.back();
this->width.pop_back();
Vec2d vec = this->last_point().cast<double>() - last_point;
coordf_t width_diff = this->width.back() - last_width;
@ -289,7 +293,8 @@ void ThickPolyline::clip_end(double distance)
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)

View File

@ -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(); }