PrusaSlicer-NonPlainar/xs/src/libslic3r/Polyline.hpp

128 lines
3.8 KiB
C++
Raw Normal View History

2013-07-14 14:09:54 +00:00
#ifndef slic3r_Polyline_hpp_
#define slic3r_Polyline_hpp_
#include "libslic3r.h"
#include "Line.hpp"
#include "MultiPoint.hpp"
2014-11-15 22:06:15 +00:00
#include <string>
2016-03-19 14:33:58 +00:00
#include <vector>
2013-07-14 14:09:54 +00:00
namespace Slic3r {
class Polyline;
2016-03-19 14:33:58 +00:00
class ThickPolyline;
typedef std::vector<Polyline> Polylines;
2016-03-19 14:33:58 +00:00
typedef std::vector<ThickPolyline> ThickPolylines;
class Polyline : public MultiPoint {
public:
Polyline() {};
Polyline(const Polyline &other) : MultiPoint(other.points) {}
Polyline(Polyline &&other) : MultiPoint(std::move(other.points)) {}
Polyline& operator=(const Polyline &other) { points = other.points; return *this; }
Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; }
void append(const Point &point) { this->points.push_back(point); }
void append(const Points &src) { this->append(src.begin(), src.end()); }
void append(const Points::const_iterator &begin, const Points::const_iterator &end) { this->points.insert(this->points.end(), begin, end); }
void append(Points &&src)
{
if (this->points.empty()) {
this->points = std::move(src);
} else {
this->points.insert(this->points.end(), src.begin(), src.end());
src.clear();
}
}
void append(const Polyline &src)
{
points.insert(points.end(), src.points.begin(), src.points.end());
}
void append(Polyline &&src)
{
if (this->points.empty()) {
this->points = std::move(src.points);
} else {
this->points.insert(this->points.end(), src.points.begin(), src.points.end());
src.points.clear();
}
}
operator Polylines() const;
2014-11-15 21:41:22 +00:00
operator Line() const;
Point last_point() const;
Point leftmost_point() const;
2016-03-19 14:33:58 +00:00
virtual Lines lines() const;
void clip_end(double distance);
void clip_start(double distance);
void extend_end(double distance);
void extend_start(double distance);
Points equally_spaced_points(double distance) const;
2013-11-22 01:16:10 +00:00
void simplify(double tolerance);
template <class T> void simplify_by_visibility(const T &area);
void split_at(const Point &point, Polyline* p1, Polyline* p2) const;
2014-11-15 22:06:15 +00:00
bool is_straight() const;
std::string wkt() const;
2013-07-14 14:09:54 +00:00
};
extern BoundingBox get_extents(const Polyline &polyline);
extern BoundingBox get_extents(const Polylines &polylines);
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)));
}
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;
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)));
}
return lines;
}
inline void polylines_append(Polylines &dst, const Polylines &src)
{
dst.insert(dst.end(), src.begin(), src.end());
}
inline void polylines_append(Polylines &dst, Polylines &&src)
{
if (dst.empty()) {
dst = std::move(src);
} else {
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
src.clear();
}
}
bool remove_degenerate(Polylines &polylines);
2016-03-19 14:33:58 +00:00
class ThickPolyline : public Polyline {
public:
std::vector<coordf_t> width;
std::pair<bool,bool> endpoints;
ThickPolyline() : endpoints(std::make_pair(false, false)) {};
2016-03-19 14:33:58 +00:00
ThickLines thicklines() const;
void reverse();
2016-03-19 14:33:58 +00:00
};
2013-07-14 14:09:54 +00:00
}
#endif