Skip to content

Commit

Permalink
Restore correct ordering of concentric infill loops, preventing them …
Browse files Browse the repository at this point in the history
…from being reordered during G-code generation
  • Loading branch information
alranel committed Mar 9, 2015
1 parent 25cddfe commit 6cab566
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/Slic3r/Fill/Concentric.pm
Expand Up @@ -6,6 +6,8 @@ extends 'Slic3r::Fill::Base';
use Slic3r::Geometry qw(scale unscale X);
use Slic3r::Geometry::Clipper qw(offset offset2 union_pt_chained);

sub no_sort { 1 }

sub fill_surface {
my $self = shift;
my ($surface, %params) = @_;
Expand Down Expand Up @@ -36,7 +38,7 @@ sub fill_surface {
@loops = map Slic3r::Polygon->new(@$_),
reverse @{union_pt_chained(\@loops)};

# order paths using a nearest neighbor search
# split paths using a nearest neighbor search
my @paths = ();
my $last_pos = Slic3r::Point->new(0,0);
foreach my $loop (@loops) {
Expand Down
6 changes: 6 additions & 0 deletions xs/src/libslic3r/ExtrusionEntity.hpp
Expand Up @@ -38,6 +38,9 @@ class ExtrusionEntity
virtual bool is_loop() const {
return false;
};
virtual bool can_reverse() const {
return true;
};
virtual ExtrusionEntity* clone() const = 0;
virtual ~ExtrusionEntity() {};
virtual void reverse() = 0;
Expand Down Expand Up @@ -92,6 +95,9 @@ class ExtrusionLoop : public ExtrusionEntity
bool is_loop() const {
return true;
};
bool can_reverse() const {
return false;
};
ExtrusionLoop* clone() const;
bool make_clockwise();
bool make_counter_clockwise();
Expand Down
4 changes: 2 additions & 2 deletions xs/src/libslic3r/ExtrusionEntityCollection.cpp
Expand Up @@ -86,7 +86,7 @@ ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEntityCo
Points endpoints;
for (ExtrusionEntitiesPtr::iterator it = my_paths.begin(); it != my_paths.end(); ++it) {
endpoints.push_back((*it)->first_point());
if (no_reverse) {
if (no_reverse || !(*it)->can_reverse()) {
endpoints.push_back((*it)->first_point());
} else {
endpoints.push_back((*it)->last_point());
Expand All @@ -99,7 +99,7 @@ ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEntityCo
int path_index = start_index/2;
ExtrusionEntity* entity = my_paths.at(path_index);
// never reverse loops, since it's pointless for chained path and callers might depend on orientation
if (start_index % 2 && !no_reverse && !entity->is_loop()) {
if (start_index % 2 && !no_reverse && entity->can_reverse()) {
entity->reverse();
}
retval->entities.push_back(my_paths.at(path_index));
Expand Down
3 changes: 3 additions & 0 deletions xs/src/libslic3r/ExtrusionEntityCollection.hpp
Expand Up @@ -16,6 +16,9 @@ class ExtrusionEntityCollection : public ExtrusionEntity
ExtrusionEntityCollection(): no_sort(false) {};
ExtrusionEntityCollection(const ExtrusionEntityCollection &collection);
ExtrusionEntityCollection& operator= (const ExtrusionEntityCollection &other);
bool can_reverse() const {
return !this->no_sort;
};
void swap (ExtrusionEntityCollection &c);
void chained_path(ExtrusionEntityCollection* retval, bool no_reverse = false, std::vector<size_t>* orig_indices = NULL) const;
void chained_path_from(Point start_near, ExtrusionEntityCollection* retval, bool no_reverse = false, std::vector<size_t>* orig_indices = NULL) const;
Expand Down
9 changes: 8 additions & 1 deletion xs/t/12_extrusionpathcollection.t
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;

use Slic3r::XS;
use Test::More tests => 16;
use Test::More tests => 18;

my $points = [
[100, 100],
Expand Down Expand Up @@ -87,4 +87,11 @@ is scalar(@{$collection->[1]}), 1, 'appended collection was duplicated';
pass 'chained_path with no_sort';
}

{
my $coll2 = $collection->clone;
ok !$coll2->no_sort, 'expected no_sort value';
$coll2->no_sort(1);
ok $coll2->clone->no_sort, 'no_sort is kept after clone';
}

__END__
2 changes: 2 additions & 0 deletions xs/xsp/ExtrusionEntityCollection.xsp
Expand Up @@ -7,6 +7,8 @@

%name{Slic3r::ExtrusionPath::Collection} class ExtrusionEntityCollection {
%name{_new} ExtrusionEntityCollection();
Clone<ExtrusionEntityCollection> clone()
%code{% RETVAL = THIS->clone(); %};
void reverse();
void clear()
%code{% THIS->entities.clear(); %};
Expand Down

0 comments on commit 6cab566

Please sign in to comment.