2012-02-15 11:04:10 +00:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2014-02-16 11:44:08 +00:00
|
|
|
plan tests => 42;
|
2012-02-15 11:04:10 +00:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
|
|
|
}
|
|
|
|
|
2014-01-11 20:34:26 +00:00
|
|
|
use List::Util qw(first);
|
2012-02-15 11:04:10 +00:00
|
|
|
use Slic3r;
|
2014-01-11 20:34:26 +00:00
|
|
|
use Slic3r::Geometry qw(scale X Y convex_hull);
|
2014-02-07 00:48:47 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(union diff_ex);
|
2012-08-25 12:59:34 +00:00
|
|
|
use Slic3r::Surface qw(:types);
|
2012-12-31 14:05:32 +00:00
|
|
|
use Slic3r::Test;
|
2012-02-15 11:04:10 +00:00
|
|
|
|
2012-08-25 12:59:34 +00:00
|
|
|
sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
|
2012-02-15 11:04:10 +00:00
|
|
|
|
|
|
|
{
|
2012-09-23 12:51:03 +00:00
|
|
|
my $print = Slic3r::Print->new;
|
|
|
|
$print->init_extruders;
|
2013-04-25 10:01:40 +00:00
|
|
|
my $filler = Slic3r::Fill::Rectilinear->new(
|
|
|
|
print => $print,
|
2013-08-26 23:26:44 +00:00
|
|
|
bounding_box => Slic3r::Geometry::BoundingBox->new_from_points([ Slic3r::Point->new(0, 0), Slic3r::Point->new(10, 10) ]),
|
2013-04-25 10:01:40 +00:00
|
|
|
);
|
2012-02-15 11:04:10 +00:00
|
|
|
my $surface_width = 250;
|
|
|
|
my $distance = $filler->adjust_solid_spacing(
|
|
|
|
width => $surface_width,
|
|
|
|
distance => 100,
|
|
|
|
);
|
|
|
|
is $distance, 125, 'adjusted solid distance';
|
|
|
|
is $surface_width % $distance, 0, 'adjusted solid distance';
|
|
|
|
}
|
|
|
|
|
2012-08-25 12:59:34 +00:00
|
|
|
{
|
2013-07-16 07:49:34 +00:00
|
|
|
my $expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,50], [0,50] ]);
|
2013-04-25 10:01:40 +00:00
|
|
|
my $filler = Slic3r::Fill::Rectilinear->new(
|
2013-06-16 10:21:25 +00:00
|
|
|
bounding_box => $expolygon->bounding_box,
|
2013-12-24 11:03:30 +00:00
|
|
|
angle => 0,
|
2013-04-25 10:01:40 +00:00
|
|
|
);
|
2012-08-25 12:59:34 +00:00
|
|
|
my $surface = Slic3r::Surface->new(
|
|
|
|
surface_type => S_TYPE_TOP,
|
2013-04-25 10:01:40 +00:00
|
|
|
expolygon => $expolygon,
|
2012-08-25 12:59:34 +00:00
|
|
|
);
|
2014-01-03 19:02:00 +00:00
|
|
|
my $flow = Slic3r::Flow->new(
|
|
|
|
width => 0.69,
|
|
|
|
spacing => 0.69,
|
|
|
|
nozzle_diameter => 0.50,
|
|
|
|
);
|
2012-08-25 12:59:34 +00:00
|
|
|
foreach my $angle (0, 45) {
|
2012-09-12 14:30:44 +00:00
|
|
|
$surface->expolygon->rotate(Slic3r::Geometry::deg2rad($angle), [0,0]);
|
2014-01-03 19:02:00 +00:00
|
|
|
my ($params, @paths) = $filler->fill_surface($surface, flow => $flow, density => 0.4);
|
2012-08-25 12:59:34 +00:00
|
|
|
is scalar @paths, 1, 'one continuous path';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:05:04 +00:00
|
|
|
{
|
2013-07-29 10:28:23 +00:00
|
|
|
my $test = sub {
|
2013-08-13 08:05:40 +00:00
|
|
|
my ($expolygon, $flow_spacing, $angle, $density) = @_;
|
2013-07-29 11:36:22 +00:00
|
|
|
|
2013-07-29 10:28:23 +00:00
|
|
|
my $filler = Slic3r::Fill::Rectilinear->new(
|
|
|
|
bounding_box => $expolygon->bounding_box,
|
2013-08-13 08:05:40 +00:00
|
|
|
angle => $angle // 0,
|
2013-07-29 10:28:23 +00:00
|
|
|
);
|
|
|
|
my $surface = Slic3r::Surface->new(
|
|
|
|
surface_type => S_TYPE_BOTTOM,
|
|
|
|
expolygon => $expolygon,
|
|
|
|
);
|
2014-01-03 19:02:00 +00:00
|
|
|
my $flow = Slic3r::Flow->new(
|
|
|
|
width => $flow_spacing,
|
|
|
|
spacing => $flow_spacing,
|
|
|
|
nozzle_diameter => $flow_spacing,
|
|
|
|
);
|
2013-08-13 08:05:40 +00:00
|
|
|
my ($params, @paths) = $filler->fill_surface(
|
|
|
|
$surface,
|
2014-01-03 19:02:00 +00:00
|
|
|
flow => $flow,
|
2013-08-13 08:05:40 +00:00
|
|
|
density => $density // 1,
|
|
|
|
);
|
2013-07-29 10:28:23 +00:00
|
|
|
|
|
|
|
# check whether any part was left uncovered
|
2014-01-03 19:02:00 +00:00
|
|
|
my @grown_paths = map @{Slic3r::Polyline->new(@$_)->grow(scale $params->{flow}->spacing/2)}, @paths;
|
2013-07-29 10:28:23 +00:00
|
|
|
my $uncovered = diff_ex([ @$expolygon ], [ @grown_paths ], 1);
|
2013-07-29 11:36:22 +00:00
|
|
|
|
|
|
|
# ignore very small dots
|
|
|
|
@$uncovered = grep $_->area > (scale $flow_spacing)**2, @$uncovered;
|
|
|
|
|
2013-07-29 10:28:23 +00:00
|
|
|
is scalar(@$uncovered), 0, 'solid surface is fully filled';
|
2013-07-29 11:36:22 +00:00
|
|
|
|
2013-07-29 10:28:23 +00:00
|
|
|
if (0 && @$uncovered) {
|
|
|
|
require "Slic3r/SVG.pm";
|
|
|
|
Slic3r::SVG::output(
|
|
|
|
"uncovered.svg",
|
|
|
|
expolygons => [$expolygon],
|
|
|
|
red_expolygons => $uncovered,
|
|
|
|
);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-29 09:05:04 +00:00
|
|
|
my $expolygon = Slic3r::ExPolygon->new([
|
|
|
|
[6883102, 9598327.01296997],
|
|
|
|
[6883102, 20327272.01297],
|
|
|
|
[3116896, 20327272.01297],
|
|
|
|
[3116896, 9598327.01296997],
|
|
|
|
]);
|
2013-07-29 11:36:22 +00:00
|
|
|
$test->($expolygon, 0.55);
|
2013-07-29 09:05:04 +00:00
|
|
|
|
2013-07-29 10:28:23 +00:00
|
|
|
for (1..20) {
|
|
|
|
$expolygon->scale(1.05);
|
2013-07-29 11:36:22 +00:00
|
|
|
$test->($expolygon, 0.55);
|
2013-07-29 10:28:23 +00:00
|
|
|
}
|
2013-07-29 11:36:22 +00:00
|
|
|
|
|
|
|
$expolygon = Slic3r::ExPolygon->new(
|
|
|
|
[[59515297,5422499],[59531249,5578697],[59695801,6123186],[59965713,6630228],[60328214,7070685],[60773285,7434379],[61274561,7702115],[61819378,7866770],[62390306,7924789],[62958700,7866744],[63503012,7702244],[64007365,7434357],[64449960,7070398],[64809327,6634999],[65082143,6123325],[65245005,5584454],[65266967,5422499],[66267307,5422499],[66269190,8310081],[66275379,17810072],[66277259,20697500],[65267237,20697500],[65245004,20533538],[65082082,19994444],[64811462,19488579],[64450624,19048208],[64012101,18686514],[63503122,18415781],[62959151,18251378],[62453416,18198442],[62390147,18197355],[62200087,18200576],[61813519,18252990],[61274433,18415918],[60768598,18686517],[60327567,19047892],[59963609,19493297],[59695865,19994587],[59531222,20539379],[59515153,20697500],[58502480,20697500],[58502480,5422499]]
|
|
|
|
);
|
|
|
|
$test->($expolygon, 0.524341649025257);
|
2013-08-13 08:05:40 +00:00
|
|
|
|
|
|
|
$expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [98,0], [98,10], [0,10] ]);
|
|
|
|
$test->($expolygon, 0.5, 45, 0.99); # non-solid infill
|
2013-07-29 09:05:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 22:52:53 +00:00
|
|
|
{
|
2013-08-29 22:06:10 +00:00
|
|
|
my $collection = Slic3r::Polyline::Collection->new(
|
2012-12-04 22:52:53 +00:00
|
|
|
Slic3r::Polyline->new([0,15], [0,18], [0,20]),
|
|
|
|
Slic3r::Polyline->new([0,10], [0,8], [0,5]),
|
2013-08-29 22:06:10 +00:00
|
|
|
);
|
2012-12-04 22:52:53 +00:00
|
|
|
is_deeply
|
2013-09-02 20:10:52 +00:00
|
|
|
[ map $_->[Y], map @$_, @{$collection->chained_path_from(Slic3r::Point->new(0,30), 0)} ],
|
2012-12-04 22:52:53 +00:00
|
|
|
[20, 18, 15, 10, 8, 5],
|
2013-02-06 09:21:23 +00:00
|
|
|
'chained path';
|
2012-12-04 22:52:53 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 17:10:20 +00:00
|
|
|
{
|
2013-08-29 22:06:10 +00:00
|
|
|
my $collection = Slic3r::Polyline::Collection->new(
|
2012-12-20 17:10:20 +00:00
|
|
|
Slic3r::Polyline->new([4,0], [10,0], [15,0]),
|
|
|
|
Slic3r::Polyline->new([10,5], [15,5], [20,5]),
|
2013-08-29 22:06:10 +00:00
|
|
|
);
|
2012-12-20 17:10:20 +00:00
|
|
|
is_deeply
|
2013-09-02 20:10:52 +00:00
|
|
|
[ map $_->[X], map @$_, @{$collection->chained_path_from(Slic3r::Point->new(30,0), 0)} ],
|
2012-12-20 17:10:20 +00:00
|
|
|
[reverse 4, 10, 15, 10, 15, 20],
|
2013-02-06 09:21:23 +00:00
|
|
|
'chained path';
|
2012-12-20 17:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2013-07-18 20:29:12 +00:00
|
|
|
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
2014-01-03 17:27:46 +00:00
|
|
|
map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
|
2012-12-20 17:10:20 +00:00
|
|
|
Slic3r::Polyline->new([0,15], [0,18], [0,20]),
|
|
|
|
Slic3r::Polyline->new([0,10], [0,8], [0,5]),
|
2013-07-18 20:29:12 +00:00
|
|
|
);
|
2012-12-20 17:10:20 +00:00
|
|
|
is_deeply
|
2013-08-29 09:47:59 +00:00
|
|
|
[ map $_->[Y], map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(0,30), 0)} ],
|
2012-12-20 17:10:20 +00:00
|
|
|
[20, 18, 15, 10, 8, 5],
|
2013-02-06 09:21:23 +00:00
|
|
|
'chained path';
|
2012-12-20 17:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2013-07-18 20:29:12 +00:00
|
|
|
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
2014-01-03 17:27:46 +00:00
|
|
|
map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
|
2012-12-20 17:10:20 +00:00
|
|
|
Slic3r::Polyline->new([15,0], [10,0], [4,0]),
|
|
|
|
Slic3r::Polyline->new([10,5], [15,5], [20,5]),
|
2013-07-18 20:29:12 +00:00
|
|
|
);
|
2012-12-20 17:10:20 +00:00
|
|
|
is_deeply
|
2013-08-29 09:47:59 +00:00
|
|
|
[ map $_->[X], map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(30,0), 0)} ],
|
2012-12-20 17:10:20 +00:00
|
|
|
[reverse 4, 10, 15, 10, 15, 20],
|
2013-02-06 09:21:23 +00:00
|
|
|
'chained path';
|
2012-12-20 17:10:20 +00:00
|
|
|
}
|
|
|
|
|
2014-01-11 20:34:26 +00:00
|
|
|
for my $pattern (qw(rectilinear honeycomb hilbertcurve concentric)) {
|
2012-12-31 14:05:32 +00:00
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
2013-09-12 09:13:11 +00:00
|
|
|
$config->set('fill_pattern', $pattern);
|
2014-01-11 20:34:26 +00:00
|
|
|
$config->set('perimeters', 1);
|
|
|
|
$config->set('skirts', 0);
|
2014-03-22 15:23:33 +00:00
|
|
|
$config->set('fill_density', 20);
|
2014-01-11 20:34:26 +00:00
|
|
|
$config->set('layer_height', 0.05);
|
|
|
|
$config->set('perimeter_extruder', 1);
|
|
|
|
$config->set('infill_extruder', 2);
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale => 2);
|
|
|
|
ok my $gcode = Slic3r::Test::gcode($print), "successful $pattern infill generation";
|
|
|
|
my $tool = undef;
|
|
|
|
my @perimeter_points = my @infill_points = ();
|
|
|
|
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($cmd =~ /^T(\d+)/) {
|
|
|
|
$tool = $1;
|
|
|
|
} elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
|
|
|
|
if ($tool == $config->perimeter_extruder-1) {
|
|
|
|
push @perimeter_points, Slic3r::Point->new_scale($args->{X}, $args->{Y});
|
|
|
|
} elsif ($tool == $config->infill_extruder-1) {
|
|
|
|
push @infill_points, Slic3r::Point->new_scale($args->{X}, $args->{Y});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
my $convex_hull = convex_hull(\@perimeter_points);
|
|
|
|
ok !(defined first { !$convex_hull->contains_point($_) } @infill_points), "infill does not exceed perimeters ($pattern)";
|
2012-12-31 14:05:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 11:44:08 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
|
|
|
$config->set('infill_only_where_needed', 1);
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
|
|
|
ok my $gcode = Slic3r::Test::gcode($print), "successful G-code generation when infill_only_where_needed is set";
|
|
|
|
}
|
|
|
|
|
2013-03-26 14:47:40 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
|
|
|
$config->set('skirts', 0);
|
|
|
|
$config->set('perimeters', 0);
|
|
|
|
$config->set('fill_density', 0);
|
|
|
|
$config->set('top_solid_layers', 0);
|
|
|
|
$config->set('bottom_solid_layers', 0);
|
|
|
|
$config->set('solid_infill_below_area', 20000000);
|
2013-06-14 14:48:24 +00:00
|
|
|
$config->set('solid_infill_every_layers', 2);
|
2013-03-26 14:47:40 +00:00
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
2013-06-14 14:48:24 +00:00
|
|
|
my %layers_with_extrusion = ();
|
2013-08-28 14:51:58 +00:00
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
2013-03-26 14:47:40 +00:00
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
2013-06-14 14:48:24 +00:00
|
|
|
$layers_with_extrusion{$self->Z} = 1 if $info->{extruding};
|
2013-03-26 14:47:40 +00:00
|
|
|
});
|
2013-06-14 14:48:24 +00:00
|
|
|
|
|
|
|
ok !%layers_with_extrusion,
|
|
|
|
"solid_infill_below_area and solid_infill_every_layers are ignored when fill_density is 0";
|
2013-03-26 14:47:40 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 00:48:47 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
|
|
|
$config->set('skirts', 0);
|
|
|
|
$config->set('perimeters', 3);
|
|
|
|
$config->set('fill_density', 0);
|
|
|
|
$config->set('layer_height', 0.2);
|
|
|
|
$config->set('first_layer_height', 0.2);
|
|
|
|
$config->set('nozzle_diameter', [0.35]);
|
|
|
|
$config->set('infill_extruder', 2);
|
|
|
|
$config->set('infill_extrusion_width', 0.52);
|
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('A', config => $config);
|
|
|
|
my %infill = (); # Z => [ Line, Line ... ]
|
|
|
|
my $tool = undef;
|
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($cmd =~ /^T(\d+)/) {
|
|
|
|
$tool = $1;
|
|
|
|
} elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
|
|
|
|
if ($tool == $config->infill_extruder-1) {
|
|
|
|
my $z = 1 * $self->Z;
|
|
|
|
$infill{$z} ||= [];
|
|
|
|
push @{$infill{$z}}, Slic3r::Line->new_scale(
|
|
|
|
[ $self->X, $self->Y ],
|
|
|
|
[ $info->{new_X}, $info->{new_Y} ],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
my $grow_d = scale($config->infill_extrusion_width)/2;
|
|
|
|
my $layer0_infill = union([ map @{$_->grow($grow_d)}, @{ $infill{0.2} } ]);
|
|
|
|
my $layer1_infill = union([ map @{$_->grow($grow_d)}, @{ $infill{0.4} } ]);
|
|
|
|
my $diff = [ grep $_->area >= 2*$grow_d**2, @{diff_ex($layer0_infill, $layer1_infill)} ];
|
|
|
|
is scalar(@$diff), 0, 'no missing parts in solid shell when fill_density is 0';
|
|
|
|
}
|
|
|
|
|
2012-02-15 11:04:10 +00:00
|
|
|
__END__
|