mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-15 02:37:51 -06:00
Ported ExtrusionPath::Collection->chained_path
This commit is contained in:
parent
ea1d138c95
commit
bd7b0e2aed
11 changed files with 170 additions and 57 deletions
75
xs/src/ExtrusionEntityCollection.cpp
Normal file
75
xs/src/ExtrusionEntityCollection.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include "ExtrusionEntityCollection.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionEntityCollection::clone() const
|
||||
{
|
||||
return new ExtrusionEntityCollection (*this);
|
||||
}
|
||||
|
||||
void
|
||||
ExtrusionEntityCollection::reverse()
|
||||
{
|
||||
for (ExtrusionEntitiesPtr::iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
|
||||
(*it)->reverse();
|
||||
}
|
||||
std::reverse(this->entities.begin(), this->entities.end());
|
||||
}
|
||||
|
||||
Point*
|
||||
ExtrusionEntityCollection::first_point()
|
||||
{
|
||||
return this->entities.front()->first_point();
|
||||
}
|
||||
|
||||
Point*
|
||||
ExtrusionEntityCollection::last_point()
|
||||
{
|
||||
return this->entities.back()->last_point();
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionEntityCollection::chained_path(bool no_reverse) const
|
||||
{
|
||||
if (this->entities.empty()) {
|
||||
return new ExtrusionEntityCollection ();
|
||||
}
|
||||
return this->chained_path_from(this->entities.front()->first_point(), no_reverse);
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionEntityCollection::chained_path_from(Point* start_near, bool no_reverse) const
|
||||
{
|
||||
if (this->no_sort) return new ExtrusionEntityCollection(*this);
|
||||
ExtrusionEntityCollection* retval = new ExtrusionEntityCollection;
|
||||
ExtrusionEntitiesPtr my_paths = this->entities;
|
||||
|
||||
Points endpoints;
|
||||
for (ExtrusionEntitiesPtr::iterator it = my_paths.begin(); it != my_paths.end(); ++it) {
|
||||
endpoints.push_back(*(*it)->first_point());
|
||||
if (no_reverse) {
|
||||
endpoints.push_back(*(*it)->first_point());
|
||||
} else {
|
||||
endpoints.push_back(*(*it)->last_point());
|
||||
}
|
||||
}
|
||||
|
||||
while (!my_paths.empty()) {
|
||||
// find nearest point
|
||||
int start_index = start_near->nearest_point_index(endpoints);
|
||||
int path_index = start_index/2;
|
||||
if (start_index % 2 && !no_reverse) {
|
||||
my_paths.at(path_index) = my_paths.at(path_index)->clone(); // maybe we should clone them all when building my_paths?
|
||||
my_paths.at(path_index)->reverse();
|
||||
}
|
||||
retval->entities.push_back(my_paths.at(path_index));
|
||||
my_paths.erase(my_paths.begin() + path_index);
|
||||
endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2);
|
||||
start_near = retval->entities.back()->last_point();
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue