/
Concentric.pm
55 lines (42 loc) · 1.61 KB
/
Concentric.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package Slic3r::Fill::Concentric;
use Moo;
extends 'Slic3r::Fill::Base';
use Slic3r::Geometry qw(scale);
use XXX;
sub fill_surface {
my $self = shift;
my ($surface, %params) = @_;
# no rotation is supported for this infill pattern
my $scaled_flow_spacing = scale $params{flow_spacing};
my $distance = $scaled_flow_spacing / $params{density};
my @contour_loops = ();
my @hole_loops = ();
my @last_offsets = ($surface->expolygon->offset_ex($distance));
while (@last_offsets) {
my @new_offsets = ();
foreach my $expolygon (@last_offsets) {
my @offsets = $expolygon->offset_ex(-$distance);
foreach my $offset (@offsets) {
push @new_offsets, $offset;
push @contour_loops, $offset->contour;
push @hole_loops, $offset->holes;
}
}
@last_offsets = @new_offsets;
}
my @loops = (@contour_loops, reverse @hole_loops);
# make paths
my @paths = ();
my $cur_pos = Slic3r::Point->new(0,0);
foreach my $loop (map Slic3r::ExtrusionLoop->cast($_, role => 'fill'), @loops) {
# find the point of the loop that is closest to the current extruder position
$cur_pos = $loop->nearest_point_to($cur_pos);
# split the loop at the starting point and make a path
my $path = $loop->split_at($cur_pos);
# clip the path to avoid the extruder to get exactly on the first point of the loop
$path->clip_end(scale $Slic3r::flow_spacing);
push @paths, $path->p;
}
return @paths;
}
1;