2013-07-16 19:04:14 +00:00
|
|
|
#include "Polyline.hpp"
|
2013-11-21 16:53:50 +00:00
|
|
|
#include "Polygon.hpp"
|
2013-07-16 19:04:14 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
Polyline::operator Polylines() const
|
|
|
|
{
|
|
|
|
Polylines polylines(1);
|
|
|
|
polylines.push_back(*this);
|
|
|
|
return polylines;
|
|
|
|
}
|
|
|
|
|
2013-09-02 18:22:20 +00:00
|
|
|
Point*
|
|
|
|
Polyline::last_point() const
|
|
|
|
{
|
2013-09-02 20:33:03 +00:00
|
|
|
return new Point(this->points.back());
|
2013-09-02 18:22:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 13:19:15 +00:00
|
|
|
Lines
|
|
|
|
Polyline::lines() const
|
2013-07-16 19:04:14 +00:00
|
|
|
{
|
2013-09-13 13:19:15 +00:00
|
|
|
Lines lines;
|
|
|
|
lines.reserve(this->points.size() - 1);
|
|
|
|
for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) {
|
|
|
|
lines.push_back(Line(*it, *(it + 1)));
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
2013-09-13 13:19:15 +00:00
|
|
|
return lines;
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-27 21:57:25 +00:00
|
|
|
// removes the given distance from the end of the polyline
|
|
|
|
void
|
|
|
|
Polyline::clip_end(double distance)
|
|
|
|
{
|
|
|
|
while (distance > 0) {
|
|
|
|
Point last_point = *this->last_point();
|
|
|
|
this->points.pop_back();
|
|
|
|
if (this->points.empty()) break;
|
|
|
|
|
|
|
|
double last_segment_length = last_point.distance_to(this->last_point());
|
|
|
|
if (last_segment_length <= distance) {
|
|
|
|
distance -= last_segment_length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Line segment(last_point, *this->last_point());
|
|
|
|
this->points.push_back(*segment.point_at(distance));
|
|
|
|
distance = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-06 18:30:45 +00:00
|
|
|
// removes the given distance from the start of the polyline
|
|
|
|
void
|
|
|
|
Polyline::clip_start(double distance)
|
|
|
|
{
|
|
|
|
this->reverse();
|
|
|
|
this->clip_end(distance);
|
|
|
|
if (this->points.size() >= 2) this->reverse();
|
|
|
|
}
|
|
|
|
|
2013-11-11 19:59:58 +00:00
|
|
|
/* this method returns a collection of points picked on the polygon contour
|
|
|
|
so that they are evenly spaced according to the input distance */
|
|
|
|
Points
|
|
|
|
Polyline::equally_spaced_points(double distance) const
|
|
|
|
{
|
|
|
|
Points pts;
|
|
|
|
pts.push_back(*this->first_point());
|
|
|
|
double len = 0;
|
|
|
|
|
|
|
|
for (Points::const_iterator it = this->points.begin() + 1; it != this->points.end(); ++it) {
|
|
|
|
double segment_length = it->distance_to(&*(it-1));
|
|
|
|
len += segment_length;
|
|
|
|
if (len < distance) continue;
|
|
|
|
|
|
|
|
if (len == distance) {
|
|
|
|
pts.push_back(*it);
|
|
|
|
len = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
double take = segment_length - (len - distance); // how much we take of this segment
|
|
|
|
Line segment(*(it-1), *it);
|
|
|
|
pts.push_back(*segment.point_at(take));
|
|
|
|
it--;
|
|
|
|
len = -take;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-13 12:48:40 +00:00
|
|
|
#ifdef SLIC3RXS
|
2013-08-29 22:06:10 +00:00
|
|
|
SV*
|
2013-09-03 17:26:58 +00:00
|
|
|
Polyline::to_SV_ref()
|
2013-09-02 18:22:20 +00:00
|
|
|
{
|
|
|
|
SV* sv = newSV(0);
|
|
|
|
sv_setref_pv( sv, "Slic3r::Polyline::Ref", (void*)this );
|
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
SV*
|
|
|
|
Polyline::to_SV_clone_ref() const
|
2013-08-29 22:06:10 +00:00
|
|
|
{
|
|
|
|
SV* sv = newSV(0);
|
|
|
|
sv_setref_pv( sv, "Slic3r::Polyline", new Polyline(*this) );
|
|
|
|
return sv;
|
|
|
|
}
|
2013-09-13 12:48:40 +00:00
|
|
|
#endif
|
2013-08-29 22:06:10 +00:00
|
|
|
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|