Minor optimizations
This commit is contained in:
parent
6e22a82e7d
commit
4dce461aaf
@ -33,7 +33,7 @@ ExtrusionLoop::clone() const
|
||||
}
|
||||
|
||||
ExtrusionPath*
|
||||
ExtrusionLoop::split_at_index(int index)
|
||||
ExtrusionLoop::split_at_index(int index) const
|
||||
{
|
||||
Polyline* poly = this->polygon.split_at_index(index);
|
||||
|
||||
@ -48,7 +48,7 @@ ExtrusionLoop::split_at_index(int index)
|
||||
}
|
||||
|
||||
ExtrusionPath*
|
||||
ExtrusionLoop::split_at_first_point()
|
||||
ExtrusionLoop::split_at_first_point() const
|
||||
{
|
||||
return this->split_at_index(0);
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ class ExtrusionLoop : public ExtrusionEntity
|
||||
public:
|
||||
ExtrusionLoop* clone() const;
|
||||
Polygon polygon;
|
||||
ExtrusionPath* split_at_index(int index);
|
||||
ExtrusionPath* split_at_first_point();
|
||||
ExtrusionPath* split_at_index(int index) const;
|
||||
ExtrusionPath* split_at_first_point() const;
|
||||
bool make_counter_clockwise();
|
||||
void reverse();
|
||||
Point* first_point() const;
|
||||
|
@ -15,40 +15,40 @@ Lines
|
||||
Polygon::lines() const
|
||||
{
|
||||
Lines lines;
|
||||
for (int i = 0; i < this->points.size()-1; i++) {
|
||||
lines.push_back(Line(this->points[i], this->points[i+1]));
|
||||
lines.reserve(this->points.size());
|
||||
for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) {
|
||||
lines.push_back(Line(*it, *(it + 1)));
|
||||
}
|
||||
lines.push_back(Line(this->points.back(), this->points.front()));
|
||||
return lines;
|
||||
}
|
||||
|
||||
Polyline*
|
||||
Polygon::split_at(const Point* point)
|
||||
Polygon::split_at(const Point* point) const
|
||||
{
|
||||
// find index of point
|
||||
for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
|
||||
if ((*it).coincides_with(point)) {
|
||||
if (it->coincides_with(point))
|
||||
return this->split_at_index(it - this->points.begin());
|
||||
}
|
||||
}
|
||||
throw "Point not found";
|
||||
CONFESS("Point not found");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Polyline*
|
||||
Polygon::split_at_index(int index)
|
||||
Polygon::split_at_index(int index) const
|
||||
{
|
||||
Polyline* poly = new Polyline;
|
||||
for (int i = index; i < this->points.size(); i++) {
|
||||
poly->points.push_back( this->points[i] );
|
||||
}
|
||||
for (int i = 0; i <= index; i++) {
|
||||
poly->points.push_back( this->points[i] );
|
||||
}
|
||||
poly->points.reserve(this->points.size() + 1);
|
||||
for (Points::const_iterator it = this->points.begin() + index; it != this->points.end(); ++it)
|
||||
poly->points.push_back(*it);
|
||||
for (Points::const_iterator it = this->points.begin(); it != this->points.begin() + index + 1; ++it)
|
||||
poly->points.push_back(*it);
|
||||
return poly;
|
||||
}
|
||||
|
||||
Polyline*
|
||||
Polygon::split_at_first_point()
|
||||
Polygon::split_at_first_point() const
|
||||
{
|
||||
return this->split_at_index(0);
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ class Polygon : public MultiPoint {
|
||||
public:
|
||||
Point* last_point() const;
|
||||
Lines lines() const;
|
||||
Polyline* split_at(const Point* point);
|
||||
Polyline* split_at_index(int index);
|
||||
Polyline* split_at_first_point();
|
||||
Polyline* split_at(const Point* point) const;
|
||||
Polyline* split_at_index(int index) const;
|
||||
Polyline* split_at_first_point() const;
|
||||
double area() const;
|
||||
bool is_counter_clockwise() const;
|
||||
bool is_clockwise() const;
|
||||
|
@ -8,13 +8,15 @@ Polyline::last_point() const
|
||||
return new Point(this->points.back());
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::lines(Lines &lines) const
|
||||
Lines
|
||||
Polyline::lines() const
|
||||
{
|
||||
lines.clear();
|
||||
for (int i = 0; i < this->points.size()-1; i++) {
|
||||
lines.push_back(Line(this->points[i], this->points[i+1]));
|
||||
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)));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
|
@ -9,7 +9,7 @@ namespace Slic3r {
|
||||
class Polyline : public MultiPoint {
|
||||
public:
|
||||
Point* last_point() const;
|
||||
void lines(Lines &lines) const;
|
||||
Lines lines() const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
|
@ -15,7 +15,7 @@
|
||||
%code{% THIS->polyline.points.pop_back(); %};
|
||||
void reverse();
|
||||
Lines lines()
|
||||
%code{% RETVAL = Lines(); THIS->polyline.lines(RETVAL); %};
|
||||
%code{% RETVAL = THIS->polyline.lines(); %};
|
||||
Point* first_point()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
|
||||
Point* last_point()
|
||||
|
@ -18,8 +18,7 @@
|
||||
void pop_back()
|
||||
%code{% THIS->points.pop_back(); %};
|
||||
void reverse();
|
||||
Lines lines()
|
||||
%code{% RETVAL = Lines(); THIS->lines(RETVAL); %};
|
||||
Lines lines();
|
||||
Point* first_point()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
|
||||
Point* last_point()
|
||||
|
Loading…
Reference in New Issue
Block a user