mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-15 02:37:51 -06:00
Refactored signatures of many C++ methods for more efficient and safer style. Includes a bugfix for Point::nearest_point() which was returning a pointer to freed memory. #1961
This commit is contained in:
parent
6201aacf88
commit
ca4d4211c9
30 changed files with 203 additions and 161 deletions
|
@ -1,16 +1,36 @@
|
|||
#include "ExtrusionEntityCollection.hpp"
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
ExtrusionEntityCollection::ExtrusionEntityCollection(const ExtrusionEntityCollection& collection)
|
||||
: no_sort(collection.no_sort), orig_indices(collection.orig_indices)
|
||||
{
|
||||
this->entities.reserve(collection.entities.size());
|
||||
for (ExtrusionEntitiesPtr::const_iterator it = collection.entities.begin(); it != collection.entities.end(); ++it)
|
||||
this->entities.push_back((*it)->clone());
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection& ExtrusionEntityCollection::operator= (const ExtrusionEntityCollection &other)
|
||||
{
|
||||
ExtrusionEntityCollection tmp(other);
|
||||
this->swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
ExtrusionEntityCollection::swap (ExtrusionEntityCollection &c)
|
||||
{
|
||||
std::swap(this->entities, c.entities);
|
||||
std::swap(this->orig_indices, c.orig_indices);
|
||||
std::swap(this->no_sort, c.no_sort);
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionEntityCollection::clone() const
|
||||
{
|
||||
ExtrusionEntityCollection* collection = new ExtrusionEntityCollection (*this);
|
||||
for (ExtrusionEntitiesPtr::iterator it = collection->entities.begin(); it != collection->entities.end(); ++it) {
|
||||
*it = (*it)->clone();
|
||||
}
|
||||
return collection;
|
||||
return new ExtrusionEntityCollection(*this);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -22,32 +42,32 @@ ExtrusionEntityCollection::reverse()
|
|||
std::reverse(this->entities.begin(), this->entities.end());
|
||||
}
|
||||
|
||||
Point*
|
||||
Point
|
||||
ExtrusionEntityCollection::first_point() const
|
||||
{
|
||||
return this->entities.front()->first_point();
|
||||
}
|
||||
|
||||
Point*
|
||||
Point
|
||||
ExtrusionEntityCollection::last_point() const
|
||||
{
|
||||
return this->entities.back()->last_point();
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionEntityCollection::chained_path(bool no_reverse, std::vector<size_t>* orig_indices) const
|
||||
void
|
||||
ExtrusionEntityCollection::chained_path(ExtrusionEntityCollection* retval, bool no_reverse, std::vector<size_t>* orig_indices) const
|
||||
{
|
||||
if (this->entities.empty()) {
|
||||
return new ExtrusionEntityCollection ();
|
||||
}
|
||||
return this->chained_path_from(this->entities.front()->first_point(), no_reverse, orig_indices);
|
||||
if (this->entities.empty()) return;
|
||||
this->chained_path_from(this->entities.front()->first_point(), retval, no_reverse, orig_indices);
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionEntityCollection::chained_path_from(Point* start_near, bool no_reverse, std::vector<size_t>* orig_indices) const
|
||||
void
|
||||
ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEntityCollection* retval, bool no_reverse, std::vector<size_t>* orig_indices) const
|
||||
{
|
||||
if (this->no_sort) return this->clone();
|
||||
ExtrusionEntityCollection* retval = new ExtrusionEntityCollection;
|
||||
if (this->no_sort) {
|
||||
*retval = *this;
|
||||
return;
|
||||
}
|
||||
retval->entities.reserve(this->entities.size());
|
||||
retval->orig_indices.reserve(this->entities.size());
|
||||
|
||||
|
@ -63,17 +83,17 @@ ExtrusionEntityCollection::chained_path_from(Point* start_near, bool no_reverse,
|
|||
|
||||
Points endpoints;
|
||||
for (ExtrusionEntitiesPtr::iterator it = my_paths.begin(); it != my_paths.end(); ++it) {
|
||||
endpoints.push_back(*(*it)->first_point());
|
||||
endpoints.push_back((*it)->first_point());
|
||||
if (no_reverse) {
|
||||
endpoints.push_back(*(*it)->first_point());
|
||||
endpoints.push_back((*it)->first_point());
|
||||
} else {
|
||||
endpoints.push_back(*(*it)->last_point());
|
||||
endpoints.push_back((*it)->last_point());
|
||||
}
|
||||
}
|
||||
|
||||
while (!my_paths.empty()) {
|
||||
// find nearest point
|
||||
int start_index = start_near->nearest_point_index(endpoints);
|
||||
int start_index = start_near.nearest_point_index(endpoints);
|
||||
int path_index = start_index/2;
|
||||
ExtrusionEntity* entity = my_paths.at(path_index);
|
||||
if (start_index % 2 && !no_reverse) {
|
||||
|
@ -85,8 +105,6 @@ ExtrusionEntityCollection::chained_path_from(Point* start_near, bool no_reverse,
|
|||
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