Minor code cleanup here and there

This commit is contained in:
Alessandro Ranellucci 2015-12-19 20:27:04 +01:00
parent 795107dfa2
commit 70e8db8a0a
3 changed files with 13 additions and 24 deletions

View File

@ -22,7 +22,7 @@ sub new {
keep_upper => 1, keep_upper => 1,
keep_lower => 1, keep_lower => 1,
rotate_lower => 1, rotate_lower => 1,
preview => 0, preview => 1,
}; };
my $optgroup; my $optgroup;

View File

@ -90,12 +90,8 @@ MotionPlanner::shortest_path(const Point &from, const Point &to)
if (!this->initialized) this->initialize(); if (!this->initialized) this->initialize();
// if we have an empty configuration space, return a straight move // if we have an empty configuration space, return a straight move
if (this->islands.empty()) { if (this->islands.empty())
Polyline p; return Line(from, to);
p.points.push_back(from);
p.points.push_back(to);
return p;
}
// Are both points in the same island? // Are both points in the same island?
int island_idx = -1; int island_idx = -1;
@ -103,12 +99,9 @@ MotionPlanner::shortest_path(const Point &from, const Point &to)
if (island->contains(from) && island->contains(to)) { if (island->contains(from) && island->contains(to)) {
// since both points are in the same island, is a direct move possible? // since both points are in the same island, is a direct move possible?
// if so, we avoid generating the visibility environment // if so, we avoid generating the visibility environment
if (island->contains(Line(from, to))) { if (island->contains(Line(from, to)))
Polyline p; return Line(from, to);
p.points.push_back(from);
p.points.push_back(to);
return p;
}
island_idx = island - this->islands.begin(); island_idx = island - this->islands.begin();
break; break;
} }
@ -119,10 +112,7 @@ MotionPlanner::shortest_path(const Point &from, const Point &to)
if (env.expolygons.empty()) { if (env.expolygons.empty()) {
// if this environment is empty (probably because it's too small), perform straight move // if this environment is empty (probably because it's too small), perform straight move
// and avoid running the algorithms on empty dataset // and avoid running the algorithms on empty dataset
Polyline p; return Line(from, to);
p.points.push_back(from);
p.points.push_back(to);
return p; // bye bye
} }
// Now check whether points are inside the environment. // Now check whether points are inside the environment.

View File

@ -472,11 +472,10 @@ TriangleMeshSlicer::slice(const std::vector<float> &z, std::vector<Polygons>* la
// build loops // build loops
layers->resize(z.size()); layers->resize(z.size());
for (std::vector<IntersectionLines>::iterator it = lines.begin(); it != lines.end(); ++it) { for (std::vector<IntersectionLines>::iterator it = lines.begin(); it != lines.end(); ++it) {
int layer_idx = it - lines.begin(); size_t layer_idx = it - lines.begin();
#ifdef SLIC3R_DEBUG #ifdef SLIC3R_DEBUG
printf("Layer %d:\n", layer_idx); printf("Layer %zu:\n", layer_idx);
#endif #endif
this->make_loops(*it, &(*layers)[layer_idx]); this->make_loops(*it, &(*layers)[layer_idx]);
} }
} }
@ -708,7 +707,7 @@ TriangleMeshSlicer::make_loops(std::vector<IntersectionLine> &lines, Polygons* l
// loop is complete // loop is complete
Polygon p; Polygon p;
p.points.reserve(loop.size()); p.points.reserve(loop.size());
for (IntersectionLinePtrs::iterator lineptr = loop.begin(); lineptr != loop.end(); ++lineptr) { for (IntersectionLinePtrs::const_iterator lineptr = loop.begin(); lineptr != loop.end(); ++lineptr) {
p.points.push_back((*lineptr)->a); p.points.push_back((*lineptr)->a);
} }
loops->push_back(p); loops->push_back(p);
@ -858,7 +857,7 @@ TriangleMeshSlicer::make_expolygons(std::vector<IntersectionLine> &lines, ExPoly
void void
TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
{ {
std::vector<IntersectionLine> upper_lines, lower_lines; IntersectionLines upper_lines, lower_lines;
float scaled_z = scale_(z); float scaled_z = scale_(z);
for (int facet_idx = 0; facet_idx < this->mesh->stl.stats.number_of_facets; facet_idx++) { for (int facet_idx = 0; facet_idx < this->mesh->stl.stats.number_of_facets; facet_idx++) {
@ -869,11 +868,11 @@ TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
float max_z = fmaxf(facet->vertex[0].z, fmaxf(facet->vertex[1].z, facet->vertex[2].z)); float max_z = fmaxf(facet->vertex[0].z, fmaxf(facet->vertex[1].z, facet->vertex[2].z));
// intersect facet with cutting plane // intersect facet with cutting plane
std::vector<IntersectionLine> lines; IntersectionLines lines;
this->slice_facet(scaled_z, *facet, facet_idx, min_z, max_z, &lines); this->slice_facet(scaled_z, *facet, facet_idx, min_z, max_z, &lines);
// save intersection lines for generating correct triangulations // save intersection lines for generating correct triangulations
for (std::vector<IntersectionLine>::iterator it = lines.begin(); it != lines.end(); ++it) { for (IntersectionLines::const_iterator it = lines.begin(); it != lines.end(); ++it) {
if (it->edge_type == feTop) { if (it->edge_type == feTop) {
lower_lines.push_back(*it); lower_lines.push_back(*it);
} else if (it->edge_type == feBottom) { } else if (it->edge_type == feBottom) {