mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 07:35:57 +08:00
Fix of ThickPolyline::clip_end()
This commit is contained in:
parent
6734ad6c3c
commit
9ecf1e4134
@ -267,29 +267,34 @@ ThickLines ThickPolyline::thicklines() const
|
|||||||
// Removes the given distance from the end of the ThickPolyline
|
// Removes the given distance from the end of the ThickPolyline
|
||||||
void ThickPolyline::clip_end(double distance)
|
void ThickPolyline::clip_end(double distance)
|
||||||
{
|
{
|
||||||
while (distance > 0) {
|
if (! this->empty()) {
|
||||||
Vec2d last_point = this->last_point().cast<double>();
|
assert(this->width.size() == (this->points.size() - 1) * 2);
|
||||||
coordf_t last_width = this->width.back();
|
while (distance > 0) {
|
||||||
this->points.pop_back();
|
Vec2d last_point = this->last_point().cast<double>();
|
||||||
this->width.pop_back();
|
this->points.pop_back();
|
||||||
if (this->points.empty())
|
if (this->points.empty()) {
|
||||||
break;
|
assert(this->width.empty());
|
||||||
|
break;
|
||||||
Vec2d vec = this->last_point().cast<double>() - last_point;
|
}
|
||||||
coordf_t width_diff = this->width.back() - last_width;
|
coordf_t last_width = this->width.back();
|
||||||
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();
|
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)
|
void ThickPolyline::start_at_index(int index)
|
||||||
|
@ -187,6 +187,7 @@ struct ThickPolyline {
|
|||||||
const Point& last_point() const { return this->points.back(); }
|
const Point& last_point() const { return this->points.back(); }
|
||||||
size_t size() const { return this->points.size(); }
|
size_t size() const { return this->points.size(); }
|
||||||
bool is_valid() const { return this->points.size() >= 2; }
|
bool is_valid() const { return this->points.size() >= 2; }
|
||||||
|
bool empty() const { return this->points.empty(); }
|
||||||
double length() const { return Slic3r::length(this->points); }
|
double length() const { return Slic3r::length(this->points); }
|
||||||
|
|
||||||
void clear() { this->points.clear(); this->width.clear(); }
|
void clear() { this->points.clear(); this->width.clear(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user