Cleanup of some method signatures and of XS return types

This commit is contained in:
Alessandro Ranellucci 2015-01-19 18:53:04 +01:00
parent c9cdae1a96
commit 8791f5a493
39 changed files with 252 additions and 339 deletions

View file

@ -14,9 +14,7 @@ Polygon::operator Polygons() const
Polygon::operator Polyline() const
{
Polyline polyline;
this->split_at_first_point(&polyline);
return polyline;
return this->split_at_first_point();
}
Point&
@ -41,55 +39,49 @@ Lines
Polygon::lines() const
{
Lines lines;
this->lines(&lines);
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;
}
void
Polygon::lines(Lines* lines) const
{
lines->reserve(lines->size() + 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()));
}
void
Polygon::split_at_vertex(const Point &point, Polyline* polyline) const
Polyline
Polygon::split_at_vertex(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)) {
this->split_at_index(it - this->points.begin(), polyline);
return;
return this->split_at_index(it - this->points.begin());
}
}
CONFESS("Point not found");
return Polyline();
}
void
Polygon::split_at_index(int index, Polyline* polyline) const
{
polyline->points.reserve(this->points.size() + 1);
for (Points::const_iterator it = this->points.begin() + index; it != this->points.end(); ++it)
polyline->points.push_back(*it);
for (Points::const_iterator it = this->points.begin(); it != this->points.begin() + index + 1; ++it)
polyline->points.push_back(*it);
}
void
Polygon::split_at_first_point(Polyline* polyline) const
{
this->split_at_index(0, polyline);
}
void
Polygon::equally_spaced_points(double distance, Points* points) const
Polyline
Polygon::split_at_index(int index) const
{
Polyline polyline;
this->split_at_first_point(&polyline);
polyline.equally_spaced_points(distance, points);
polyline.points.reserve(this->points.size() + 1);
for (Points::const_iterator it = this->points.begin() + index; it != this->points.end(); ++it)
polyline.points.push_back(*it);
for (Points::const_iterator it = this->points.begin(); it != this->points.begin() + index + 1; ++it)
polyline.points.push_back(*it);
return polyline;
}
Polyline
Polygon::split_at_first_point() const
{
return this->split_at_index(0);
}
Points
Polygon::equally_spaced_points(double distance) const
{
return this->split_at_first_point().equally_spaced_points(distance);
}
double
@ -203,8 +195,7 @@ Polygon::centroid() const
double x_temp = 0;
double y_temp = 0;
Polyline polyline;
this->split_at_first_point(&polyline);
Polyline polyline = this->split_at_first_point();
for (Points::const_iterator point = polyline.points.begin(); point != polyline.points.end() - 1; ++point) {
x_temp += (double)( point->x + (point+1)->x ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y );
y_temp += (double)( point->y + (point+1)->y ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y );
@ -227,55 +218,49 @@ Polygon::wkt() const
}
// find all concave vertices (i.e. having an internal angle greater than the supplied angle) */
void
Polygon::concave_points(double angle, Points* points) const
Points
Polygon::concave_points(double angle) const
{
Points points;
angle = 2*PI - angle;
// check whether first point forms a concave angle
if (this->points.front().ccw_angle(this->points.back(), *(this->points.begin()+1)) <= angle)
points->push_back(this->points.front());
points.push_back(this->points.front());
// check whether points 1..(n-1) form concave angles
for (Points::const_iterator p = this->points.begin()+1; p != this->points.end()-1; ++p) {
if (p->ccw_angle(*(p-1), *(p+1)) <= angle) points->push_back(*p);
if (p->ccw_angle(*(p-1), *(p+1)) <= angle) points.push_back(*p);
}
// check whether last point forms a concave angle
if (this->points.back().ccw_angle(*(this->points.end()-2), this->points.front()) <= angle)
points->push_back(this->points.back());
}
void
Polygon::concave_points(Points* points) const
{
this->concave_points(PI, points);
points.push_back(this->points.back());
return points;
}
// find all convex vertices (i.e. having an internal angle smaller than the supplied angle) */
void
Polygon::convex_points(double angle, Points* points) const
Points
Polygon::convex_points(double angle) const
{
Points points;
angle = 2*PI - angle;
// check whether first point forms a convex angle
if (this->points.front().ccw_angle(this->points.back(), *(this->points.begin()+1)) >= angle)
points->push_back(this->points.front());
points.push_back(this->points.front());
// check whether points 1..(n-1) form convex angles
for (Points::const_iterator p = this->points.begin()+1; p != this->points.end()-1; ++p) {
if (p->ccw_angle(*(p-1), *(p+1)) >= angle) points->push_back(*p);
if (p->ccw_angle(*(p-1), *(p+1)) >= angle) points.push_back(*p);
}
// check whether last point forms a convex angle
if (this->points.back().ccw_angle(*(this->points.end()-2), this->points.front()) >= angle)
points->push_back(this->points.back());
}
void
Polygon::convex_points(Points* points) const
{
this->convex_points(PI, points);
points.push_back(this->points.back());
return points;
}
#ifdef SLIC3RXS