mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 18:18:57 +08:00
Add conversion into Lines for ThickPolyline.
This commit is contained in:
parent
5cc2e5eb0b
commit
2cba980a8b
@ -194,7 +194,7 @@ template<class L> bool intersection(const L &l1, const L &l2, Vec<Dim<L>, Scalar
|
||||
class Line
|
||||
{
|
||||
public:
|
||||
Line() {}
|
||||
Line() = default;
|
||||
Line(const Point& _a, const Point& _b) : a(_a), b(_b) {}
|
||||
explicit operator Lines() const { Lines lines; lines.emplace_back(*this); return lines; }
|
||||
void scale(double factor) { this->a *= factor; this->b *= factor; }
|
||||
|
@ -297,6 +297,44 @@ std::pair<int, Point> foot_pt(const Points &polyline, const Point &pt)
|
||||
return std::make_pair(int(it_proj - polyline.begin()) - 1, foot_pt_min);
|
||||
}
|
||||
|
||||
size_t total_lines_count(const ThickPolylines &thick_polylines) {
|
||||
size_t lines_cnt = 0;
|
||||
for (const ThickPolyline &thick_polyline : thick_polylines) {
|
||||
if (thick_polyline.points.size() > 1) {
|
||||
lines_cnt += thick_polyline.points.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return lines_cnt;
|
||||
}
|
||||
|
||||
Lines to_lines(const ThickPolyline &thick_polyline) {
|
||||
Lines lines;
|
||||
if (thick_polyline.points.size() >= 2) {
|
||||
lines.reserve(thick_polyline.points.size() - 1);
|
||||
|
||||
for (Points::const_iterator it = thick_polyline.points.begin(); it != thick_polyline.points.end() - 1; ++it) {
|
||||
lines.emplace_back(*it, *(it + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
Lines to_lines(const ThickPolylines &thick_polylines) {
|
||||
const size_t lines_cnt = total_lines_count(thick_polylines);
|
||||
|
||||
Lines lines;
|
||||
lines.reserve(lines_cnt);
|
||||
for (const ThickPolyline &thick_polyline : thick_polylines) {
|
||||
for (Points::const_iterator it = thick_polyline.points.begin(); it != thick_polyline.points.end() - 1; ++it) {
|
||||
lines.emplace_back(*it, *(it + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
ThickLines ThickPolyline::thicklines() const
|
||||
{
|
||||
ThickLines lines;
|
||||
|
@ -119,30 +119,40 @@ inline double total_length(const Polylines &polylines) {
|
||||
return total;
|
||||
}
|
||||
|
||||
inline Lines to_lines(const Polyline &poly)
|
||||
{
|
||||
inline size_t total_lines_count(const Polylines &polylines) {
|
||||
size_t lines_cnt = 0;
|
||||
for (const Polyline &polyline : polylines) {
|
||||
if (polyline.points.size() > 1) {
|
||||
lines_cnt += polyline.points.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return lines_cnt;
|
||||
}
|
||||
|
||||
inline Lines to_lines(const Polyline &poly) {
|
||||
Lines lines;
|
||||
if (poly.points.size() >= 2) {
|
||||
lines.reserve(poly.points.size() - 1);
|
||||
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
|
||||
lines.push_back(Line(*it, *(it + 1)));
|
||||
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end() - 1; ++it) {
|
||||
lines.emplace_back(*it, *(it + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
inline Lines to_lines(const Polylines &polys)
|
||||
{
|
||||
size_t n_lines = 0;
|
||||
for (size_t i = 0; i < polys.size(); ++ i)
|
||||
if (polys[i].points.size() > 1)
|
||||
n_lines += polys[i].points.size() - 1;
|
||||
inline Lines to_lines(const Polylines &polylines) {
|
||||
const size_t lines_cnt = total_lines_count(polylines);
|
||||
|
||||
Lines lines;
|
||||
lines.reserve(n_lines);
|
||||
for (size_t i = 0; i < polys.size(); ++ i) {
|
||||
const Polyline &poly = polys[i];
|
||||
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
|
||||
lines.push_back(Line(*it, *(it + 1)));
|
||||
lines.reserve(lines_cnt);
|
||||
for (const Polyline &polyline : polylines) {
|
||||
for (Points::const_iterator it = polyline.points.begin(); it != polyline.points.end() - 1; ++it) {
|
||||
lines.emplace_back(*it, *(it + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
@ -251,6 +261,11 @@ inline ThickPolylines to_thick_polylines(Polylines &&polylines, const coordf_t w
|
||||
return out;
|
||||
}
|
||||
|
||||
size_t total_lines_count(const ThickPolylines &thick_polylines);
|
||||
|
||||
Lines to_lines(const ThickPolyline &thick_polyline);
|
||||
Lines to_lines(const ThickPolylines &thick_polylines);
|
||||
|
||||
class Polyline3 : public MultiPoint3
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user