Ported regular_points() to XS and renamed it to equally_spaced_points()

This commit is contained in:
Alessandro Ranellucci 2013-11-11 20:59:58 +01:00
parent 6bb425e88d
commit 885ab5844e
8 changed files with 45 additions and 34 deletions

View file

@ -53,6 +53,15 @@ Polygon::split_at_first_point() const
return this->split_at_index(0);
}
Points
Polygon::equally_spaced_points(double distance) const
{
Polyline* polyline = this->split_at_first_point();
Points pts = polyline->equally_spaced_points(distance);
delete polyline;
return pts;
}
double
Polygon::area() const
{

View file

@ -16,6 +16,7 @@ class Polygon : public MultiPoint {
Polyline* split_at(const Point* point) const;
Polyline* split_at_index(int index) const;
Polyline* split_at_first_point() const;
Points equally_spaced_points(double distance) const;
double area() const;
bool is_counter_clockwise() const;
bool is_clockwise() const;

View file

@ -49,6 +49,37 @@ Polyline::clip_start(double distance)
if (this->points.size() >= 2) this->reverse();
}
/* 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;
}
#ifdef SLIC3RXS
SV*
Polyline::to_SV_ref()

View file

@ -12,6 +12,7 @@ class Polyline : public MultiPoint {
Lines lines() const;
void clip_end(double distance);
void clip_start(double distance);
Points equally_spaced_points(double distance) const;
#ifdef SLIC3RXS
SV* to_SV_ref();

View file

@ -23,6 +23,7 @@
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_index(index); %};
Polyline* split_at_first_point()
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_first_point(); %};
Points equally_spaced_points(double distance);
double length();
double area();
bool is_counter_clockwise();

View file

@ -23,6 +23,7 @@
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
Points equally_spaced_points(double distance);
double length();
bool is_valid();
void clip_end(double distance);