mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-31 20:51:12 -06:00
Add the full source of BambuStudio
using version 1.0.10
This commit is contained in:
parent
30bcadab3e
commit
1555904bef
3771 changed files with 1251328 additions and 0 deletions
93
t/angles.t
Normal file
93
t/angles.t
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 34;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(rad2deg_dir angle3points PI);
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
is line_atan([ [0, 0], [10, 0] ]), (0), 'E atan2';
|
||||
is line_atan([ [10, 0], [0, 0] ]), (PI), 'W atan2';
|
||||
is line_atan([ [0, 0], [0, 10] ]), (PI/2), 'N atan2';
|
||||
is line_atan([ [0, 10], [0, 0] ]), -(PI/2), 'S atan2';
|
||||
|
||||
is line_atan([ [10, 10], [0, 0] ]), -(PI*3/4), 'SW atan2';
|
||||
is line_atan([ [0, 0], [10, 10] ]), (PI*1/4), 'NE atan2';
|
||||
is line_atan([ [0, 10], [10, 0] ]), -(PI*1/4), 'SE atan2';
|
||||
is line_atan([ [10, 0], [0, 10] ]), (PI*3/4), 'NW atan2';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
is line_orientation([ [0, 0], [10, 0] ]), (0), 'E orientation';
|
||||
is line_orientation([ [0, 0], [0, 10] ]), (PI/2), 'N orientation';
|
||||
is line_orientation([ [10, 0], [0, 0] ]), (PI), 'W orientation';
|
||||
is line_orientation([ [0, 10], [0, 0] ]), (PI*3/2), 'S orientation';
|
||||
|
||||
is line_orientation([ [0, 0], [10, 10] ]), (PI*1/4), 'NE orientation';
|
||||
is line_orientation([ [10, 0], [0, 10] ]), (PI*3/4), 'NW orientation';
|
||||
is line_orientation([ [10, 10], [0, 0] ]), (PI*5/4), 'SW orientation';
|
||||
is line_orientation([ [0, 10], [10, 0] ]), (PI*7/4), 'SE orientation';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
is line_direction([ [0, 0], [10, 0] ]), (0), 'E direction';
|
||||
is line_direction([ [10, 0], [0, 0] ]), (0), 'W direction';
|
||||
is line_direction([ [0, 0], [0, 10] ]), (PI/2), 'N direction';
|
||||
is line_direction([ [0, 10], [0, 0] ]), (PI/2), 'S direction';
|
||||
|
||||
is line_direction([ [10, 10], [0, 0] ]), (PI*1/4), 'SW direction';
|
||||
is line_direction([ [0, 0], [10, 10] ]), (PI*1/4), 'NE direction';
|
||||
is line_direction([ [0, 10], [10, 0] ]), (PI*3/4), 'SE direction';
|
||||
is line_direction([ [10, 0], [0, 10] ]), (PI*3/4), 'NW direction';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
is rad2deg_dir(0), 90, 'E (degrees)';
|
||||
is rad2deg_dir(PI), 270, 'W (degrees)';
|
||||
is rad2deg_dir(PI/2), 0, 'N (degrees)';
|
||||
is rad2deg_dir(-(PI/2)), 180, 'S (degrees)';
|
||||
is rad2deg_dir(PI*1/4), 45, 'NE (degrees)';
|
||||
is rad2deg_dir(PI*3/4), 135, 'NW (degrees)';
|
||||
is rad2deg_dir(PI/6), 60, '30°';
|
||||
is rad2deg_dir(PI/6*2), 30, '60°';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
is angle3points([0,0], [10,0], [0,10]), PI/2, 'CW angle3points';
|
||||
is angle3points([0,0], [0,10], [10,0]), PI/2*3, 'CCW angle3points';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
sub line_atan {
|
||||
my ($l) = @_;
|
||||
return Slic3r::Line->new(@$l)->atan2_;
|
||||
}
|
||||
|
||||
sub line_orientation {
|
||||
my ($l) = @_;
|
||||
return Slic3r::Line->new(@$l)->orientation;
|
||||
}
|
||||
|
||||
sub line_direction {
|
||||
my ($l) = @_;
|
||||
return Slic3r::Line->new(@$l)->direction;
|
||||
}
|
||||
22
t/avoid_crossing_perimeters.t
Normal file
22
t/avoid_crossing_perimeters.t
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use Test::More tests => 1;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first sum);
|
||||
use Slic3r;
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('avoid_crossing_perimeters', 2);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
||||
ok my $gcode = Slic3r::Test::gcode($print), "no crash with avoid_crossing_perimeters and multiple objects";
|
||||
}
|
||||
|
||||
__END__
|
||||
137
t/bridges.t
Normal file
137
t/bridges.t
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
use Test::More tests => 16;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first sum);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(scale epsilon deg2rad rad2deg);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $test = sub {
|
||||
my ($bridge_size, $rotate, $expected_angle, $tolerance) = @_;
|
||||
|
||||
my ($x, $y) = @$bridge_size;
|
||||
my $lower = Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new_scale([-2,-2], [$x+2,-2], [$x+2,$y+2], [-2,$y+2]),
|
||||
Slic3r::Polygon->new_scale([0,0], [0,$y], [$x,$y], [$x,0]),
|
||||
);
|
||||
$lower->translate(scale 20, scale 20); # avoid negative coordinates for easier SVG preview
|
||||
$lower->rotate(deg2rad($rotate), [$x/2,$y/2]);
|
||||
my $bridge = $lower->[1]->clone;
|
||||
$bridge->reverse;
|
||||
$bridge = Slic3r::ExPolygon->new($bridge);
|
||||
|
||||
ok check_angle([$lower], $bridge, $expected_angle, $tolerance), 'correct bridge angle for O-shaped overhang';
|
||||
};
|
||||
|
||||
$test->([20,10], 0, 90);
|
||||
$test->([10,20], 0, 0);
|
||||
$test->([20,10], 45, 135, 20);
|
||||
$test->([20,10], 135, 45, 20);
|
||||
}
|
||||
|
||||
{
|
||||
my $bridge = Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new_scale([0,0], [20,0], [20,10], [0,10]),
|
||||
);
|
||||
my $lower = [
|
||||
Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new_scale([-2,0], [0,0], [0,10], [-2,10]),
|
||||
),
|
||||
];
|
||||
$_->translate(scale 20, scale 20) for $bridge, @$lower; # avoid negative coordinates for easier SVG preview
|
||||
|
||||
$lower->[1] = $lower->[0]->clone;
|
||||
$lower->[1]->translate(scale 22, 0);
|
||||
|
||||
ok check_angle($lower, $bridge, 0), 'correct bridge angle for two-sided bridge';
|
||||
}
|
||||
|
||||
{
|
||||
my $bridge = Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new_scale([0,0], [20,0], [10,10], [0,10]),
|
||||
);
|
||||
my $lower = [
|
||||
Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new_scale([0,0], [0,10], [10,10], [10,12], [-2,12], [-2,-2], [22,-2], [22,0]),
|
||||
),
|
||||
];
|
||||
$_->translate(scale 20, scale 20) for $bridge, @$lower; # avoid negative coordinates for easier SVG preview
|
||||
|
||||
ok check_angle($lower, $bridge, 135), 'correct bridge angle for C-shaped overhang';
|
||||
}
|
||||
|
||||
{
|
||||
my $bridge = Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new_scale([10,10],[20,10],[20,20], [10,20]),
|
||||
);
|
||||
my $lower = [
|
||||
Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new_scale([10,10],[10,20],[20,20],[30,30],[0,30],[0,0]),
|
||||
),
|
||||
];
|
||||
$_->translate(scale 20, scale 20) for $bridge, @$lower; # avoid negative coordinates for easier SVG preview
|
||||
|
||||
ok check_angle($lower, $bridge, 45, undef, $bridge->area/2), 'correct bridge angle for square overhang with L-shaped anchors';
|
||||
}
|
||||
|
||||
sub check_angle {
|
||||
my ($lower, $bridge, $expected, $tolerance, $expected_coverage) = @_;
|
||||
|
||||
if (ref($lower) eq 'ARRAY') {
|
||||
$lower = Slic3r::ExPolygon::Collection->new(@$lower);
|
||||
}
|
||||
|
||||
$expected_coverage //= -1;
|
||||
$expected_coverage = $bridge->area if $expected_coverage == -1;
|
||||
|
||||
my $bd = Slic3r::BridgeDetector->new($bridge, $lower, scale 0.5);
|
||||
|
||||
$tolerance //= rad2deg($bd->resolution) + epsilon;
|
||||
$bd->detect_angle;
|
||||
my $result = $bd->angle;
|
||||
my $coverage = $bd->coverage;
|
||||
is sum(map $_->area, @$coverage), $expected_coverage, 'correct coverage area';
|
||||
|
||||
# our epsilon is equal to the steps used by the bridge detection algorithm
|
||||
###use XXX; YYY [ rad2deg($result), $expected ];
|
||||
# returned value must be non-negative, check for that too
|
||||
my $delta=rad2deg($result) - $expected;
|
||||
$delta-=180 if $delta>=180 - epsilon;
|
||||
return defined $result && $result>=0 && abs($delta) < $tolerance;
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('top_solid_layers', 0); # to prevent bridging on sparse infill
|
||||
$config->set('bridge_speed', 99);
|
||||
|
||||
my $print = Slic3r::Test::init_print('bridge', config => $config);
|
||||
|
||||
my %extrusions = (); # angle => length
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1' && ($args->{F} // $self->F)/60 == $config->bridge_speed) {
|
||||
my $line = Slic3r::Line->new_scale(
|
||||
[ $self->X, $self->Y ],
|
||||
[ $info->{new_X}, $info->{new_Y} ],
|
||||
);
|
||||
my $angle = $line->direction;
|
||||
$extrusions{$angle} //= 0;
|
||||
$extrusions{$angle} += $line->length;
|
||||
}
|
||||
});
|
||||
ok !!%extrusions, "bridge is generated";
|
||||
my ($main_angle) = sort { $extrusions{$b} <=> $extrusions{$a} } keys %extrusions;
|
||||
is $main_angle, 0, "bridge has the expected direction";
|
||||
}
|
||||
|
||||
__END__
|
||||
83
t/clean_polylines.t
Normal file
83
t/clean_polylines.t
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 6;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
|
||||
{
|
||||
my $polyline = Slic3r::Polyline->new(
|
||||
[0,0],[1,0],[2,0],[2,1],[2,2],[1,2],[0,2],[0,1],[0,0],
|
||||
);
|
||||
$polyline->simplify(1);
|
||||
is_deeply $polyline->pp, [ [0, 0], [2, 0], [2, 2], [0, 2], [0, 0] ], 'Douglas-Peucker';
|
||||
}
|
||||
|
||||
{
|
||||
my $polyline = Slic3r::Polyline->new(
|
||||
[0,0], [50,50], [100,0], [125,-25], [150,50],
|
||||
);
|
||||
$polyline->simplify(25);
|
||||
is_deeply $polyline->pp, [ [0, 0], [50, 50], [125, -25], [150, 50] ], 'Douglas-Peucker';
|
||||
}
|
||||
|
||||
{
|
||||
my $gear = Slic3r::Polygon->new_scale(
|
||||
[144.9694,317.1543], [145.4181,301.5633], [146.3466,296.921], [131.8436,294.1643], [131.7467,294.1464],
|
||||
[121.7238,291.5082], [117.1631,290.2776], [107.9198,308.2068], [100.1735,304.5101], [104.9896,290.3672],
|
||||
[106.6511,286.2133], [93.453,279.2327], [81.0065,271.4171], [67.7886,286.5055], [60.7927,280.1127],
|
||||
[69.3928,268.2566], [72.7271,264.9224], [61.8152,253.9959], [52.2273,242.8494], [47.5799,245.7224],
|
||||
[34.6577,252.6559], [30.3369,245.2236], [42.1712,236.3251], [46.1122,233.9605], [43.2099,228.4876],
|
||||
[35.0862,211.5672], [33.1441,207.0856], [13.3923,212.1895], [10.6572,203.3273], [6.0707,204.8561],
|
||||
[7.2775,204.4259], [29.6713,196.3631], [25.9815,172.1277], [25.4589,167.2745], [19.8337,167.0129],
|
||||
[5.0625,166.3346], [5.0625,156.9425], [5.3701,156.9282], [21.8636,156.1628], [25.3713,156.4613],
|
||||
[25.4243,155.9976], [29.3432,155.8157], [30.3838,149.3549], [26.3596,147.8137], [27.1085,141.2604],
|
||||
[29.8466,126.8337], [24.5841,124.9201], [10.6664,119.8989], [13.4454,110.9264], [33.1886,116.0691],
|
||||
[38.817,103.1819], [45.8311,89.8133], [30.4286,76.81], [35.7686,70.0812], [48.0879,77.6873],
|
||||
[51.564,81.1635], [61.9006,69.1791], [72.3019,58.7916], [60.5509,42.5416], [68.3369,37.1532],
|
||||
[77.9524,48.1338], [80.405,52.2215], [92.5632,44.5992], [93.0123,44.3223], [106.3561,37.2056],
|
||||
[100.8631,17.4679], [108.759,14.3778], [107.3148,11.1283], [117.0002,32.8627], [140.9109,27.3974],
|
||||
[145.7004,26.4994], [145.1346,6.1011], [154.502,5.4063], [156.9398,25.6501], [171.0557,26.2017],
|
||||
[181.3139,27.323], [186.2377,27.8532], [191.6031,8.5474], [200.6724,11.2756], [197.2362,30.2334],
|
||||
[220.0789,39.1906], [224.3261,41.031], [236.3506,24.4291], [243.6897,28.6723], [234.2956,46.7747],
|
||||
[245.6562,55.1643], [257.2523,65.0901], [261.4374,61.5679], [273.1709,52.8031], [278.555,59.5164],
|
||||
[268.4334,69.8001], [264.1615,72.3633], [268.2763,77.9442], [278.8488,93.5305], [281.4596,97.6332],
|
||||
[286.4487,95.5191], [300.2821,90.5903], [303.4456,98.5849], [286.4523,107.7253], [293.7063,131.1779],
|
||||
[294.9748,135.8787], [314.918,133.8172], [315.6941,143.2589], [300.9234,146.1746], [296.6419,147.0309],
|
||||
[297.1839,161.7052], [296.6136,176.3942], [302.1147,177.4857], [316.603,180.3608], [317.1658,176.7341],
|
||||
[315.215,189.6589], [315.1749,189.6548], [294.9411,187.5222], [291.13,201.7233], [286.2615,215.5916],
|
||||
[291.1944,218.2545], [303.9158,225.1271], [299.2384,233.3694], [285.7165,227.6001], [281.7091,225.1956],
|
||||
[273.8981,237.6457], [268.3486,245.2248], [267.4538,246.4414], [264.8496,250.0221], [268.6392,253.896],
|
||||
[278.5017,265.2131], [272.721,271.4403], [257.2776,258.3579], [234.4345,276.5687], [242.6222,294.8315],
|
||||
[234.9061,298.5798], [227.0321,286.2841], [225.2505,281.8301], [211.5387,287.8187], [202.3025,291.0935],
|
||||
[197.307,292.831], [199.808,313.1906], [191.5298,315.0787], [187.3082,299.8172], [186.4201,295.3766],
|
||||
[180.595,296.0487], [161.7854,297.4248], [156.8058,297.6214], [154.3395,317.8592],
|
||||
);
|
||||
|
||||
my $num_points = scalar @$gear;
|
||||
my $simplified = $gear->simplify(1000);
|
||||
ok @$simplified == 1, 'gear simplified to a single polygon';
|
||||
###note sprintf "original points: %d\nnew points: %d", $num_points, scalar(@{$simplified->[0]});
|
||||
ok @{$simplified->[0]} < $num_points, 'gear was further simplified using Douglas-Peucker';
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
my $hole_in_square = Slic3r::Polygon->new( # cw
|
||||
[140, 140],
|
||||
[140, 160],
|
||||
[160, 160],
|
||||
[160, 140],
|
||||
);
|
||||
my $simplified = $hole_in_square->simplify(2);
|
||||
is scalar(@$simplified), 1, 'hole simplification returns one polygon';
|
||||
ok $simplified->[0]->is_counter_clockwise, 'hole simplification turns cw polygon into ccw polygon';
|
||||
}
|
||||
|
||||
87
t/collinear.t
Normal file
87
t/collinear.t
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 11;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(collinear);
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my @lines = (
|
||||
Slic3r::Line->new([0,4], [4,2]),
|
||||
Slic3r::Line->new([2,3], [8,0]),
|
||||
Slic3r::Line->new([6,1], [8,0]),
|
||||
);
|
||||
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
||||
is collinear($lines[1], $lines[2]), 1, 'collinear';
|
||||
is collinear($lines[0], $lines[2]), 1, 'collinear';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
# horizontal
|
||||
my @lines = (
|
||||
Slic3r::Line->new([0,1], [5,1]),
|
||||
Slic3r::Line->new([2,1], [8,1]),
|
||||
);
|
||||
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
# vertical
|
||||
my @lines = (
|
||||
Slic3r::Line->new([1,0], [1,5]),
|
||||
Slic3r::Line->new([1,2], [1,8]),
|
||||
);
|
||||
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
# non overlapping
|
||||
my @lines = (
|
||||
Slic3r::Line->new([0,1], [5,1]),
|
||||
Slic3r::Line->new([7,1], [10,1]),
|
||||
);
|
||||
is collinear($lines[0], $lines[1], 1), 0, 'non overlapping';
|
||||
is collinear($lines[0], $lines[1], 0), 1, 'overlapping';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
# with one common point
|
||||
my @lines = (
|
||||
Slic3r::Line->new([0,4], [4,2]),
|
||||
Slic3r::Line->new([4,2], [8,0]),
|
||||
);
|
||||
is collinear($lines[0], $lines[1], 1), 1, 'one common point';
|
||||
is collinear($lines[0], $lines[1], 0), 1, 'one common point';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
# not collinear
|
||||
my @lines = (
|
||||
Slic3r::Line->new([290000000,690525600], [285163380,684761540]),
|
||||
Slic3r::Line->new([285163380,684761540], [193267599,575244400]),
|
||||
);
|
||||
is collinear($lines[0], $lines[1], 0), 0, 'not collinear';
|
||||
is collinear($lines[0], $lines[1], 1), 0, 'not collinear';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
166
t/combineinfill.t
Normal file
166
t/combineinfill.t
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Surface ':types';
|
||||
use Slic3r::Test;
|
||||
|
||||
plan tests => 8;
|
||||
|
||||
{
|
||||
my $test = sub {
|
||||
my ($config) = @_;
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok my $gcode = Slic3r::Test::gcode($print), "infill_every_layers does not crash";
|
||||
|
||||
my $tool = undef;
|
||||
my %layers = (); # layer_z => 1
|
||||
my %layer_infill = (); # layer_z => has_infill
|
||||
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 && $tool != $config->support_material_extruder-1) {
|
||||
$layer_infill{$self->Z} //= 0;
|
||||
if ($tool == $config->infill_extruder-1) {
|
||||
$layer_infill{$self->Z} = 1;
|
||||
}
|
||||
}
|
||||
# Previously, all G-code commands had a fixed number of decimal points with means with redundant zeros after decimal points.
|
||||
# We changed this behavior and got rid of these redundant padding zeros, which caused this test to fail
|
||||
# because the position in Z-axis is compared as a string, and previously, G-code contained the following two commands:
|
||||
# "G1 Z5 F5000 ; lift nozzle"
|
||||
# "G1 Z5.000 F7800.000"
|
||||
# That has a different Z-axis position from the view of string comparisons of floating-point numbers.
|
||||
# To correct the computation of the number of printed layers, even in the case of string comparisons of floating-point numbers,
|
||||
# we filtered out the G-code command with the commend 'lift nozzle'.
|
||||
$layers{$args->{Z}} = 1 if $cmd eq 'G1' && $info->{dist_Z} && index($info->{comment}, 'lift nozzle') == -1;
|
||||
});
|
||||
|
||||
my $layers_with_perimeters = scalar(keys %layer_infill);
|
||||
my $layers_with_infill = grep $_ > 0, values %layer_infill;
|
||||
is scalar(keys %layers), $layers_with_perimeters+$config->raft_layers, 'expected number of layers';
|
||||
|
||||
if ($config->raft_layers == 0) {
|
||||
# first infill layer printed directly on print bed is not combined, so we don't consider it.
|
||||
$layers_with_infill--;
|
||||
$layers_with_perimeters--;
|
||||
}
|
||||
|
||||
# we expect that infill is generated for half the number of combined layers
|
||||
# plus for each single layer that was not combined (remainder)
|
||||
is $layers_with_infill,
|
||||
int($layers_with_perimeters/$config->infill_every_layers) + ($layers_with_perimeters % $config->infill_every_layers),
|
||||
'infill is only present in correct number of layers';
|
||||
};
|
||||
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('layer_height', 0.2);
|
||||
$config->set('first_layer_height', 0.2);
|
||||
$config->set('nozzle_diameter', [0.5,0.5,0.5,0.5]);
|
||||
$config->set('infill_every_layers', 2);
|
||||
$config->set('perimeter_extruder', 1);
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('wipe_into_infill', 0);
|
||||
$config->set('support_material_extruder', 3);
|
||||
$config->set('support_material_interface_extruder', 3);
|
||||
$config->set('top_solid_layers', 0);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
$test->($config);
|
||||
|
||||
$config->set('skirts', 0); # prevent usage of perimeter_extruder in raft layers
|
||||
$config->set('raft_layers', 5);
|
||||
$test->($config);
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('layer_height', 0.2);
|
||||
$config->set('first_layer_height', 0.2);
|
||||
$config->set('nozzle_diameter', [0.5]);
|
||||
$config->set('infill_every_layers', 2);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
$print->process;
|
||||
|
||||
ok defined(first { @{$_->get_region(0)->fill_surfaces->filter_by_type(S_TYPE_INTERNALVOID)} > 0 }
|
||||
@{$print->print->get_object(0)->layers}),
|
||||
'infill combination produces internal void surfaces';
|
||||
|
||||
# we disable combination after infill has been generated
|
||||
$config->set('infill_every_layers', 1);
|
||||
$print->apply($print->print->model->clone, $config);
|
||||
$print->process;
|
||||
|
||||
ok !(defined first { @{$_->get_region(0)->fill_surfaces} == 0 }
|
||||
@{$print->print->get_object(0)->layers}),
|
||||
'infill combination is idempotent';
|
||||
}
|
||||
|
||||
# the following needs to be adapted to the new API
|
||||
if (0) {
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('solid_layers', 0);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
$config->set('top_solid_layers', 0);
|
||||
$config->set('infill_every_layers', 6);
|
||||
$config->set('layer_height', 0.06);
|
||||
$config->set('perimeters', 1);
|
||||
|
||||
my $test = sub {
|
||||
my ($shift) = @_;
|
||||
|
||||
my $self = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
|
||||
$shift /= &Slic3r::SCALING_FACTOR;
|
||||
my $scale = 4; # make room for fat infill lines with low layer height
|
||||
|
||||
# Put a slope on the box's sides by shifting x and y coords by $tilt * (z / boxheight).
|
||||
# The test here is to put such a slight slope on the walls that it should
|
||||
# not trigger any extra fill on fill layers that should be empty when
|
||||
# combine infill is enabled.
|
||||
$_->[0] += $shift * ($_->[2] / (20 / &Slic3r::SCALING_FACTOR)) for @{$self->objects->[0]->meshes->[0]->vertices};
|
||||
$_->[1] += $shift * ($_->[2] / (20 / &Slic3r::SCALING_FACTOR)) for @{$self->objects->[0]->meshes->[0]->vertices};
|
||||
$_ = [$_->[0]*$scale, $_->[1]*$scale, $_->[2]] for @{$self->objects->[0]->meshes->[0]->vertices};
|
||||
|
||||
# copy of Print::export_gcode() up to the point
|
||||
# after fill surfaces are combined
|
||||
$_->slice for @{$self->objects};
|
||||
$_->make_perimeters for @{$self->objects};
|
||||
$_->detect_surfaces_type for @{$self->objects};
|
||||
$_->prepare_fill_surfaces for map @{$_->regions}, map @{$_->layers}, @{$self->objects};
|
||||
$_->process_external_surfaces for map @{$_->regions}, map @{$_->layers}, @{$self->objects};
|
||||
$_->discover_horizontal_shells for @{$self->objects};
|
||||
$_->combine_infill for @{$self->objects};
|
||||
|
||||
# Only layers with id % 6 == 0 should have fill.
|
||||
my $spurious_infill = 0;
|
||||
foreach my $layer (map @{$_->layers}, @{$self->objects}) {
|
||||
++$spurious_infill if ($layer->id % 6 && grep @{$_->fill_surfaces} > 0, @{$layer->regions});
|
||||
}
|
||||
|
||||
$spurious_infill -= scalar(@{$self->objects->[0]->layers} - 1) % 6;
|
||||
|
||||
fail "spurious fill surfaces found on layers that should have none (walls " . sprintf("%.4f", Slic3r::Geometry::rad2deg(atan2($shift, 20/&Slic3r::SCALING_FACTOR))) . " degrees off vertical)"
|
||||
unless $spurious_infill == 0;
|
||||
1;
|
||||
};
|
||||
|
||||
# Test with mm skew offsets for the top of the 20mm-high box
|
||||
for my $shift (0, 0.0001, 1) {
|
||||
ok $test->($shift), "no spurious fill surfaces with box walls " . sprintf("%.4f",Slic3r::Geometry::rad2deg(atan2($shift, 20))) . " degrees off of vertical";
|
||||
}
|
||||
}
|
||||
|
||||
__END__
|
||||
20
t/config.t
Normal file
20
t/config.t
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use Test::More tests => 1;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('perimeter_extrusion_width', '250%');
|
||||
ok $config->validate, 'percent extrusion width is validated';
|
||||
}
|
||||
|
||||
__END__
|
||||
214
t/cooling.t
Normal file
214
t/cooling.t
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 14;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(none all);
|
||||
use Slic3r;
|
||||
use Slic3r::Test;
|
||||
|
||||
my $gcodegen;
|
||||
sub buffer {
|
||||
my $config = shift;
|
||||
if (defined($config)) {
|
||||
$config = $config->clone();
|
||||
} else {
|
||||
$config = Slic3r::Config->new;
|
||||
}
|
||||
my $config_override = shift;
|
||||
foreach my $key (keys %{$config_override}) {
|
||||
$config->set($key, ${$config_override}{$key});
|
||||
}
|
||||
|
||||
my $print_config = Slic3r::Config::Print->new;
|
||||
$print_config->apply_dynamic($config);
|
||||
|
||||
$gcodegen = Slic3r::GCode->new;
|
||||
$gcodegen->apply_print_config($print_config);
|
||||
$gcodegen->set_layer_count(10);
|
||||
|
||||
my $extruders_ref = shift;
|
||||
$extruders_ref = [ 0 ] if !defined $extruders_ref;
|
||||
$gcodegen->set_extruders($extruders_ref);
|
||||
return Slic3r::GCode::CoolingBuffer->new($gcodegen);
|
||||
}
|
||||
|
||||
my $gcode1 = "G1 X100 E1 F3000\n";
|
||||
my $print_time1 = 100 / (3000 / 60); # 2 sec
|
||||
my $gcode2 = $gcode1 . "G1 X0 E1 F3000\n";
|
||||
my $print_time2 = 2 * $print_time1; # 4 sec
|
||||
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
# Default cooling settings.
|
||||
$config->set('bridge_fan_speed', [ 100 ]);
|
||||
$config->set('cooling', [ 1 ]);
|
||||
$config->set('fan_always_on', [ 0 ]);
|
||||
$config->set('fan_below_layer_time', [ 60 ]);
|
||||
$config->set('max_fan_speed', [ 100 ]);
|
||||
$config->set('min_print_speed', [ 10 ]);
|
||||
$config->set('slowdown_below_layer_time', [ 5 ]);
|
||||
# Default print speeds.
|
||||
$config->set('bridge_speed', 60);
|
||||
$config->set('external_perimeter_speed', '50%');
|
||||
$config->set('first_layer_speed', 30);
|
||||
$config->set('gap_fill_speed', 20);
|
||||
$config->set('infill_speed', 80);
|
||||
$config->set('perimeter_speed', 60);
|
||||
$config->set('small_perimeter_speed', 15);
|
||||
$config->set('solid_infill_speed', 20);
|
||||
$config->set('top_solid_infill_speed', 15);
|
||||
$config->set('max_print_speed', 80);
|
||||
# Override for tests.
|
||||
$config->set('disable_fan_first_layers', [ 0 ]);
|
||||
|
||||
{
|
||||
my $gcode_src = "G1 F3000;_EXTRUDE_SET_SPEED\nG1 X100 E1";
|
||||
# Print time of $gcode.
|
||||
my $print_time = 100 / (3000 / 60);
|
||||
my $buffer = buffer($config, { 'slowdown_below_layer_time' => [ $print_time * 0.999 ] });
|
||||
my $gcode = $buffer->process_layer($gcode_src, 0);
|
||||
like $gcode, qr/F3000/, 'speed is not altered when elapsed time is greater than slowdown threshold';
|
||||
}
|
||||
|
||||
{
|
||||
my $gcode_src =
|
||||
"G1 X50 F2500\n" .
|
||||
"G1 F3000;_EXTRUDE_SET_SPEED\n" .
|
||||
"G1 X100 E1\n" .
|
||||
";_EXTRUDE_END\n" .
|
||||
"G1 E4 F400",
|
||||
# Print time of $gcode.
|
||||
my $print_time = 50 / (2500 / 60) + 100 / (3000 / 60) + 4 / (400 / 60);
|
||||
my $buffer = buffer($config, { 'slowdown_below_layer_time' => [ $print_time * 1.001 ] });
|
||||
my $gcode = $buffer->process_layer($gcode_src, 0);
|
||||
unlike $gcode, qr/F3000/, 'speed is altered when elapsed time is lower than slowdown threshold';
|
||||
like $gcode, qr/F2500/, 'speed is not altered for travel moves';
|
||||
like $gcode, qr/F400/, 'speed is not altered for extruder-only moves';
|
||||
}
|
||||
|
||||
{
|
||||
my $buffer = buffer($config, {
|
||||
'fan_below_layer_time' => [ $print_time1 * 0.88 ],
|
||||
'slowdown_below_layer_time' => [ $print_time1 * 0.99 ]
|
||||
});
|
||||
my $gcode = $buffer->process_layer($gcode1, 0);
|
||||
unlike $gcode, qr/M106/, 'fan is not activated when elapsed time is greater than fan threshold';
|
||||
}
|
||||
|
||||
{
|
||||
my $gcode .= buffer($config, { 'slowdown_below_layer_time', [ $print_time2 * 0.99 ] })->process_layer($gcode2, 0);
|
||||
like $gcode, qr/F3000/, 'slowdown is computed on all objects printing at the same Z';
|
||||
}
|
||||
|
||||
{
|
||||
# use an elapsed time which is < the threshold but greater than it when summed twice
|
||||
my $buffer = buffer($config, {
|
||||
'fan_below_layer_time' => [ $print_time2 * 0.65],
|
||||
'slowdown_below_layer_time' => [ $print_time2 * 0.7 ]
|
||||
});
|
||||
my $gcode = $buffer->process_layer($gcode2, 0) .
|
||||
$buffer->process_layer($gcode2, 1);
|
||||
unlike $gcode, qr/M106/, 'fan is not activated on all objects printing at different Z';
|
||||
}
|
||||
|
||||
{
|
||||
# use an elapsed time which is < the threshold even when summed twice
|
||||
my $buffer = buffer($config, {
|
||||
'fan_below_layer_time' => [ $print_time2 + 1 ],
|
||||
'slowdown_below_layer_time' => [ $print_time2 + 2 ]
|
||||
});
|
||||
my $gcode = $buffer->process_layer($gcode2, 0) .
|
||||
$buffer->process_layer($gcode2, 1);
|
||||
like $gcode, qr/M106/, 'fan is activated on all objects printing at different Z';
|
||||
}
|
||||
|
||||
{
|
||||
my $buffer = buffer($config, {
|
||||
'cooling' => [ 1 , 0 ],
|
||||
'fan_below_layer_time' => [ $print_time2 + 1, $print_time2 + 1 ],
|
||||
'slowdown_below_layer_time' => [ $print_time2 + 2, $print_time2 + 2 ]
|
||||
},
|
||||
[ 0, 1]);
|
||||
my $gcode = $buffer->process_layer($gcode1 . "T1\nG1 X0 E1 F3000\n", 0);
|
||||
like $gcode, qr/^M106/, 'fan is activated for the 1st tool';
|
||||
like $gcode, qr/.*M107/, 'fan is disabled for the 2nd tool';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('cooling', [ 1 ]);
|
||||
$config->set('bridge_fan_speed', [ 100 ]);
|
||||
$config->set('fan_below_layer_time', [ 0 ]);
|
||||
$config->set('slowdown_below_layer_time', [ 0 ]);
|
||||
$config->set('bridge_speed', 99);
|
||||
$config->set('top_solid_layers', 1); # internal bridges use solid_infil speed
|
||||
$config->set('bottom_solid_layers', 1); # internal bridges use solid_infil speed
|
||||
|
||||
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
||||
my $fan = 0;
|
||||
my $fan_with_incorrect_speeds = my $fan_with_incorrect_print_speeds = 0;
|
||||
my $bridge_with_no_fan = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'M106') {
|
||||
$fan = $args->{S};
|
||||
$fan_with_incorrect_speeds++ if $fan != 255;
|
||||
} elsif ($cmd eq 'M107') {
|
||||
$fan = 0;
|
||||
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
$fan_with_incorrect_print_speeds++
|
||||
if ($fan > 0) && ($args->{F} // $self->F) != 60*$config->bridge_speed;
|
||||
$bridge_with_no_fan++
|
||||
if !$fan && ($args->{F} // $self->F) == 60*$config->bridge_speed;
|
||||
}
|
||||
});
|
||||
ok !$fan_with_incorrect_speeds, 'bridge fan speed is applied correctly';
|
||||
ok !$fan_with_incorrect_print_speeds, 'bridge fan is only turned on for bridges';
|
||||
ok !$bridge_with_no_fan, 'bridge fan is turned on for all bridges';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('cooling', [ 1 ]);
|
||||
$config->set('fan_below_layer_time', [ 0 ]);
|
||||
$config->set('slowdown_below_layer_time', [ 10 ]);
|
||||
$config->set('min_print_speed', [ 0 ]);
|
||||
$config->set('start_gcode', '');
|
||||
$config->set('first_layer_speed', '100%');
|
||||
$config->set('external_perimeter_speed', 99);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my @layer_times = (0); # in seconds
|
||||
my %layer_external = (); # z => 1
|
||||
Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1') {
|
||||
if ($info->{dist_Z}) {
|
||||
push @layer_times, 0;
|
||||
$layer_external{ $args->{Z} } = 0;
|
||||
}
|
||||
$layer_times[-1] += abs($info->{dist_XY} || $info->{dist_E} || $info->{dist_Z} || 0) / ($args->{F} // $self->F) * 60;
|
||||
if ($args->{F} && $args->{F} == $config->external_perimeter_speed*60) {
|
||||
$layer_external{ $self->Z }++;
|
||||
}
|
||||
}
|
||||
});
|
||||
@layer_times = grep $_, @layer_times;
|
||||
my $all_below = none { $_ < $config->slowdown_below_layer_time->[0] } @layer_times;
|
||||
ok $all_below, 'slowdown_below_layer_time is honored';
|
||||
|
||||
# check that all layers have at least one unaltered external perimeter speed
|
||||
# my $external = all { $_ > 0 } values %layer_external;
|
||||
# ok $external, 'slowdown_below_layer_time does not alter external perimeters';
|
||||
}
|
||||
|
||||
__END__
|
||||
210
t/custom_gcode.t
Normal file
210
t/custom_gcode.t
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
use Test::More tests => 38;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
|
||||
my $test = sub {
|
||||
my ($conf) = @_;
|
||||
$conf ||= $config;
|
||||
|
||||
my $print = Slic3r::Test::init_print('2x20x10', config => $conf);
|
||||
|
||||
my $last_move_was_z_change = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($last_move_was_z_change && $cmd ne $config->layer_gcode) {
|
||||
fail 'custom layer G-code was not applied after Z change';
|
||||
}
|
||||
if (!$last_move_was_z_change && $cmd eq $config->layer_gcode) {
|
||||
fail 'custom layer G-code was not applied after Z change';
|
||||
}
|
||||
|
||||
$last_move_was_z_change = (defined $info->{dist_Z} && $info->{dist_Z} > 0);
|
||||
});
|
||||
|
||||
1;
|
||||
};
|
||||
|
||||
$config->set('start_gcode', '_MY_CUSTOM_START_GCODE_'); # to avoid dealing with the nozzle lift in start G-code
|
||||
$config->set('layer_gcode', '_MY_CUSTOM_LAYER_GCODE_');
|
||||
ok $test->(), "custom layer G-code is applied after Z move and before other moves";
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('output_filename_format', 'ts_[travel_speed]_lh_[layer_height].gcode');
|
||||
$config->set('start_gcode', "TRAVEL:[travel_speed] HEIGHT:[layer_height]\n");
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
|
||||
my $output_file = $print->print->output_filepath;
|
||||
my ($t, $h) = map $config->$_, qw(travel_speed layer_height);
|
||||
ok $output_file =~ /ts_${t}_/, 'print config options are replaced in output filename';
|
||||
ok $output_file =~ /lh_$h\./, 'region config options are replaced in output filename';
|
||||
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
ok $gcode =~ /TRAVEL:$t/, 'print config options are replaced in custom G-code';
|
||||
ok $gcode =~ /HEIGHT:$h/, 'region config options are replaced in custom G-code';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('extruder', 2);
|
||||
$config->set('first_layer_temperature', [200,205]);
|
||||
|
||||
{
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
ok $gcode =~ /M104 S205 T1/, 'temperature set correctly for non-zero yet single extruder';
|
||||
ok $gcode !~ /M104 S\d+ T0/, 'unused extruder correctly ignored';
|
||||
}
|
||||
|
||||
$config->set('infill_extruder', 1);
|
||||
{
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
ok $gcode =~ /M104 S200 T0/, 'temperature set correctly for first extruder';
|
||||
ok $gcode =~ /M104 S205 T1/, 'temperature set correctly for second extruder';
|
||||
}
|
||||
|
||||
my @start_gcode = (qq!
|
||||
;__temp0:[first_layer_temperature_0]__
|
||||
;__temp1:[first_layer_temperature_1]__
|
||||
;__temp2:[first_layer_temperature_2]__
|
||||
!, qq!
|
||||
;__temp0:{first_layer_temperature[0]}__
|
||||
;__temp1:{first_layer_temperature[1]}__
|
||||
;__temp2:{first_layer_temperature[2]}__
|
||||
!);
|
||||
my @syntax_description = (' (legacy syntax)', ' (new syntax)');
|
||||
for my $i (0, 1) {
|
||||
$config->set('start_gcode', $start_gcode[$i]);
|
||||
{
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
# we use the [infill_extruder] placeholder to make sure this test doesn't
|
||||
# catch a false positive caused by the unparsed start G-code option itself
|
||||
# being embedded in the G-code
|
||||
ok $gcode =~ /temp0:200/, 'temperature placeholder for first extruder correctly populated' . $syntax_description[$i];
|
||||
ok $gcode =~ /temp1:205/, 'temperature placeholder for second extruder correctly populated' . $syntax_description[$i];
|
||||
ok $gcode =~ /temp2:200/, 'temperature placeholder for unused extruder populated with first value' . $syntax_description[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$config->set('start_gcode', qq!
|
||||
;substitution:{if infill_extruder==1}extruder1
|
||||
{elsif infill_extruder==2}extruder2
|
||||
{else}extruder3{endif}
|
||||
!);
|
||||
{
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
ok $gcode =~ /substitution:extruder1/, 'if / else / endif - first block returned';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('before_layer_gcode', ';BEFORE [layer_num]');
|
||||
$config->set('layer_gcode', ';CHANGE [layer_num]');
|
||||
$config->set('support_material', 1);
|
||||
$config->set('layer_height', 0.2);
|
||||
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
|
||||
my @before = ();
|
||||
my @change = ();
|
||||
foreach my $line (split /\R+/, $gcode) {
|
||||
if ($line =~ /;BEFORE (\d+)/) {
|
||||
push @before, $1;
|
||||
} elsif ($line =~ /;CHANGE (\d+)/) {
|
||||
push @change, $1;
|
||||
fail 'inconsistent layer_num before and after layer change'
|
||||
if $1 != $before[-1];
|
||||
}
|
||||
}
|
||||
is_deeply \@before, \@change, 'layer_num is consistent before and after layer changes';
|
||||
ok !defined(first { $change[$_] != $change[$_-1]+1 } 1..$#change),
|
||||
'layer_num grows continously'; # i.e. no duplicates or regressions
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6,0.6]);
|
||||
$config->set('start_gcode', qq!
|
||||
;substitution:{if infill_extruder==1}if block
|
||||
{elsif infill_extruder==2}elsif block 1
|
||||
{elsif infill_extruder==3}elsif block 2
|
||||
{elsif infill_extruder==4}elsif block 3
|
||||
{else}endif block{endif}
|
||||
!);
|
||||
my @returned = ('', 'if block', 'elsif block 1', 'elsif block 2', 'elsif block 3', 'endif block');
|
||||
for my $i (1,2,3,4,5) {
|
||||
$config->set('infill_extruder', $i);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
my $found_other = 0;
|
||||
for my $j (1,2,3,4,5) {
|
||||
next if $i == $j;
|
||||
$found_other = 1 if $gcode =~ /substitution:$returned[$j]/;
|
||||
}
|
||||
ok $gcode =~ /substitution:$returned[$i]/, 'if / else / endif - ' . $returned[$i] . ' returned';
|
||||
ok !$found_other, 'if / else / endif - only ' . $returned[$i] . ' returned';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('start_gcode',
|
||||
';substitution:{if infill_extruder==1}{if perimeter_extruder==1}block11{else}block12{endif}' .
|
||||
'{elsif infill_extruder==2}{if perimeter_extruder==1}block21{else}block22{endif}' .
|
||||
'{else}{if perimeter_extruder==1}block31{else}block32{endif}{endif}:end');
|
||||
for my $i (1,2,3) {
|
||||
$config->set('infill_extruder', $i);
|
||||
for my $j (1,2) {
|
||||
$config->set('perimeter_extruder', $j);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
ok $gcode =~ /substitution:block$i$j:end/, "two level if / else / endif - block$i$j returned";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('start_gcode',
|
||||
';substitution:{if notes=="MK2"}MK2{elsif notes=="MK3"}MK3{else}MK1{endif}:end');
|
||||
for my $printer_name ("MK2", "MK3", "MK1") {
|
||||
$config->set('notes', $printer_name);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
ok $gcode =~ /substitution:$printer_name:end/, "printer name $printer_name matched";
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('complete_objects', 1);
|
||||
$config->set('between_objects_gcode', '_MY_CUSTOM_GCODE_');
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 3);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
is scalar(() = $gcode =~ /^_MY_CUSTOM_GCODE_/gm), 2, 'between_objects_gcode is applied correctly';
|
||||
}
|
||||
|
||||
__END__
|
||||
93
t/dynamic.t
Normal file
93
t/dynamic.t
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan skip_all => 'variable-width paths are currently disabled';
|
||||
plan tests => 20;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(X Y scale epsilon);
|
||||
use Slic3r::Surface ':types';
|
||||
|
||||
sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
|
||||
|
||||
{
|
||||
my $square = Slic3r::ExPolygon->new([
|
||||
scale_points [0,0], [10,0], [10,10], [0,10],
|
||||
]);
|
||||
|
||||
my @offsets = @{$square->noncollapsing_offset_ex(- scale 5)};
|
||||
is scalar @offsets, 1, 'non-collapsing offset';
|
||||
}
|
||||
|
||||
{
|
||||
local $Slic3r::Config = Slic3r::Config->new(
|
||||
perimeters => 3,
|
||||
);
|
||||
my $w = 0.7;
|
||||
my $perimeter_flow = Slic3r::Flow->new(
|
||||
nozzle_diameter => 0.5,
|
||||
layer_height => 0.4,
|
||||
width => $w,
|
||||
);
|
||||
|
||||
my $print = Slic3r::Print->new;
|
||||
my $region = Slic3r::Print::Region->new(
|
||||
print => $print,
|
||||
flows => { perimeter => $perimeter_flow },
|
||||
);
|
||||
push @{$print->regions}, $region;
|
||||
my $object = Slic3r::Print::Object->new(
|
||||
print => $print,
|
||||
size => [1,1],
|
||||
);
|
||||
my $make_layer = sub {
|
||||
my ($width) = @_;
|
||||
my $layer = Slic3r::Layer->new(
|
||||
object => $object,
|
||||
id => 1,
|
||||
slices => [
|
||||
Slic3r::Surface->new(
|
||||
surface_type => S_TYPE_INTERNAL,
|
||||
expolygon => Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,$width], [0,$width] ]),
|
||||
),
|
||||
],
|
||||
thin_walls => [],
|
||||
);
|
||||
my $layerm = $layer->region(0);
|
||||
$layer->make_perimeters;
|
||||
return $layerm;
|
||||
};
|
||||
|
||||
my %widths = (
|
||||
1 * $w => { perimeters => 1, gaps => 0 },
|
||||
1.3 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 0.2 * $w)->spacing },
|
||||
1.5 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 0.5 * $w)->spacing },
|
||||
2 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->spacing },
|
||||
2.5 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 1.5 * $w)->spacing },
|
||||
3 * $w => { perimeters => 2, gaps => 0 },
|
||||
4 * $w => { perimeters => 2, gaps => 1, gap_flow_spacing => $perimeter_flow->spacing },
|
||||
);
|
||||
|
||||
foreach my $width (sort keys %widths) {
|
||||
my $layerm = $make_layer->($width);
|
||||
is scalar @{$layerm->perimeters}, $widths{$width}{perimeters}, 'right number of perimeters';
|
||||
is scalar @{$layerm->thin_fills} ? 1 : 0, $widths{$width}{gaps},
|
||||
($widths{$width}{gaps} ? 'gaps were filled' : 'no gaps detected'); # TODO: we should check the exact number of gaps, but we need a better medial axis algorithm
|
||||
|
||||
my @gaps = map $_, @{$layerm->thin_fills};
|
||||
if (@gaps) {
|
||||
ok +(!first { abs($_->flow_spacing - $widths{$width}{gap_flow_spacing}) > epsilon } @gaps),
|
||||
'flow spacing was dynamically adjusted';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__END__
|
||||
318
t/fill.t
Normal file
318
t/fill.t
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#plan tests => 43;
|
||||
# Test of a 100% coverage is off.
|
||||
plan tests => 19;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first sum);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(X Y scale unscale convex_hull);
|
||||
use Slic3r::Geometry::Clipper qw(union diff diff_ex offset offset2_ex);
|
||||
use Slic3r::Surface qw(:types);
|
||||
use Slic3r::Test;
|
||||
|
||||
sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
|
||||
|
||||
{
|
||||
my $expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,50], [0,50] ]);
|
||||
my $filler = Slic3r::Filler->new_from_type('rectilinear');
|
||||
$filler->set_bounding_box($expolygon->bounding_box);
|
||||
$filler->set_angle(0);
|
||||
my $surface = Slic3r::Surface->new(
|
||||
surface_type => S_TYPE_TOP,
|
||||
expolygon => $expolygon,
|
||||
);
|
||||
my $flow = Slic3r::Flow->new(
|
||||
width => 0.69,
|
||||
height => 0.4,
|
||||
nozzle_diameter => 0.50,
|
||||
);
|
||||
$filler->set_spacing($flow->spacing);
|
||||
foreach my $angle (0, 45) {
|
||||
$surface->expolygon->rotate(Slic3r::Geometry::deg2rad($angle), [0,0]);
|
||||
my $paths = $filler->fill_surface($surface, layer_height => 0.4, density => 0.4);
|
||||
is scalar @$paths, 1, 'one continuous path';
|
||||
}
|
||||
}
|
||||
|
||||
SKIP:
|
||||
{
|
||||
skip "The FillRectilinear2 does not fill the surface completely", 1;
|
||||
|
||||
my $test = sub {
|
||||
my ($expolygon, $flow_spacing, $angle, $density) = @_;
|
||||
|
||||
my $filler = Slic3r::Filler->new_from_type('rectilinear');
|
||||
$filler->set_bounding_box($expolygon->bounding_box);
|
||||
$filler->set_angle($angle // 0);
|
||||
# Adjust line spacing to fill the region.
|
||||
$filler->set_dont_adjust(0);
|
||||
$filler->set_link_max_length(scale(1.2*$flow_spacing));
|
||||
my $surface = Slic3r::Surface->new(
|
||||
surface_type => S_TYPE_BOTTOM,
|
||||
expolygon => $expolygon,
|
||||
);
|
||||
my $flow = Slic3r::Flow->new(
|
||||
width => $flow_spacing,
|
||||
height => 0.4,
|
||||
nozzle_diameter => $flow_spacing,
|
||||
);
|
||||
$filler->set_spacing($flow->spacing);
|
||||
my $paths = $filler->fill_surface(
|
||||
$surface,
|
||||
layer_height => $flow->height,
|
||||
density => $density // 1,
|
||||
);
|
||||
|
||||
# check whether any part was left uncovered
|
||||
my @grown_paths = map @{Slic3r::Polyline->new(@$_)->grow(scale $filler->spacing/2)}, @$paths;
|
||||
my $uncovered = diff_ex([ @$expolygon ], [ @grown_paths ], 1);
|
||||
|
||||
# ignore very small dots
|
||||
my $uncovered_filtered = [ grep $_->area > (scale $flow_spacing)**2, @$uncovered ];
|
||||
|
||||
is scalar(@$uncovered_filtered), 0, 'solid surface is fully filled';
|
||||
|
||||
if (0 && @$uncovered_filtered) {
|
||||
require "Slic3r/SVG.pm";
|
||||
Slic3r::SVG::output("uncovered.svg",
|
||||
no_arrows => 1,
|
||||
expolygons => [ $expolygon ],
|
||||
blue_expolygons => [ @$uncovered ],
|
||||
red_expolygons => [ @$uncovered_filtered ],
|
||||
polylines => [ @$paths ],
|
||||
);
|
||||
exit;
|
||||
}
|
||||
};
|
||||
|
||||
my $expolygon = Slic3r::ExPolygon->new([
|
||||
[6883102, 9598327.01296997],
|
||||
[6883102, 20327272.01297],
|
||||
[3116896, 20327272.01297],
|
||||
[3116896, 9598327.01296997],
|
||||
]);
|
||||
$test->($expolygon, 0.55);
|
||||
|
||||
for (1..20) {
|
||||
$expolygon->scale(1.05);
|
||||
$test->($expolygon, 0.55);
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
$expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [98,0], [98,10], [0,10] ]);
|
||||
$test->($expolygon, 0.5, 45, 0.99); # non-solid infill
|
||||
}
|
||||
|
||||
{
|
||||
my $collection = Slic3r::Polyline::Collection->new(
|
||||
Slic3r::Polyline->new([0,15], [0,18], [0,20]),
|
||||
Slic3r::Polyline->new([0,10], [0,8], [0,5]),
|
||||
);
|
||||
is_deeply
|
||||
[ map $_->[Y], map @$_, @{$collection->chained_path_from(Slic3r::Point->new(0,30), 0)} ],
|
||||
[20, 18, 15, 10, 8, 5],
|
||||
'chained path';
|
||||
}
|
||||
|
||||
{
|
||||
my $collection = Slic3r::Polyline::Collection->new(
|
||||
Slic3r::Polyline->new([4,0], [10,0], [15,0]),
|
||||
Slic3r::Polyline->new([10,5], [15,5], [20,5]),
|
||||
);
|
||||
is_deeply
|
||||
[ map $_->[X], map @$_, @{$collection->chained_path_from(Slic3r::Point->new(30,0), 0)} ],
|
||||
[reverse 4, 10, 15, 10, 15, 20],
|
||||
'chained path';
|
||||
}
|
||||
|
||||
{
|
||||
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
||||
map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
|
||||
Slic3r::Polyline->new([0,15], [0,18], [0,20]),
|
||||
Slic3r::Polyline->new([0,10], [0,8], [0,5]),
|
||||
);
|
||||
is_deeply
|
||||
[ map $_->[Y], map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(0,30), 0)} ],
|
||||
[20, 18, 15, 10, 8, 5],
|
||||
'chained path';
|
||||
}
|
||||
|
||||
{
|
||||
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
||||
map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
|
||||
Slic3r::Polyline->new([15,0], [10,0], [4,0]),
|
||||
Slic3r::Polyline->new([10,5], [15,5], [20,5]),
|
||||
);
|
||||
is_deeply
|
||||
[ map $_->[X], map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(30,0), 0)} ],
|
||||
[reverse 4, 10, 15, 10, 15, 20],
|
||||
'chained path';
|
||||
}
|
||||
|
||||
for my $pattern (qw(rectilinear honeycomb hilbertcurve concentric)) {
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.4,0.4,0.4,0.4]);
|
||||
$config->set('fill_pattern', $pattern);
|
||||
$config->set('top_fill_pattern', $pattern);
|
||||
$config->set('bottom_fill_pattern', $pattern);
|
||||
$config->set('perimeters', 1);
|
||||
$config->set('skirts', 0);
|
||||
$config->set('fill_density', 20);
|
||||
$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)";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.4,0.4,0.4,0.4]);
|
||||
$config->set('infill_only_where_needed', 1);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('infill_extrusion_width', 0.5);
|
||||
$config->set('wipe_into_infill', 0);
|
||||
$config->set('fill_density', 40);
|
||||
$config->set('cooling', [ 0 ]); # for preventing speeds from being altered
|
||||
$config->set('first_layer_speed', '100%'); # for preventing speeds from being altered
|
||||
|
||||
my $test = sub {
|
||||
my $print = Slic3r::Test::init_print('pyramid', config => $config);
|
||||
|
||||
my $tool = undef;
|
||||
my @infill_extrusions = (); # array of polylines
|
||||
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) {
|
||||
push @infill_extrusions, Slic3r::Line->new_scale(
|
||||
[ $self->X, $self->Y ],
|
||||
[ $info->{new_X}, $info->{new_Y} ],
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
return 0 if !@infill_extrusions; # prevent calling convex_hull() with no points
|
||||
|
||||
my $convex_hull = convex_hull([ map $_->pp, map @$_, @infill_extrusions ]);
|
||||
return unscale unscale sum(map $_->area, @{offset([$convex_hull], scale(+$config->infill_extrusion_width/2))});
|
||||
};
|
||||
|
||||
my $tolerance = 5; # mm^2
|
||||
|
||||
$config->set('solid_infill_below_area', 0);
|
||||
ok $test->() < $tolerance,
|
||||
'no infill is generated when using infill_only_where_needed on a pyramid';
|
||||
|
||||
$config->set('solid_infill_below_area', 70);
|
||||
ok abs($test->() - $config->solid_infill_below_area) < $tolerance,
|
||||
'infill is only generated under the forced solid shells';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('perimeters', 1);
|
||||
$config->set('fill_density', 0);
|
||||
$config->set('top_solid_layers', 0);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
$config->set('solid_infill_below_area', 20000000);
|
||||
$config->set('solid_infill_every_layers', 2);
|
||||
$config->set('perimeter_speed', 99);
|
||||
$config->set('external_perimeter_speed', 99);
|
||||
$config->set('cooling', [ 0 ]);
|
||||
$config->set('first_layer_speed', '100%');
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my %layers_with_extrusion = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1' && $info->{dist_XY} > 0 && $info->{extruding}) {
|
||||
if (($args->{F} // $self->F) != $config->perimeter_speed*60) {
|
||||
$layers_with_extrusion{$self->Z} = ($args->{F} // $self->F);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ok !%layers_with_extrusion,
|
||||
"solid_infill_below_area and solid_infill_every_layers are ignored when fill_density is 0";
|
||||
}
|
||||
|
||||
{
|
||||
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,0.35,0.35,0.35]);
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('solid_infill_extruder', 2);
|
||||
$config->set('infill_extrusion_width', 0.52);
|
||||
$config->set('solid_infill_extrusion_width', 0.52);
|
||||
$config->set('first_layer_extrusion_width', 0);
|
||||
|
||||
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 = diff($layer0_infill, $layer1_infill);
|
||||
$diff = offset2_ex($diff, -$grow_d, +$grow_d);
|
||||
$diff = [ grep { $_->area > 2*(($grow_d*2)**2) } @$diff ];
|
||||
is scalar(@$diff), 0, 'no missing parts in solid shell when fill_density is 0';
|
||||
}
|
||||
|
||||
__END__
|
||||
83
t/flow.t
Normal file
83
t/flow.t
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
use Test::More tests => 6;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first sum);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(scale PI);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 1);
|
||||
$config->set('brim_width', 2);
|
||||
$config->set('perimeters', 3);
|
||||
$config->set('fill_density', 0.4);
|
||||
$config->set('bottom_solid_layers', 1);
|
||||
$config->set('first_layer_extrusion_width', 2);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('filament_diameter', [ 3.0 ]);
|
||||
$config->set('nozzle_diameter', [ 0.5 ]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my @E_per_mm = ();
|
||||
Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($self->Z == $config->layer_height) { # only consider first layer
|
||||
if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
|
||||
}
|
||||
}
|
||||
});
|
||||
my $E_per_mm_avg = sum(@E_per_mm) / @E_per_mm;
|
||||
# allow some tolerance because solid rectilinear infill might be adjusted/stretched
|
||||
ok !(defined first { abs($_ - $E_per_mm_avg) > 0.015 } @E_per_mm),
|
||||
'first_layer_extrusion_width applies to everything on first layer';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('bridge_speed', 99);
|
||||
$config->set('bridge_flow_ratio', 1);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds from being altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds from being altered
|
||||
|
||||
my $test = sub {
|
||||
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
||||
my @E_per_mm = ();
|
||||
Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
if (($args->{F} // $self->F) == $config->bridge_speed*60) {
|
||||
push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
|
||||
}
|
||||
}
|
||||
});
|
||||
my $expected_mm3_per_mm = ($config->nozzle_diameter->[0]**2) * PI/4 * $config->bridge_flow_ratio;
|
||||
my $expected_E_per_mm = $expected_mm3_per_mm / ((($config->filament_diameter->[0]/2)**2)*PI);
|
||||
ok !(defined first { abs($_ - $expected_E_per_mm) > 0.01 } @E_per_mm),
|
||||
'expected flow when using bridge_flow_ratio = ' . $config->bridge_flow_ratio;
|
||||
};
|
||||
|
||||
$config->set('bridge_flow_ratio', 0.5);
|
||||
$test->();
|
||||
$config->set('bridge_flow_ratio', 2);
|
||||
$test->();
|
||||
$config->set('extrusion_width', 0.4);
|
||||
$config->set('bridge_flow_ratio', 1);
|
||||
$test->();
|
||||
$config->set('bridge_flow_ratio', 0.5);
|
||||
$test->();
|
||||
$config->set('bridge_flow_ratio', 2);
|
||||
$test->();
|
||||
}
|
||||
|
||||
__END__
|
||||
60
t/gaps.t
Normal file
60
t/gaps.t
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
use Test::More tests => 1;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Flow ':roles';
|
||||
use Slic3r::Geometry qw(PI scale unscale convex_hull);
|
||||
use Slic3r::Surface ':types';
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('perimeter_speed', 66);
|
||||
$config->set('external_perimeter_speed', 66);
|
||||
$config->set('small_perimeter_speed', 66);
|
||||
$config->set('gap_fill_speed', 99);
|
||||
$config->set('perimeters', 1);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds from being altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds from being altered
|
||||
$config->set('perimeter_extrusion_width', 0.35);
|
||||
$config->set('first_layer_extrusion_width', 0.35);
|
||||
|
||||
my $print = Slic3r::Test::init_print('two_hollow_squares', config => $config);
|
||||
my @perimeter_points = ();
|
||||
my $last = ''; # perimeter | gap
|
||||
my $gap_fills_outside_last_perimeters = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
my $F = $args->{F} // $self->F;
|
||||
my $point = Slic3r::Point->new_scale($info->{new_X}, $info->{new_Y});
|
||||
if ($F == $config->perimeter_speed*60) {
|
||||
if ($last eq 'gap') {
|
||||
@perimeter_points = ();
|
||||
}
|
||||
push @perimeter_points, $point;
|
||||
$last = 'perimeter';
|
||||
} elsif ($F == $config->gap_fill_speed*60) {
|
||||
my $convex_hull = convex_hull(\@perimeter_points);
|
||||
if (!$convex_hull->contains_point($point)) {
|
||||
$gap_fills_outside_last_perimeters++;
|
||||
}
|
||||
|
||||
$last = 'gap';
|
||||
}
|
||||
}
|
||||
});
|
||||
is $gap_fills_outside_last_perimeters, 0, 'gap fills are printed before leaving islands';
|
||||
}
|
||||
|
||||
__END__
|
||||
248
t/gcode.t
Normal file
248
t/gcode.t
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
use Test::More tests => 24;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(scale convex_hull);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $gcodegen = Slic3r::GCode->new();
|
||||
$gcodegen->set_layer_count(1);
|
||||
$gcodegen->set_origin(Slic3r::Pointf->new(10, 10));
|
||||
is_deeply $gcodegen->last_pos->arrayref, [scale -10, scale -10], 'last_pos is shifted correctly';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('wipe', [1]);
|
||||
$config->set('retract_layer_change', [0]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $have_wipe = 0;
|
||||
my @retract_speeds = ();
|
||||
my $extruded_on_this_layer = 0;
|
||||
my $wiping_on_new_layer = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{travel} && $info->{dist_Z}) {
|
||||
# changing layer
|
||||
$extruded_on_this_layer = 0;
|
||||
} elsif ($info->{extruding} && $info->{dist_XY}) {
|
||||
$extruded_on_this_layer = 1;
|
||||
} elsif ($info->{retracting} && $info->{dist_XY} > 0) {
|
||||
$have_wipe = 1;
|
||||
$wiping_on_new_layer = 1 if !$extruded_on_this_layer;
|
||||
my $move_time = $info->{dist_XY} / ($args->{F} // $self->F);
|
||||
push @retract_speeds, abs($info->{dist_E}) / $move_time;
|
||||
}
|
||||
});
|
||||
|
||||
ok $have_wipe, "wipe";
|
||||
ok !defined (first { abs($_ - $config->retract_speed->[0]*60) < 5 } @retract_speeds), 'wipe moves don\'t retract faster than configured speed';
|
||||
ok !$wiping_on_new_layer, 'no wiping after layer change';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('z_offset', 5);
|
||||
$config->set('start_gcode', '');
|
||||
|
||||
my $test = sub {
|
||||
my ($comment) = @_;
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $moves_below_z_offset = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{travel} && exists $args->{Z}) {
|
||||
$moves_below_z_offset++ if $args->{Z} < $config->z_offset;
|
||||
}
|
||||
});
|
||||
is $moves_below_z_offset, 0, "no Z moves below Z offset ($comment)";
|
||||
};
|
||||
|
||||
$test->("no lift");
|
||||
|
||||
$config->set('retract_lift', [3]);
|
||||
$test->("lift < z_offset");
|
||||
|
||||
$config->set('retract_lift', [6]);
|
||||
$test->("lift > z_offset");
|
||||
}
|
||||
|
||||
{
|
||||
# This tests the following behavior:
|
||||
# - complete objects does not crash
|
||||
# - no hard-coded "E" are generated
|
||||
# - Z moves are correctly generated for both objects
|
||||
# - no travel moves go outside skirt
|
||||
# - temperatures are set correctly
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_comments', 1);
|
||||
$config->set('complete_objects', 1);
|
||||
$config->set('extrusion_axis', 'A');
|
||||
$config->set('start_gcode', ''); # prevent any default extra Z move
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', 0.4);
|
||||
$config->set('temperature', [200]);
|
||||
$config->set('first_layer_temperature', [210]);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
||||
ok my $gcode = Slic3r::Test::gcode($print), "complete_objects";
|
||||
my @z_moves = ();
|
||||
my @travel_moves = (); # array of scaled points
|
||||
my @extrusions = (); # array of scaled points
|
||||
my @temps = ();
|
||||
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
fail 'unexpected E argument' if defined $args->{E};
|
||||
if (defined $args->{Z}) {
|
||||
push @z_moves, $args->{Z};
|
||||
}
|
||||
|
||||
if ($info->{dist_XY}) {
|
||||
if ($info->{extruding} || $args->{A}) {
|
||||
push @extrusions, Slic3r::Point->new_scale($info->{new_X}, $info->{new_Y});
|
||||
} else {
|
||||
push @travel_moves, Slic3r::Point->new_scale($info->{new_X}, $info->{new_Y})
|
||||
if @extrusions; # skip initial travel move to first skirt point
|
||||
}
|
||||
} elsif ($cmd eq 'M104' || $cmd eq 'M109') {
|
||||
push @temps, $args->{S} if !@temps || $args->{S} != $temps[-1];
|
||||
}
|
||||
});
|
||||
my $layer_count = 20/0.4; # cube is 20mm tall
|
||||
is scalar(@z_moves), 2*$layer_count, 'complete_objects generates the correct number of Z moves';
|
||||
is_deeply [ @z_moves[0..($layer_count-1)] ], [ @z_moves[$layer_count..$#z_moves] ], 'complete_objects generates the correct Z moves';
|
||||
|
||||
my $convex_hull = convex_hull(\@extrusions);
|
||||
ok !(defined first { !$convex_hull->contains_point($_) } @travel_moves), 'all travel moves happen within skirt';
|
||||
|
||||
is_deeply \@temps, [210, 200, 210, 200, 0], 'expected temperature changes';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('retract_length', [1000000]);
|
||||
$config->set('use_relative_e_distances', 1);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
Slic3r::Test::gcode($print);
|
||||
ok $print->print->total_used_filament > 0, 'final retraction is not considered in total used filament';
|
||||
}
|
||||
|
||||
{
|
||||
my $test = sub {
|
||||
my ($print, $comment) = @_;
|
||||
|
||||
my @percent = ();
|
||||
my $got_100 = 0;
|
||||
my $extruding_after_100 = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'M73') {
|
||||
push @percent, $args->{P};
|
||||
$got_100 = 1 if $args->{P} eq '100';
|
||||
}
|
||||
if ($info->{extruding} && $got_100) {
|
||||
$extruding_after_100 = 1;
|
||||
}
|
||||
});
|
||||
# the extruder heater is turned off when M73 P100 is reached
|
||||
ok !(defined first { $_ > 100 } @percent), "M73 is never given more than 100% ($comment)";
|
||||
ok !$extruding_after_100, "no extrusions after M73 P100 ($comment)";
|
||||
};
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
$config->set('raft_layers', 3);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
$test->($print, 'single object');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
||||
$test->($print, 'two copies of single object');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
my $print = Slic3r::Test::init_print(['20mm_cube','20mm_cube'], config => $config);
|
||||
$test->($print, 'two objects');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale_xyz => [1,1, 1/(20/$config->layer_height) ]);
|
||||
$test->($print, 'one layer object');
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('start_gcode', 'START:[input_filename]');
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
like $gcode, qr/START:20mm_cube/, '[input_filename] is also available in custom G-code';
|
||||
}
|
||||
|
||||
# The current Spiral Vase slicing code removes the holes and all but the largest contours from each slice,
|
||||
# therefore the following test is no more valid.
|
||||
#{
|
||||
# my $config = Slic3r::Config::new_from_defaults;
|
||||
# $config->set('spiral_vase', 1);
|
||||
# my $print = Slic3r::Test::init_print('cube_with_hole', config => $config);
|
||||
#
|
||||
# my $spiral = 0;
|
||||
# Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
# my ($self, $cmd, $args, $info) = @_;
|
||||
#
|
||||
# if ($cmd eq 'G1' && exists $args->{E} && exists $args->{Z}) {
|
||||
# $spiral = 1;
|
||||
# }
|
||||
# });
|
||||
#
|
||||
# ok !$spiral, 'spiral vase is correctly disabled on layers with multiple loops';
|
||||
#}
|
||||
|
||||
|
||||
{
|
||||
# Tests that the Repetier flavor produces M201 Xnnn Ynnn for resetting
|
||||
# acceleration, also that M204 Snnn syntax is not generated.
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'repetier');
|
||||
$config->set('default_acceleration', 1337);
|
||||
my $print = Slic3r::Test::init_print('cube_with_hole', config => $config);
|
||||
|
||||
my $has_accel = 0;
|
||||
my $has_m204 = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'M201' && exists $args->{X} && exists $args->{Y}) {
|
||||
if ($args->{X} == 1337 && $args->{Y} == 1337) {
|
||||
$has_accel = 1;
|
||||
}
|
||||
}
|
||||
if ($cmd eq 'M204' && exists $args->{S}) {
|
||||
$has_m204 = 1;
|
||||
}
|
||||
});
|
||||
ok $has_accel, 'M201 is generated for repetier firmware.';
|
||||
ok !$has_m204, 'M204 is not generated for repetier firmware';
|
||||
}
|
||||
|
||||
__END__
|
||||
257
t/geometry.t
Normal file
257
t/geometry.t
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 42;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(PI polygon_is_convex
|
||||
chained_path_from epsilon scale);
|
||||
|
||||
{
|
||||
# this test was failing on Windows (GH #1950)
|
||||
my $polygon = Slic3r::Polygon->new(
|
||||
[207802834,-57084522],[196528149,-37556190],[173626821,-25420928],[171285751,-21366123],
|
||||
[118673592,-21366123],[116332562,-25420928],[93431208,-37556191],[82156517,-57084523],
|
||||
[129714478,-84542120],[160244873,-84542120],
|
||||
);
|
||||
my $point = Slic3r::Point->new(95706562, -57294774);
|
||||
ok $polygon->contains_point($point), 'contains_point';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
my $line1 = [ [5, 15], [30, 15] ];
|
||||
my $line2 = [ [10, 20], [10, 10] ];
|
||||
is_deeply Slic3r::Geometry::line_intersection($line1, $line2, 1)->arrayref, [10, 15], 'line_intersection';
|
||||
|
||||
#==========================================================
|
||||
|
||||
$line1 = [ [73.6310778185108/0.0000001, 371.74239268924/0.0000001], [73.6310778185108/0.0000001, 501.74239268924/0.0000001] ];
|
||||
$line2 = [ [75/0.0000001, 437.9853/0.0000001], [62.7484/0.0000001, 440.4223/0.0000001] ];
|
||||
isnt Slic3r::Geometry::line_intersection($line1, $line2, 1), undef, 'line_intersection';
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $polygon = Slic3r::Polygon->new(
|
||||
[45919000, 515273900], [14726100, 461246400], [14726100, 348753500], [33988700, 315389800],
|
||||
[43749700, 343843000], [45422300, 352251500], [52362100, 362637800], [62748400, 369577600],
|
||||
[75000000, 372014700], [87251500, 369577600], [97637800, 362637800], [104577600, 352251500],
|
||||
[107014700, 340000000], [104577600, 327748400], [97637800, 317362100], [87251500, 310422300],
|
||||
[82789200, 309534700], [69846100, 294726100], [254081000, 294726100], [285273900, 348753500],
|
||||
[285273900, 461246400], [254081000, 515273900],
|
||||
);
|
||||
|
||||
# this points belongs to $polyline
|
||||
# note: it's actually a vertex, while we should better check an intermediate point
|
||||
my $point = Slic3r::Point->new(104577600, 327748400);
|
||||
|
||||
local $Slic3r::Geometry::epsilon = 1E-5;
|
||||
is_deeply Slic3r::Geometry::polygon_segment_having_point($polygon, $point)->pp,
|
||||
[ [107014700, 340000000], [104577600, 327748400] ],
|
||||
'polygon_segment_having_point';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $point = Slic3r::Point->new(736310778.185108, 5017423926.8924);
|
||||
my $line = Slic3r::Line->new([627484000, 3695776000], [750000000, 3720147000]);
|
||||
is Slic3r::Geometry::point_in_segment($point, $line), 0, 'point_in_segment';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $point = Slic3r::Point->new(736310778.185108, 5017423926.8924);
|
||||
my $line = Slic3r::Line->new([627484000, 3695776000], [750000000, 3720147000]);
|
||||
is Slic3r::Geometry::point_in_segment($point, $line), 0, 'point_in_segment';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
my $polygons = [
|
||||
Slic3r::Polygon->new( # contour, ccw
|
||||
[45919000, 515273900], [14726100, 461246400], [14726100, 348753500], [33988700, 315389800],
|
||||
[43749700, 343843000], [45422300, 352251500], [52362100, 362637800], [62748400, 369577600],
|
||||
[75000000, 372014700], [87251500, 369577600], [97637800, 362637800], [104577600, 352251500],
|
||||
[107014700, 340000000], [104577600, 327748400], [97637800, 317362100], [87251500, 310422300],
|
||||
[82789200, 309534700], [69846100, 294726100], [254081000, 294726100], [285273900, 348753500],
|
||||
[285273900, 461246400], [254081000, 515273900],
|
||||
|
||||
),
|
||||
Slic3r::Polygon->new( # hole, cw
|
||||
[75000000, 502014700], [87251500, 499577600], [97637800, 492637800], [104577600, 482251500],
|
||||
[107014700, 470000000], [104577600, 457748400], [97637800, 447362100], [87251500, 440422300],
|
||||
[75000000, 437985300], [62748400, 440422300], [52362100, 447362100], [45422300, 457748400],
|
||||
[42985300, 470000000], [45422300, 482251500], [52362100, 492637800], [62748400, 499577600],
|
||||
),
|
||||
];
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $p1 = [10, 10];
|
||||
my $p2 = [10, 20];
|
||||
my $p3 = [10, 30];
|
||||
my $p4 = [20, 20];
|
||||
my $p5 = [0, 20];
|
||||
|
||||
is Slic3r::Geometry::angle3points($p2, $p3, $p1), PI(), 'angle3points';
|
||||
is Slic3r::Geometry::angle3points($p2, $p1, $p3), PI(), 'angle3points';
|
||||
is Slic3r::Geometry::angle3points($p2, $p3, $p4), PI()/2*3, 'angle3points';
|
||||
is Slic3r::Geometry::angle3points($p2, $p4, $p3), PI()/2, 'angle3points';
|
||||
is Slic3r::Geometry::angle3points($p2, $p1, $p4), PI()/2, 'angle3points';
|
||||
is Slic3r::Geometry::angle3points($p2, $p1, $p5), PI()/2*3, 'angle3points';
|
||||
}
|
||||
|
||||
{
|
||||
my $p1 = [30, 30];
|
||||
my $p2 = [20, 20];
|
||||
my $p3 = [10, 10];
|
||||
my $p4 = [30, 10];
|
||||
|
||||
is Slic3r::Geometry::angle3points($p2, $p1, $p3), PI(), 'angle3points';
|
||||
is Slic3r::Geometry::angle3points($p2, $p1, $p4), PI()/2*3, 'angle3points';
|
||||
is Slic3r::Geometry::angle3points($p2, $p1, $p1), 2*PI(), 'angle3points';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $cw_square = [ [0,0], [0,10], [10,10], [10,0] ];
|
||||
is polygon_is_convex($cw_square), 0, 'cw square is not convex';
|
||||
is polygon_is_convex([ reverse @$cw_square ]), 1, 'ccw square is convex';
|
||||
|
||||
my $convex1 = [ [0,0], [10,0], [10,10], [0,10], [0,6], [4,6], [4,4], [0,4] ];
|
||||
is polygon_is_convex($convex1), 0, 'concave polygon';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $polyline = Slic3r::Polyline->new([0, 0], [10, 0], [20, 0]);
|
||||
is_deeply [ map $_->pp, @{$polyline->lines} ], [
|
||||
[ [0, 0], [10, 0] ],
|
||||
[ [10, 0], [20, 0] ],
|
||||
], 'polyline_lines';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $polygon = Slic3r::Polygon->new([0, 0], [10, 0], [5, 5]);
|
||||
my $result = $polygon->split_at_index(1);
|
||||
is ref($result), 'Slic3r::Polyline', 'split_at_index returns polyline';
|
||||
is_deeply $result->pp, [ [10, 0], [5, 5], [0, 0], [10, 0] ], 'split_at_index';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $bb = Slic3r::Geometry::BoundingBox->new_from_points([ map Slic3r::Point->new(@$_), [0, 1], [10, 2], [20, 2] ]);
|
||||
$bb->scale(2);
|
||||
is_deeply [ $bb->min_point->pp, $bb->max_point->pp ], [ [0,2], [40,4] ], 'bounding box is scaled correctly';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $line = Slic3r::Line->new([10,10], [20,10]);
|
||||
is $line->grow(5)->[0]->area, Slic3r::Polygon->new([10,5], [20,5], [20,15], [10,15])->area, 'grow line';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
# if chained_path() works correctly, these points should be joined with no diagonal paths
|
||||
# (thus 26 units long)
|
||||
my @points = map Slic3r::Point->new_scale(@$_), [26,26],[52,26],[0,26],[26,52],[26,0],[0,52],[52,52],[52,0];
|
||||
my @ordered = @points[@{chained_path_from(\@points, $points[0])}];
|
||||
ok !(grep { abs($ordered[$_]->distance_to($ordered[$_+1]) - scale 26) > epsilon } 0..$#ordered-1), 'chained_path';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $line = Slic3r::Line->new([0, 0], [20, 0]);
|
||||
is +Slic3r::Point->new(10, 10)->distance_to_line($line), 10, 'distance_to';
|
||||
is +Slic3r::Point->new(50, 0)->distance_to_line($line), 30, 'distance_to';
|
||||
is +Slic3r::Point->new(0, 0)->distance_to_line($line), 0, 'distance_to';
|
||||
is +Slic3r::Point->new(20, 0)->distance_to_line($line), 0, 'distance_to';
|
||||
is +Slic3r::Point->new(10, 0)->distance_to_line($line), 0, 'distance_to';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $square = Slic3r::Polygon->new_scale(
|
||||
[100,100],
|
||||
[200,100],
|
||||
[200,200],
|
||||
[100,200],
|
||||
);
|
||||
is scalar(@{$square->concave_points(PI*4/3)}), 0, 'no concave vertices detected in ccw square';
|
||||
is scalar(@{$square->convex_points(PI*2/3)}), 4, 'four convex vertices detected in ccw square';
|
||||
|
||||
$square->make_clockwise;
|
||||
is scalar(@{$square->concave_points(PI*4/3)}), 4, 'fuor concave vertices detected in cw square';
|
||||
is scalar(@{$square->convex_points(PI*2/3)}), 0, 'no convex vertices detected in cw square';
|
||||
}
|
||||
|
||||
{
|
||||
my $square = Slic3r::Polygon->new_scale(
|
||||
[150,100],
|
||||
[200,100],
|
||||
[200,200],
|
||||
[100,200],
|
||||
[100,100],
|
||||
);
|
||||
is scalar(@{$square->concave_points(PI*4/3)}), 0, 'no concave vertices detected in convex polygon';
|
||||
is scalar(@{$square->convex_points(PI*2/3)}), 4, 'four convex vertices detected in square';
|
||||
}
|
||||
|
||||
{
|
||||
my $square = Slic3r::Polygon->new_scale(
|
||||
[200,200],
|
||||
[100,200],
|
||||
[100,100],
|
||||
[150,100],
|
||||
[200,100],
|
||||
);
|
||||
is scalar(@{$square->concave_points(PI*4/3)}), 0, 'no concave vertices detected in convex polygon';
|
||||
is scalar(@{$square->convex_points(PI*2/3)}), 4, 'four convex vertices detected in square';
|
||||
}
|
||||
|
||||
{
|
||||
my $triangle = Slic3r::Polygon->new(
|
||||
[16000170,26257364], [714223,461012], [31286371,461008],
|
||||
);
|
||||
is scalar(@{$triangle->concave_points(PI*4/3)}), 0, 'no concave vertices detected in triangle';
|
||||
is scalar(@{$triangle->convex_points(PI*2/3)}), 3, 'three convex vertices detected in triangle';
|
||||
}
|
||||
|
||||
{
|
||||
my $triangle = Slic3r::Polygon->new(
|
||||
[16000170,26257364], [714223,461012], [20000000,461012], [31286371,461012],
|
||||
);
|
||||
is scalar(@{$triangle->concave_points(PI*4/3)}), 0, 'no concave vertices detected in triangle having collinear point';
|
||||
is scalar(@{$triangle->convex_points(PI*2/3)}), 3, 'three convex vertices detected in triangle having collinear point';
|
||||
}
|
||||
|
||||
{
|
||||
my $triangle = Slic3r::Polygon->new(
|
||||
[16000170,26257364], [714223,461012], [31286371,461008],
|
||||
);
|
||||
my $simplified = $triangle->simplify(250000)->[0];
|
||||
is scalar(@$simplified), 3, 'triangle is never simplified to less than 3 points';
|
||||
}
|
||||
|
||||
__END__
|
||||
78
t/layers.t
Normal file
78
t/layers.t
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
use Test::More tests => 5;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Test qw(_eq);
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
|
||||
my $test = sub {
|
||||
my ($conf) = @_;
|
||||
$conf ||= $config;
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
|
||||
|
||||
my @z = ();
|
||||
my @increments = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{dist_Z}) {
|
||||
push @z, 1*$args->{Z};
|
||||
push @increments, $info->{dist_Z};
|
||||
}
|
||||
});
|
||||
|
||||
fail 'wrong first layer height'
|
||||
if $z[0] ne $config->get_value('first_layer_height') + $config->z_offset;
|
||||
|
||||
fail 'wrong second layer height'
|
||||
if $z[1] ne $config->get_value('first_layer_height') + $config->get_value('layer_height') + $config->z_offset;
|
||||
|
||||
fail 'wrong layer height'
|
||||
if first { !_eq($_, $config->layer_height) } @increments[1..$#increments];
|
||||
|
||||
1;
|
||||
};
|
||||
|
||||
$config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
|
||||
$config->set('layer_height', 0.3);
|
||||
$config->set('first_layer_height', 0.2);
|
||||
ok $test->(), "absolute first layer height";
|
||||
|
||||
$config->set('first_layer_height', 0.6 * $config->layer_height);
|
||||
ok $test->(), "relative first layer height";
|
||||
|
||||
$config->set('z_offset', 0.9);
|
||||
ok $test->(), "positive Z offset";
|
||||
|
||||
$config->set('z_offset', -0.8);
|
||||
ok $test->(), "negative Z offset";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('fill_density', 0); # just for making the test faster
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale => 2);
|
||||
|
||||
my @z = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{dist_Z}) {
|
||||
push @z, 1*$args->{Z};
|
||||
}
|
||||
});
|
||||
ok $z[-1] > 20*1.8 && $z[-1] < 20*2.2, 'resulting G-code has reasonable height';
|
||||
}
|
||||
|
||||
__END__
|
||||
57
t/loops.t
Normal file
57
t/loops.t
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan skip_all => 'temporarily disabled';
|
||||
plan tests => 4;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
# We only need to slice at one height, so we'll build a non-manifold mesh
|
||||
# that still produces complete loops at that height. Triangular walls are
|
||||
# enough for this purpose.
|
||||
# Basically we want to check what happens when three concentric loops happen
|
||||
# to be at the same height, the two external ones being ccw and the other being
|
||||
# a hole, thus cw.
|
||||
my (@vertices, @facets) = ();
|
||||
Slic3r::Test::add_facet($_, \@vertices, \@facets) for
|
||||
# external surface below the slicing Z
|
||||
[ [0,0,0], [20,0,10], [0,0,10] ],
|
||||
[ [20,0,0], [20,20,10], [20,0,10] ],
|
||||
[ [20,20,0], [0,20,10], [20,20,10] ],
|
||||
[ [0,20,0], [0,0,10], [0,20,10] ],
|
||||
|
||||
# external insetted surface above the slicing Z
|
||||
[ [2,2,10], [18,2,10], [2,2,20] ],
|
||||
[ [18,2,10], [18,18,10], [18,2,20] ],
|
||||
[ [18,18,10], [2,18,10], [18,18,20] ],
|
||||
[ [2,18,10], [2,2,10], [2,18,20] ],
|
||||
|
||||
# insetted hole below the slicing Z
|
||||
[ [15,5,0], [5,5,10], [15,5,10] ],
|
||||
[ [15,15,0], [15,5,10], [15,15,10] ],
|
||||
[ [5,15,0], [15,15,10], [5,15,10] ],
|
||||
[ [5,5,0], [5,15,10], [5,5,10] ];
|
||||
|
||||
my $mesh = Slic3r::TriangleMesh->new;
|
||||
$mesh->ReadFromPerl(\@vertices, \@facets);
|
||||
$mesh->analyze;
|
||||
my @lines = map $mesh->intersect_facet($_, 10), 0..$#facets;
|
||||
my $loops = Slic3r::TriangleMesh::make_loops(\@lines);
|
||||
is scalar(@$loops), 3, 'correct number of loops detected';
|
||||
is scalar(grep $_->is_counter_clockwise, @$loops), 2, 'correct number of ccw loops detected';
|
||||
|
||||
my @surfaces = Slic3r::Layer::Region::_merge_loops($loops, 0);
|
||||
is scalar(@surfaces), 1, 'one surface detected';
|
||||
is scalar(@{$surfaces[0]->expolygon})-1, 1, 'surface has one hole';
|
||||
}
|
||||
|
||||
__END__
|
||||
221
t/multi.t
Normal file
221
t/multi.t
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
use Test::More tests => 13;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(scale convex_hull);
|
||||
use Slic3r::Geometry::Clipper qw(offset);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('raft_layers', 2);
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('solid_infill_extruder', 3);
|
||||
$config->set('support_material_extruder', 4);
|
||||
$config->set('ooze_prevention', 1);
|
||||
$config->set('extruder_offset', [ [0,0], [20,0], [0,20], [20,20] ]);
|
||||
$config->set('temperature', [200, 180, 170, 160]);
|
||||
$config->set('first_layer_temperature', [206, 186, 166, 156]);
|
||||
$config->set('toolchange_gcode', 'T[next_extruder] ;toolchange'); # test that it doesn't crash when this is supplied
|
||||
# Since July 2019, PrusaSlicer only emits automatic Tn command in case that the toolchange_gcode is empty
|
||||
# The "T[next_extruder]" is therefore needed in this test.
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
|
||||
my $tool = undef;
|
||||
my @tool_temp = (0,0,0,0);
|
||||
my @toolchange_points = ();
|
||||
my @extrusion_points = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd =~ /^T(\d+)/) {
|
||||
# ignore initial toolchange
|
||||
if (defined $tool) {
|
||||
my $expected_temp = $self->Z == ($config->get_value('first_layer_height') + $config->z_offset)
|
||||
? $config->first_layer_temperature->[$tool]
|
||||
: $config->temperature->[$tool];
|
||||
die 'standby temperature was not set before toolchange'
|
||||
if $tool_temp[$tool] != $expected_temp + $config->standby_temperature_delta;
|
||||
|
||||
push @toolchange_points, my $point = Slic3r::Point->new_scale($self->X, $self->Y);
|
||||
}
|
||||
$tool = $1;
|
||||
} elsif ($cmd eq 'M104' || $cmd eq 'M109') {
|
||||
my $t = $args->{T} // $tool;
|
||||
if ($tool_temp[$t] == 0) {
|
||||
fail 'initial temperature is not equal to first layer temperature + standby delta'
|
||||
unless $args->{S} == $config->first_layer_temperature->[$t] + $config->standby_temperature_delta;
|
||||
}
|
||||
$tool_temp[$t] = $args->{S};
|
||||
} elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
|
||||
push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
|
||||
$point->translate(map +scale($_), @{ $config->extruder_offset->[$tool] });
|
||||
}
|
||||
});
|
||||
my $convex_hull = convex_hull(\@extrusion_points);
|
||||
|
||||
my @t = ();
|
||||
foreach my $point (@toolchange_points) {
|
||||
foreach my $offset (@{$config->extruder_offset}) {
|
||||
push @t, my $p = $point->clone;
|
||||
$p->translate(map +scale($_), @$offset);
|
||||
}
|
||||
}
|
||||
ok !(defined first { $convex_hull->contains_point($_) } @t), 'all nozzles are outside skirt at toolchange';
|
||||
|
||||
if (0) {
|
||||
require "Slic3r/SVG.pm";
|
||||
Slic3r::SVG::output(
|
||||
"ooze_prevention_test.svg",
|
||||
no_arrows => 1,
|
||||
polygons => [$convex_hull],
|
||||
red_points => \@t,
|
||||
points => \@toolchange_points,
|
||||
);
|
||||
}
|
||||
|
||||
# offset the skirt by the maximum displacement between extruders plus a safety extra margin
|
||||
my $delta = scale(20 * sqrt(2) + 1);
|
||||
my $outer_convex_hull = offset([$convex_hull], +$delta)->[0];
|
||||
ok !(defined first { !$outer_convex_hull->contains_point($_) } @toolchange_points), 'all toolchanges happen within expected area';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('support_material_extruder', 3);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'no errors when using non-consecutive extruders';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('extruder', 2);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
like Slic3r::Test::gcode($print), qr/ T1/, 'extruder shortcut';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('perimeter_extruder', 2);
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('support_material_extruder', 2);
|
||||
$config->set('support_material_interface_extruder', 2);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'no errors when using multiple skirts with a single, non-zero, extruder';
|
||||
}
|
||||
|
||||
{
|
||||
my $model = stacked_cubes();
|
||||
my $lower_config = $model->get_material('lower')->config;
|
||||
my $upper_config = $model->get_material('upper')->config;
|
||||
|
||||
$lower_config->set('extruder', 1);
|
||||
$lower_config->set('bottom_solid_layers', 0);
|
||||
$lower_config->set('top_solid_layers', 1);
|
||||
$upper_config->set('extruder', 2);
|
||||
$upper_config->set('bottom_solid_layers', 1);
|
||||
$upper_config->set('top_solid_layers', 0);
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('fill_density', 0);
|
||||
$config->set('solid_infill_speed', 99);
|
||||
$config->set('top_solid_infill_speed', 99);
|
||||
$config->set('cooling', [ 0 ]); # for preventing speeds from being altered
|
||||
$config->set('first_layer_speed', '100%'); # for preventing speeds from being altered
|
||||
|
||||
my $test = sub {
|
||||
my $print = Slic3r::Test::init_print($model, config => $config);
|
||||
my $tool = undef;
|
||||
my %T0_shells = my %T1_shells = (); # Z => 1
|
||||
Slic3r::GCode::Reader->new->parse(my $gcode = 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 (($args->{F} // $self->F) == $config->solid_infill_speed*60) {
|
||||
if ($tool == 0) {
|
||||
$T0_shells{$self->Z} = 1;
|
||||
} elsif ($tool == 1) {
|
||||
$T1_shells{$self->Z} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return [ sort keys %T0_shells ], [ sort keys %T1_shells ];
|
||||
};
|
||||
|
||||
{
|
||||
my ($t0, $t1) = $test->();
|
||||
is scalar(@$t0), 0, 'no interface shells';
|
||||
is scalar(@$t1), 0, 'no interface shells';
|
||||
}
|
||||
{
|
||||
$config->set('interface_shells', 1);
|
||||
my ($t0, $t1) = $test->();
|
||||
is scalar(@$t0), $lower_config->top_solid_layers, 'top interface shells';
|
||||
is scalar(@$t1), $upper_config->bottom_solid_layers, 'bottom interface shells';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $model = stacked_cubes();
|
||||
my $object = $model->objects->[0];
|
||||
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('skirts', 0);
|
||||
my $print = Slic3r::Test::init_print($model, config => $config);
|
||||
|
||||
is $object->volumes->[0]->config->extruder, 1, 'auto_assign_extruders() assigned correct extruder to first volume';
|
||||
is $object->volumes->[1]->config->extruder, 2, 'auto_assign_extruders() assigned correct extruder to second volume';
|
||||
|
||||
my $tool = undef;
|
||||
my %T0 = my %T1 = (); # Z => 1
|
||||
Slic3r::GCode::Reader->new->parse(my $gcode = 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 == 0) {
|
||||
$T0{$self->Z} = 1;
|
||||
} elsif ($tool == 1) {
|
||||
$T1{$self->Z} = 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ok !(defined first { $_ > 20 } keys %T0), 'T0 is never used for upper object';
|
||||
ok !(defined first { $_ < 20 } keys %T1), 'T1 is never used for lower object';
|
||||
}
|
||||
|
||||
sub stacked_cubes {
|
||||
my $model = Slic3r::Model->new;
|
||||
my $object = $model->add_object;
|
||||
$object->add_volume(mesh => Slic3r::Test::mesh('20mm_cube'), material_id => 'lower');
|
||||
$object->add_volume(mesh => Slic3r::Test::mesh('20mm_cube', translate => [0,0,20]), material_id => 'upper');
|
||||
$object->add_instance(offset => Slic3r::Pointf->new(0,0));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
__END__
|
||||
444
t/perimeters.t
Normal file
444
t/perimeters.t
Normal file
File diff suppressed because one or more lines are too long
121
t/polyclip.t
Normal file
121
t/polyclip.t
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 18;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry::Clipper qw(intersection_pl);
|
||||
|
||||
#==========================================================
|
||||
|
||||
is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(10, 10), Slic3r::Line->new([5, 10], [20, 10])), 1, 'point in horizontal segment';
|
||||
is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(30, 10), Slic3r::Line->new([5, 10], [20, 10])), 0, 'point not in horizontal segment';
|
||||
is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(10, 10), Slic3r::Line->new([10, 5], [10, 20])), 1, 'point in vertical segment';
|
||||
is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(10, 30), Slic3r::Line->new([10, 5], [10, 20])), 0, 'point not in vertical segment';
|
||||
is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(15, 15), Slic3r::Line->new([10, 10], [20, 20])), 1, 'point in diagonal segment';
|
||||
is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(20, 15), Slic3r::Line->new([10, 10], [20, 20])), 0, 'point not in diagonal segment';
|
||||
|
||||
#==========================================================
|
||||
|
||||
my $square = Slic3r::Polygon->new( # ccw
|
||||
[100, 100],
|
||||
[200, 100],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
);
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $hole_in_square = [ # cw
|
||||
[140, 140],
|
||||
[140, 160],
|
||||
[160, 160],
|
||||
[160, 140],
|
||||
];
|
||||
my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
|
||||
#is $expolygon->contains_point(Slic3r::Point->new(100, 100)), 1, 'corner point is recognized';
|
||||
#is $expolygon->contains_point(Slic3r::Point->new(100, 180)), 1, 'point on contour is recognized';
|
||||
#is $expolygon->contains_point(Slic3r::Point->new(140, 150)), 1, 'point on hole contour is recognized';
|
||||
#is $expolygon->contains_point(Slic3r::Point->new(140, 140)), 1, 'point on hole corner is recognized';
|
||||
{
|
||||
my $intersection = intersection_pl([Slic3r::Polyline->new([150,180], [150,150])], \@$expolygon);
|
||||
is $intersection->[0]->length, Slic3r::Line->new([150, 180], [150, 160])->length,
|
||||
'line is clipped to square with hole';
|
||||
}
|
||||
{
|
||||
my $intersection = intersection_pl([Slic3r::Polyline->new([150,150], [150,120])], \@$expolygon);
|
||||
is $intersection->[0]->length, Slic3r::Line->new([150, 140], [150, 120])->length,
|
||||
'line is clipped to square with hole';
|
||||
}
|
||||
{
|
||||
my $intersection = intersection_pl([Slic3r::Polyline->new([120,180], [180,180])], \@$expolygon);
|
||||
is $intersection->[0]->length, Slic3r::Line->new([120,180], [180,180])->length,
|
||||
'line is clipped to square with hole';
|
||||
}
|
||||
{
|
||||
my $intersection = intersection_pl([Slic3r::Polyline->new([50, 150], [300, 150])], \@$expolygon);
|
||||
is $intersection->[0]->length, Slic3r::Line->new([100, 150], [140, 150])->length,
|
||||
'line is clipped to square with hole';
|
||||
is $intersection->[1]->length, Slic3r::Line->new([160, 150], [200, 150])->length,
|
||||
'line is clipped to square with hole';
|
||||
}
|
||||
{
|
||||
my $intersection = intersection_pl([Slic3r::Polyline->new([300, 150], [50, 150])], \@$expolygon);
|
||||
is $intersection->[0]->length, Slic3r::Line->new([200, 150], [160, 150])->length,
|
||||
'reverse line is clipped to square with hole';
|
||||
is $intersection->[1]->length, Slic3r::Line->new([140, 150], [100, 150])->length,
|
||||
'reverse line is clipped to square with hole';
|
||||
}
|
||||
{
|
||||
my $intersection = intersection_pl([Slic3r::Polyline->new([100,180], [200,180])], \@$expolygon);
|
||||
is $intersection->[0]->length, Slic3r::Line->new([100,180], [200,180])->length,
|
||||
'tangent line is clipped to square with hole';
|
||||
}
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $large_circle = Slic3r::Polygon->new_scale( # ccw
|
||||
[151.8639,288.1192], [133.2778,284.6011], [115.0091,279.6997], [98.2859,270.8606], [82.2734,260.7933],
|
||||
[68.8974,247.4181], [56.5622,233.0777], [47.7228,216.3558], [40.1617,199.0172], [36.6431,180.4328],
|
||||
[34.932,165.2312], [37.5567,165.1101], [41.0547,142.9903], [36.9056,141.4295], [40.199,124.1277],
|
||||
[47.7776,106.7972], [56.6335,90.084], [68.9831,75.7557], [82.3712,62.3948], [98.395,52.3429],
|
||||
[115.1281,43.5199], [133.4004,38.6374], [151.9884,35.1378], [170.8905,35.8571], [189.6847,37.991],
|
||||
[207.5349,44.2488], [224.8662,51.8273], [240.0786,63.067], [254.407,75.4169], [265.6311,90.6406],
|
||||
[275.6832,106.6636], [281.9225,124.52], [286.8064,142.795], [287.5061,161.696], [286.7874,180.5972],
|
||||
[281.8856,198.8664], [275.6283,216.7169], [265.5604,232.7294], [254.3211,247.942], [239.9802,260.2776],
|
||||
[224.757,271.5022], [207.4179,279.0635], [189.5605,285.3035], [170.7649,287.4188],
|
||||
);
|
||||
ok $large_circle->is_counter_clockwise, "contour is counter-clockwise";
|
||||
|
||||
my $small_circle = Slic3r::Polygon->new_scale( # cw
|
||||
[158.227,215.9007], [164.5136,215.9007], [175.15,214.5007], [184.5576,210.6044], [190.2268,207.8743],
|
||||
[199.1462,201.0306], [209.0146,188.346], [213.5135,177.4829], [214.6979,168.4866], [216.1025,162.3325],
|
||||
[214.6463,151.2703], [213.2471,145.1399], [209.0146,134.9203], [199.1462,122.2357], [189.8944,115.1366],
|
||||
[181.2504,111.5567], [175.5684,108.8205], [164.5136,107.3655], [158.2269,107.3655], [147.5907,108.7656],
|
||||
[138.183,112.6616], [132.5135,115.3919], [123.5943,122.2357], [113.7259,134.92], [109.2269,145.7834],
|
||||
[108.0426,154.7799], [106.638,160.9339], [108.0941,171.9957], [109.4933,178.1264], [113.7259,188.3463],
|
||||
[123.5943,201.0306], [132.8461,208.1296], [141.4901,211.7094], [147.172,214.4458],
|
||||
);
|
||||
ok $small_circle->is_clockwise, "hole is clockwise";
|
||||
|
||||
my $expolygon = Slic3r::ExPolygon->new($large_circle, $small_circle);
|
||||
my $line = Slic3r::Polyline->new_scale([152.742,288.086671142818], [152.742,34.166466971035]);
|
||||
|
||||
my $intersection = intersection_pl([$line], \@$expolygon);
|
||||
is $intersection->[0]->length, Slic3r::Line->new([152742000, 288086661], [152742000, 215178843])->length,
|
||||
'line is clipped to square with hole';
|
||||
is $intersection->[1]->length, Slic3r::Line->new([152742000, 108087507], [152742000, 35166477])->length,
|
||||
'line is clipped to square with hole';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
65
t/print.t
Normal file
65
t/print.t
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
use Test::More tests => 6;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(unscale X Y);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
my $print_center = [100,100];
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, print_center => $print_center);
|
||||
my @extrusion_points = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
|
||||
push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
|
||||
}
|
||||
});
|
||||
my $bb = Slic3r::Geometry::BoundingBox->new_from_points(\@extrusion_points);
|
||||
my $center = $bb->center;
|
||||
ok abs(unscale($center->[X]) - $print_center->[X]) < 0.005, 'print is centered around print_center (X)';
|
||||
ok abs(unscale($center->[Y]) - $print_center->[Y]) < 0.005, 'print is centered around print_center (Y)';
|
||||
}
|
||||
|
||||
{
|
||||
# this represents the aggregate config from presets
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
# Define 4 extruders.
|
||||
$config->set('nozzle_diameter', [0.4, 0.4, 0.4, 0.4]);
|
||||
|
||||
# user adds one object to the plater
|
||||
my $print = Slic3r::Test::init_print(my $model = Slic3r::Test::model('20mm_cube'), config => $config);
|
||||
|
||||
# user sets a per-region option
|
||||
my $model2 = $model->clone;
|
||||
$model2->get_object(0)->config->set('fill_density', 100);
|
||||
$print->apply($model2, $config);
|
||||
|
||||
is $print->print->regions->[0]->config->fill_density, 100, 'region config inherits model object config';
|
||||
|
||||
# user exports G-code, thus the default config is reapplied
|
||||
$model2->get_object(0)->config->erase('fill_density');
|
||||
$print->apply($model2, $config);
|
||||
|
||||
is $print->print->regions->[0]->config->fill_density, 20, 'region config is resetted';
|
||||
|
||||
# user assigns object extruders
|
||||
$model2->get_object(0)->config->set('extruder', 3);
|
||||
$model2->get_object(0)->config->set('perimeter_extruder', 2);
|
||||
$print->apply($model2, $config);
|
||||
|
||||
is $print->print->regions->[0]->config->infill_extruder, 3, 'extruder setting is correctly expanded';
|
||||
is $print->print->regions->[0]->config->perimeter_extruder, 2, 'extruder setting does not override explicitely specified extruders';
|
||||
}
|
||||
|
||||
__END__
|
||||
260
t/retraction.t
Normal file
260
t/retraction.t
Normal file
|
|
@ -0,0 +1,260 @@
|
|||
use Test::More tests => 26;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(any);
|
||||
use Slic3r;
|
||||
use Slic3r::Test qw(_eq);
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
my $duplicate = 1;
|
||||
|
||||
my $test = sub {
|
||||
my ($conf) = @_;
|
||||
$conf ||= $config;
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf, duplicate => $duplicate);
|
||||
|
||||
my $tool = 0;
|
||||
my @toolchange_count = (); # track first usages so that we don't expect retract_length_toolchange when extruders are used for the first time
|
||||
my @retracted = (1); # ignore the first travel move from home to first point
|
||||
my @retracted_length = (0);
|
||||
my $lifted = 0;
|
||||
my $lift_dist = 0; # track lifted distance for toolchanges and extruders with different retract_lift values
|
||||
my $changed_tool = 0;
|
||||
my $wait_for_toolchange = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd =~ /^T(\d+)/) {
|
||||
$tool = $1;
|
||||
$changed_tool = 1;
|
||||
$wait_for_toolchange = 0;
|
||||
$toolchange_count[$tool] //= 0;
|
||||
$toolchange_count[$tool]++;
|
||||
} elsif ($cmd =~ /^G[01]$/ && !$args->{Z}) { # ignore lift taking place after retraction
|
||||
fail 'toolchange happens right after retraction' if $wait_for_toolchange;
|
||||
}
|
||||
|
||||
if ($info->{dist_Z}) {
|
||||
# lift move or lift + change layer
|
||||
if (_eq($info->{dist_Z}, $print->print->config->get_at('retract_lift', $tool))
|
||||
|| (_eq($info->{dist_Z}, $conf->layer_height + $print->print->config->get_at('retract_lift', $tool)) && $print->print->config->get_at('retract_lift', $tool) > 0)) {
|
||||
fail 'only lifting while retracted' if !$retracted[$tool];
|
||||
fail 'double lift' if $lifted;
|
||||
$lifted = 1;
|
||||
$lift_dist = $info->{dist_Z};
|
||||
}
|
||||
if ($info->{dist_Z} < 0) {
|
||||
fail 'going down only after lifting' if !$lifted;
|
||||
fail 'going down by the same amount of the lift or by the amount needed to get to next layer'
|
||||
if !_eq($info->{dist_Z}, -$lift_dist)
|
||||
&& !_eq($info->{dist_Z}, -lift_dist + $conf->layer_height);
|
||||
$lift_dist = 0;
|
||||
$lifted = 0;
|
||||
}
|
||||
fail 'move Z at travel speed' if ($args->{F} // $self->F) != $conf->travel_speed * 60;
|
||||
}
|
||||
if ($info->{retracting}) {
|
||||
$retracted[$tool] = 1;
|
||||
$retracted_length[$tool] += -$info->{dist_E};
|
||||
if (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length', $tool))) {
|
||||
# okay
|
||||
} elsif (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length_toolchange', $tool))) {
|
||||
$wait_for_toolchange = 1;
|
||||
} else {
|
||||
fail 'retracted by the correct amount';
|
||||
}
|
||||
}
|
||||
if ($info->{extruding}) {
|
||||
fail 'only extruding while not lifted' if $lifted;
|
||||
if ($retracted[$tool]) {
|
||||
my $expected_amount = $retracted_length[$tool] + $print->print->config->get_at('retract_restart_extra', $tool);
|
||||
if ($changed_tool && $toolchange_count[$tool] > 1) {
|
||||
$expected_amount = $print->print->config->get_at('retract_length_toolchange', $tool) + $print->print->config->get_at('retract_restart_extra_toolchange', $tool);
|
||||
$changed_tool = 0;
|
||||
}
|
||||
fail 'unretracted by the correct amount' && exit
|
||||
if !_eq($info->{dist_E}, $expected_amount);
|
||||
$retracted[$tool] = 0;
|
||||
$retracted_length[$tool] = 0;
|
||||
}
|
||||
}
|
||||
if ($info->{travel} && $info->{dist_XY} >= $print->print->config->get_at('retract_before_travel', $tool)) {
|
||||
fail 'retracted before long travel move' if !$retracted[$tool];
|
||||
}
|
||||
});
|
||||
|
||||
1;
|
||||
};
|
||||
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('first_layer_speed', '100%');
|
||||
$config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
|
||||
$config->set('retract_length', [1.5]);
|
||||
$config->set('retract_before_travel', [3]);
|
||||
$config->set('only_retract_when_crossing_perimeters', 0);
|
||||
|
||||
my $retract_tests = sub {
|
||||
my ($descr) = @_;
|
||||
|
||||
ok $test->(), "retraction$descr";
|
||||
|
||||
my $conf = $config->clone;
|
||||
$conf->set('retract_restart_extra', [1]);
|
||||
ok $test->($conf), "restart extra length$descr";
|
||||
|
||||
$conf->set('retract_restart_extra', [-1]);
|
||||
ok $test->($conf), "negative restart extra length$descr";
|
||||
|
||||
$conf->set('retract_lift', [1, 2]);
|
||||
ok $test->($conf), "lift$descr";
|
||||
};
|
||||
|
||||
$retract_tests->('');
|
||||
|
||||
$duplicate = 2;
|
||||
$retract_tests->(' (duplicate)');
|
||||
|
||||
$duplicate = 1;
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('skirts', 4);
|
||||
$config->set('skirt_height', 3);
|
||||
$retract_tests->(' (dual extruder with multiple skirt layers)');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('start_gcode', ''); # prevent any default priming Z move from affecting our lift detection
|
||||
$config->set('retract_length', [0]);
|
||||
$config->set('retract_layer_change', [0]);
|
||||
$config->set('retract_lift', [0.2]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $retracted = 0;
|
||||
my $layer_changes_with_retraction = 0;
|
||||
my $retractions = my $z_restores = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{retracting}) {
|
||||
$retracted = 1;
|
||||
$retractions++;
|
||||
} elsif ($info->{extruding} && $retracted) {
|
||||
$retracted = 0;
|
||||
}
|
||||
|
||||
if ($info->{dist_Z} && $retracted) {
|
||||
$layer_changes_with_retraction++;
|
||||
}
|
||||
if ($info->{dist_Z} && $args->{Z} < $self->Z) {
|
||||
$z_restores++;
|
||||
}
|
||||
});
|
||||
|
||||
is $layer_changes_with_retraction, 0, 'no retraction on layer change';
|
||||
is $retractions, 0, 'no retractions';
|
||||
is $z_restores, 0, 'no lift';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('use_firmware_retraction', 1);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $retracted = 0;
|
||||
my $double_retractions = my $double_unretractions = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G10') {
|
||||
$double_retractions++ if $retracted;
|
||||
$retracted = 1;
|
||||
} elsif ($cmd eq 'G11') {
|
||||
$double_unretractions++ if !$retracted;
|
||||
$retracted = 0;
|
||||
}
|
||||
});
|
||||
|
||||
is $double_retractions, 0, 'no double retractions';
|
||||
is $double_unretractions, 0, 'no double unretractions';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('use_firmware_retraction', 1);
|
||||
$config->set('retract_length', [0]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $retracted = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G10') {
|
||||
$retracted = 1;
|
||||
}
|
||||
});
|
||||
|
||||
ok $retracted, 'retracting also when --retract-length is 0 but --use-firmware-retraction is enabled';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('start_gcode', '');
|
||||
$config->set('retract_lift', [3, 4]);
|
||||
|
||||
my @lifted_at = ();
|
||||
my $test = sub {
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
||||
@lifted_at = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1' && $info->{dist_Z} < 0) {
|
||||
push @lifted_at, $info->{new_Z};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$config->set('retract_lift_above', [0, 0]);
|
||||
$config->set('retract_lift_below', [0, 0]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below == 0';
|
||||
|
||||
$config->set('retract_lift_above', [5, 6]);
|
||||
$config->set('retract_lift_below', [15, 13]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below != 0';
|
||||
ok !(any { $_ < $config->get_at('retract_lift_above', 0) } @lifted_at),
|
||||
'Z is not lifted below the configured value';
|
||||
ok !(any { $_ > $config->get_at('retract_lift_below', 0) } @lifted_at),
|
||||
'Z is not lifted above the configured value';
|
||||
|
||||
# check lifting with different values for 2. extruder
|
||||
$config->set('perimeter_extruder', 2);
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('retract_lift_above', [0, 0]);
|
||||
$config->set('retract_lift_below', [0, 0]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below == 0 for 2. extruder';
|
||||
|
||||
$config->set('retract_lift_above', [5, 6]);
|
||||
$config->set('retract_lift_below', [15, 13]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below != 0 for 2. extruder';
|
||||
ok !(any { $_ < $config->get_at('retract_lift_above', 1) } @lifted_at),
|
||||
'Z is not lifted below the configured value for 2. extruder';
|
||||
ok !(any { $_ > $config->get_at('retract_lift_below', 1) } @lifted_at),
|
||||
'Z is not lifted above the configured value for 2. extruder';
|
||||
}
|
||||
|
||||
__END__
|
||||
332
t/shells.t
Normal file
332
t/shells.t
Normal file
|
|
@ -0,0 +1,332 @@
|
|||
use Test::More tests => 20;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first sum);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(epsilon);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('perimeters', 0);
|
||||
$config->set('solid_infill_speed', 99);
|
||||
$config->set('top_solid_infill_speed', 99);
|
||||
$config->set('bridge_speed', 72);
|
||||
$config->set('first_layer_speed', '100%');
|
||||
$config->set('cooling', [ 0 ]);
|
||||
|
||||
my $test = sub {
|
||||
my ($conf) = @_;
|
||||
$conf ||= $config;
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
|
||||
my %z = (); # Z => 1
|
||||
my %layers_with_solid_infill = (); # Z => $count
|
||||
my %layers_with_bridge_infill = (); # Z => $count
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($self->Z > 0) {
|
||||
$z{ $self->Z } = 1;
|
||||
if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
my $F = $args->{F} // $self->F;
|
||||
$layers_with_solid_infill{$self->Z} = 1
|
||||
if $F == $config->solid_infill_speed*60;
|
||||
$layers_with_bridge_infill{$self->Z} = 1
|
||||
if $F == $config->bridge_speed*60;
|
||||
}
|
||||
}
|
||||
});
|
||||
my @z = sort { $a <=> $b } keys %z;
|
||||
my @shells = map $layers_with_solid_infill{$_} || $layers_with_bridge_infill{$_}, @z;
|
||||
fail "insufficient number of bottom solid layers"
|
||||
unless !defined(first { !$_ } @shells[0..$config->bottom_solid_layers-1]);
|
||||
fail "excessive number of bottom solid layers"
|
||||
unless scalar(grep $_, @shells[0 .. $#shells/2]) == $config->bottom_solid_layers;
|
||||
fail "insufficient number of top solid layers"
|
||||
unless !defined(first { !$_ } @shells[-$config->top_solid_layers..-1]);
|
||||
fail "excessive number of top solid layers"
|
||||
unless scalar(grep $_, @shells[($#shells/2)..$#shells]) == $config->top_solid_layers;
|
||||
if ($config->top_solid_layers > 0) {
|
||||
fail "unexpected solid infill speed in first solid layer over sparse infill"
|
||||
if $layers_with_solid_infill{ $z[-$config->top_solid_layers] };
|
||||
die "bridge speed not used in first solid layer over sparse infill"
|
||||
if !$layers_with_bridge_infill{ $z[-$config->top_solid_layers] };
|
||||
}
|
||||
1;
|
||||
};
|
||||
|
||||
$config->set('top_solid_layers', 3);
|
||||
$config->set('bottom_solid_layers', 3);
|
||||
ok $test->(), "proper number of shells is applied";
|
||||
|
||||
$config->set('top_solid_layers', 0);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
ok $test->(), "no shells are applied when both top and bottom are set to zero";
|
||||
|
||||
$config->set('perimeters', 1);
|
||||
$config->set('top_solid_layers', 3);
|
||||
$config->set('bottom_solid_layers', 3);
|
||||
$config->set('fill_density', 0);
|
||||
ok $test->(), "proper number of shells is applied even when fill density is none";
|
||||
}
|
||||
|
||||
# issue #1161
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('layer_height', 0.3);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
$config->set('top_solid_layers', 3);
|
||||
$config->set('cooling', [ 0 ]);
|
||||
$config->set('bridge_speed', 99);
|
||||
$config->set('solid_infill_speed', 99);
|
||||
$config->set('top_solid_infill_speed', 99);
|
||||
$config->set('first_layer_speed', '100%');
|
||||
|
||||
my $print = Slic3r::Test::init_print('V', config => $config);
|
||||
my %layers_with_solid_infill = (); # Z => 1
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
$layers_with_solid_infill{$self->Z} = 1
|
||||
if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
|
||||
});
|
||||
is scalar(map $layers_with_solid_infill{$_}, grep $_ <= 7.2, keys %layers_with_solid_infill), 3,
|
||||
"correct number of top solid shells is generated in V-shaped object";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
# we need to check against one perimeter because this test is calibrated
|
||||
# (shape, extrusion_width) so that perimeters cover the bottom surfaces of
|
||||
# their lower layer - the test checks that shells are not generated on the
|
||||
# above layers (thus 'across' the shadow perimeter)
|
||||
# the test is actually calibrated to leave a narrow bottom region for each
|
||||
# layer - we test that in case of fill_density = 0 such narrow shells are
|
||||
# discarded instead of grown
|
||||
$config->set('perimeters', 1);
|
||||
$config->set('fill_density', 0);
|
||||
$config->set('cooling', [ 0 ]); # prevent speed alteration
|
||||
$config->set('first_layer_speed', '100%'); # prevent speed alteration
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('extrusion_width', 0.55);
|
||||
$config->set('bottom_solid_layers', 3);
|
||||
$config->set('top_solid_layers', 0);
|
||||
$config->set('solid_infill_speed', 99);
|
||||
|
||||
my $print = Slic3r::Test::init_print('V', config => $config);
|
||||
my %layers = (); # Z => 1
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
$layers{$self->Z} = 1
|
||||
if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
|
||||
});
|
||||
is scalar(keys %layers), $config->bottom_solid_layers,
|
||||
"shells are not propagated across perimeters of the neighbor layer";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('perimeters', 3);
|
||||
$config->set('cooling', [ 0 ]); # prevent speed alteration
|
||||
$config->set('first_layer_speed', '100%'); # prevent speed alteration
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('bottom_solid_layers', 3);
|
||||
$config->set('top_solid_layers', 3);
|
||||
$config->set('solid_infill_speed', 99);
|
||||
$config->set('top_solid_infill_speed', 99);
|
||||
$config->set('bridge_speed', 99);
|
||||
$config->set('filament_diameter', [ 3.0 ]);
|
||||
$config->set('nozzle_diameter', [ 0.5 ]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('sloping_hole', config => $config);
|
||||
my %solid_layers = (); # Z => 1
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
$solid_layers{$self->Z} = 1
|
||||
if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
|
||||
});
|
||||
is scalar(keys %solid_layers), $config->bottom_solid_layers + $config->top_solid_layers,
|
||||
"no superfluous shells are generated";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('perimeters', 1);
|
||||
$config->set('fill_density', 0);
|
||||
$config->set('top_solid_layers', 0);
|
||||
$config->set('spiral_vase', 1);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
$config->set('skirts', 0);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('start_gcode', '');
|
||||
$config->set('temperature', [200]);
|
||||
$config->set('first_layer_temperature', [205]);
|
||||
|
||||
# TODO: this needs to be tested with a model with sloping edges, where starting
|
||||
# points of each layer are not aligned - in that case we would test that no
|
||||
# travel moves are left to move to the new starting point - in a cube, end
|
||||
# points coincide with next layer starting points (provided there's no clipping)
|
||||
my $test = sub {
|
||||
my ($model_name, $description) = @_;
|
||||
my $print = Slic3r::Test::init_print($model_name, config => $config);
|
||||
my $travel_moves_after_first_extrusion = 0;
|
||||
my $started_extruding = 0;
|
||||
my $first_layer_temperature_set = 0;
|
||||
my $temperature_set = 0;
|
||||
my @z_steps = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1') {
|
||||
$started_extruding = 1 if $info->{extruding};
|
||||
push @z_steps, $info->{dist_Z}
|
||||
if $started_extruding && $info->{dist_Z} > 0;
|
||||
$travel_moves_after_first_extrusion++
|
||||
if $info->{travel} && $info->{dist_XY} > 0 && $started_extruding && !exists $args->{Z};
|
||||
} elsif ($cmd eq 'M104') {
|
||||
$first_layer_temperature_set = 1 if $args->{S} == 205;
|
||||
$temperature_set = 1 if $args->{S} == 200;
|
||||
}
|
||||
});
|
||||
|
||||
ok $first_layer_temperature_set, 'first layer temperature is preserved';
|
||||
ok $temperature_set, 'temperature is preserved';
|
||||
|
||||
# we allow one travel move after first extrusion: i.e. when moving to the first
|
||||
# spiral point after moving to second layer (bottom layer had loop clipping, so
|
||||
# we're slightly distant from the starting point of the loop)
|
||||
ok $travel_moves_after_first_extrusion <= 1, "no gaps in spiral vase ($description)";
|
||||
ok !(grep { $_ > $config->layer_height + epsilon } @z_steps), "no gaps in Z ($description)";
|
||||
};
|
||||
|
||||
$test->('20mm_cube', 'solid model');
|
||||
|
||||
$config->set('z_offset', -10);
|
||||
$test->('20mm_cube', 'solid model with negative z-offset');
|
||||
|
||||
### Disabled because the current unreliable medial axis code doesn't
|
||||
### always produce valid loops.
|
||||
###$test->('40x10', 'hollow model with negative z-offset');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('spiral_vase', 1);
|
||||
$config->set('perimeters', 1);
|
||||
$config->set('fill_density', 0);
|
||||
$config->set('top_solid_layers', 0);
|
||||
$config->set('bottom_solid_layers', 0);
|
||||
$config->set('retract_layer_change', [0]);
|
||||
$config->set('skirts', 0);
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('start_gcode', '');
|
||||
# $config->set('use_relative_e_distances', 1);
|
||||
$config->validate;
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $z_moves = 0;
|
||||
my @this_layer = (); # [ dist_Z, dist_XY ], ...
|
||||
|
||||
my $bottom_layer_not_flat = 0;
|
||||
my $null_z_moves_not_layer_changes = 0;
|
||||
my $null_z_moves_not_multiples_of_layer_height = 0;
|
||||
my $sum_of_partial_z_equals_to_layer_height = 0;
|
||||
my $all_layer_segments_have_same_slope = 0;
|
||||
my $horizontal_extrusions = 0;
|
||||
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1') {
|
||||
if ($z_moves < 2) {
|
||||
# skip everything up to the second Z move
|
||||
# (i.e. start of second layer)
|
||||
if (exists $args->{Z}) {
|
||||
$z_moves++;
|
||||
$bottom_layer_not_flat = 1
|
||||
if $info->{dist_Z} > 0 && $info->{dist_Z} != $config->layer_height;
|
||||
}
|
||||
} elsif ($info->{dist_Z} == 0 && $args->{Z}) {
|
||||
$null_z_moves_not_layer_changes = 1
|
||||
if $info->{dist_XY} != 0;
|
||||
|
||||
# % doesn't work easily with floats
|
||||
$null_z_moves_not_multiples_of_layer_height = 1
|
||||
if abs(($args->{Z} / $config->layer_height) * $config->layer_height - $args->{Z}) > epsilon;
|
||||
|
||||
my $total_dist_XY = sum(map $_->[1], @this_layer);
|
||||
$sum_of_partial_z_equals_to_layer_height = 1
|
||||
if abs(sum(map $_->[0], @this_layer) - $config->layer_height) >
|
||||
# The first segment on the 2nd layer has extrusion interpolated from zero
|
||||
# and the 1st segment has such a low extrusion assigned, that it is effectively zero, thus the move
|
||||
# is considered non-extruding and a higher epsilon is required.
|
||||
($z_moves == 2 ? 0.0021 : epsilon);
|
||||
#printf ("Total height: %f, layer height: %f, good: %d\n", sum(map $_->[0], @this_layer), $config->layer_height, $sum_of_partial_z_equals_to_layer_height);
|
||||
|
||||
foreach my $segment (@this_layer) {
|
||||
# check that segment's dist_Z is proportioned to its dist_XY
|
||||
$all_layer_segments_have_same_slope = 1
|
||||
if abs($segment->[0]*$total_dist_XY/$config->layer_height - $segment->[1]) > 0.2;
|
||||
}
|
||||
|
||||
@this_layer = ();
|
||||
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
$horizontal_extrusions = 1
|
||||
if $info->{dist_Z} == 0;
|
||||
#printf("Pushing dist_z: %f, dist_xy: %f\n", $info->{dist_Z}, $info->{dist_XY});
|
||||
push @this_layer, [ $info->{dist_Z}, $info->{dist_XY} ];
|
||||
}
|
||||
}
|
||||
});
|
||||
ok !$bottom_layer_not_flat, 'bottom layer is flat when using spiral vase';
|
||||
ok !$null_z_moves_not_layer_changes, 'null Z moves are layer changes';
|
||||
ok !$null_z_moves_not_multiples_of_layer_height, 'null Z moves are multiples of layer height';
|
||||
ok !$sum_of_partial_z_equals_to_layer_height, 'sum of partial Z increments equals to a full layer height';
|
||||
ok !$all_layer_segments_have_same_slope, 'all layer segments have the same slope';
|
||||
ok !$horizontal_extrusions, 'no horizontal extrusions';
|
||||
}
|
||||
|
||||
# The current Spiral Vase slicing code removes the holes and all but the largest contours from each slice,
|
||||
# therefore the following test is no more valid.
|
||||
#{
|
||||
# my $config = Slic3r::Config::new_from_defaults;
|
||||
# $config->set('perimeters', 1);
|
||||
# $config->set('fill_density', 0);
|
||||
# $config->set('top_solid_layers', 0);
|
||||
# $config->set('spiral_vase', 1);
|
||||
# $config->set('bottom_solid_layers', 0);
|
||||
# $config->set('skirts', 0);
|
||||
# $config->set('first_layer_height', $config->layer_height);
|
||||
# $config->set('start_gcode', '');
|
||||
#
|
||||
# my $print = Slic3r::Test::init_print('two_hollow_squares', config => $config);
|
||||
# my $diagonal_moves = 0;
|
||||
# Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
# my ($self, $cmd, $args, $info) = @_;
|
||||
#
|
||||
# if ($cmd eq 'G1') {
|
||||
# if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
# if ($info->{dist_Z} > 0) {
|
||||
# $diagonal_moves++;
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# });
|
||||
# is $diagonal_moves, 0, 'no spiral moves on two-island object';
|
||||
#}
|
||||
|
||||
__END__
|
||||
146
t/skirt_brim.t
Normal file
146
t/skirt_brim.t
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
use Test::More tests => 6;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(unscale convex_hull);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 1);
|
||||
$config->set('skirt_height', 2);
|
||||
$config->set('perimeters', 0);
|
||||
$config->set('support_material_speed', 99);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds to be altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
|
||||
|
||||
my $test = sub {
|
||||
my ($conf) = @_;
|
||||
$conf ||= $config;
|
||||
|
||||
my $print = Slic3r::Test::init_print(['20mm_cube','20mm_cube'], config => $config);
|
||||
|
||||
my %layers_with_skirt = (); # Z => $count
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if (defined $self->Z) {
|
||||
$layers_with_skirt{$self->Z} //= 0;
|
||||
$layers_with_skirt{$self->Z} = 1
|
||||
if $info->{extruding} && ($args->{F} // $self->F) == $config->support_material_speed*60;
|
||||
}
|
||||
});
|
||||
fail "wrong number of layers with skirt"
|
||||
unless (grep $_, values %layers_with_skirt) == $config->skirt_height;
|
||||
};
|
||||
|
||||
ok $test->(), "skirt_height is honored when printing multiple objects too";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('perimeters', 0);
|
||||
$config->set('top_solid_layers', 0); # to prevent solid shells and their speeds
|
||||
$config->set('bottom_solid_layers', 0); # to prevent solid shells and their speeds
|
||||
$config->set('brim_width', 5);
|
||||
$config->set('support_material_speed', 99);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds to be altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
|
||||
my %layers_with_brim = (); # Z => $count
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if (defined $self->Z) {
|
||||
$layers_with_brim{$self->Z} //= 0;
|
||||
$layers_with_brim{$self->Z} = 1
|
||||
if $info->{extruding} && $info->{dist_XY} > 0 && ($args->{F} // $self->F) != $config->infill_speed*60;
|
||||
}
|
||||
});
|
||||
is scalar(grep $_, values %layers_with_brim), 1, "brim is generated";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 1);
|
||||
$config->set('brim_width', 10);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt is smaller than brim width';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 1);
|
||||
$config->set('skirt_height', 0);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt_height = 0 and skirts > 0';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
# Define 4 extruders.
|
||||
$config->set('nozzle_diameter', [0.4, 0.4, 0.4, 0.4]);
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', 0.4);
|
||||
$config->set('skirts', 1);
|
||||
$config->set('skirt_distance', 0);
|
||||
$config->set('support_material_speed', 99);
|
||||
$config->set('perimeter_extruder', 1);
|
||||
$config->set('support_material_extruder', 2);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds to be altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
|
||||
|
||||
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
||||
$print->process;
|
||||
|
||||
# we enable support material after skirt has been generated
|
||||
$config->set('support_material', 1);
|
||||
$print->apply($print->print->model->clone, $config);
|
||||
|
||||
my $skirt_length = 0;
|
||||
my @extrusion_points = ();
|
||||
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 (defined $self->Z && $self->Z == $config->first_layer_height) {
|
||||
# we're on first layer
|
||||
if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
my $speed = ($args->{F} // $self->F) / 60;
|
||||
if ($speed == $config->support_material_speed && $tool == $config->perimeter_extruder-1) {
|
||||
# skirt uses support material speed but first object's extruder
|
||||
$skirt_length += $info->{dist_XY};
|
||||
} else {
|
||||
push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
my $convex_hull = convex_hull(\@extrusion_points);
|
||||
my $hull_perimeter = unscale($convex_hull->split_at_first_point->length);
|
||||
ok $skirt_length > $hull_perimeter, 'skirt lenght is large enough to contain object with support';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('min_skirt_length', 20);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'no crash when using min_skirt_length';
|
||||
}
|
||||
|
||||
__END__
|
||||
152
t/slice.t
Normal file
152
t/slice.t
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan skip_all => 'temporarily disabled';
|
||||
plan tests => 16;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
# temporarily disable compilation errors due to constant not being exported anymore
|
||||
sub Slic3r::TriangleMesh::I_B {}
|
||||
sub Slic3r::TriangleMesh::I_FACET_EDGE {}
|
||||
sub Slic3r::TriangleMesh::FE_BOTTOM {
|
||||
sub Slic3r::TriangleMesh::FE_TOP {}}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(X Y Z);
|
||||
|
||||
my @lines;
|
||||
my $z = 20;
|
||||
my @points = ([3, 4], [8, 5], [1, 9]); # XY coordinates of the facet vertices
|
||||
|
||||
# NOTE:
|
||||
# the first point of the intersection lines is replaced by -1 because TriangleMesh.pm
|
||||
# is saving memory and doesn't store point A anymore since it's not actually needed.
|
||||
|
||||
# We disable this test because intersect_facet() now assumes we never feed a horizontal
|
||||
# facet to it.
|
||||
# is_deeply lines(20, 20, 20), [
|
||||
# [ -1, $points[1] ], # $points[0]
|
||||
# [ -1, $points[2] ], # $points[1]
|
||||
# [ -1, $points[0] ], # $points[2]
|
||||
# ], 'horizontal';
|
||||
|
||||
is_deeply lines(22, 20, 20), [ [ -1, $points[2] ] ], 'lower edge on layer'; # $points[1]
|
||||
is_deeply lines(20, 20, 22), [ [ -1, $points[1] ] ], 'lower edge on layer'; # $points[0]
|
||||
is_deeply lines(20, 22, 20), [ [ -1, $points[0] ] ], 'lower edge on layer'; # $points[2]
|
||||
|
||||
is_deeply lines(20, 20, 10), [ [ -1, $points[0] ] ], 'upper edge on layer'; # $points[1]
|
||||
is_deeply lines(10, 20, 20), [ [ -1, $points[1] ] ], 'upper edge on layer'; # $points[2]
|
||||
is_deeply lines(20, 10, 20), [ [ -1, $points[2] ] ], 'upper edge on layer'; # $points[0]
|
||||
|
||||
is_deeply lines(20, 15, 10), [ ], 'upper vertex on layer';
|
||||
is_deeply lines(28, 20, 30), [ ], 'lower vertex on layer';
|
||||
|
||||
{
|
||||
my @z = (24, 10, 16);
|
||||
is_deeply lines(@z), [
|
||||
[
|
||||
-1, # line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
|
||||
line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
|
||||
]
|
||||
], 'two edges intersect';
|
||||
}
|
||||
|
||||
{
|
||||
my @z = (16, 24, 10);
|
||||
is_deeply lines(@z), [
|
||||
[
|
||||
-1, # line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
|
||||
line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
|
||||
]
|
||||
], 'two edges intersect';
|
||||
}
|
||||
|
||||
{
|
||||
my @z = (10, 16, 24);
|
||||
is_deeply lines(@z), [
|
||||
[
|
||||
-1, # line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
|
||||
line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
|
||||
]
|
||||
], 'two edges intersect';
|
||||
}
|
||||
|
||||
{
|
||||
my @z = (24, 10, 20);
|
||||
is_deeply lines(@z), [
|
||||
[
|
||||
-1, # line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
|
||||
$points[2],
|
||||
]
|
||||
], 'one vertex on plane and one edge intersects';
|
||||
}
|
||||
|
||||
{
|
||||
my @z = (10, 20, 24);
|
||||
is_deeply lines(@z), [
|
||||
[
|
||||
-1, # line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
|
||||
$points[1],
|
||||
]
|
||||
], 'one vertex on plane and one edge intersects';
|
||||
}
|
||||
|
||||
{
|
||||
my @z = (20, 24, 10);
|
||||
is_deeply lines(@z), [
|
||||
[
|
||||
-1, # line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
|
||||
$points[0],
|
||||
]
|
||||
], 'one vertex on plane and one edge intersects';
|
||||
}
|
||||
|
||||
my @lower = intersect(22, 20, 20);
|
||||
my @upper = intersect(20, 20, 10);
|
||||
is $lower[0][Slic3r::TriangleMesh::I_FACET_EDGE], Slic3r::TriangleMesh::FE_BOTTOM, 'bottom edge on layer';
|
||||
is $upper[0][Slic3r::TriangleMesh::I_FACET_EDGE], Slic3r::TriangleMesh::FE_TOP, 'upper edge on layer';
|
||||
|
||||
my $mesh;
|
||||
|
||||
sub intersect {
|
||||
$mesh = Slic3r::TriangleMesh->new(
|
||||
facets => [],
|
||||
vertices => [],
|
||||
);
|
||||
push @{$mesh->facets}, [ [0,0,0], @{vertices(@_)} ];
|
||||
$mesh->analyze;
|
||||
return map Slic3r::TriangleMesh::unpack_line($_), $mesh->intersect_facet($#{$mesh->facets}, $z);
|
||||
}
|
||||
|
||||
sub vertices {
|
||||
push @{$mesh->vertices}, map [ @{$points[$_]}, $_[$_] ], 0..2;
|
||||
[ ($#{$mesh->vertices}-2) .. $#{$mesh->vertices} ]
|
||||
}
|
||||
|
||||
sub lines {
|
||||
my @lines = intersect(@_);
|
||||
#$_->a->[X] = sprintf('%.0f', $_->a->[X]) for @lines;
|
||||
#$_->a->[Y] = sprintf('%.0f', $_->a->[Y]) for @lines;
|
||||
$_->[Slic3r::TriangleMesh::I_B][X] = sprintf('%.0f', $_->[Slic3r::TriangleMesh::I_B][X]) for @lines;
|
||||
$_->[Slic3r::TriangleMesh::I_B][Y] = sprintf('%.0f', $_->[Slic3r::TriangleMesh::I_B][Y]) for @lines;
|
||||
return [ map [ -1, $_->[Slic3r::TriangleMesh::I_B] ], @lines ];
|
||||
}
|
||||
|
||||
sub line_plane_intersection {
|
||||
my ($line) = @_;
|
||||
@$line = map $mesh->vertices->[$_], @$line;
|
||||
|
||||
return [
|
||||
map sprintf('%.0f', $_),
|
||||
map +($line->[1][$_] + ($line->[0][$_] - $line->[1][$_]) * ($z - $line->[1][Z]) / ($line->[0][Z] - $line->[1][Z])),
|
||||
(X,Y)
|
||||
];
|
||||
}
|
||||
|
||||
__END__
|
||||
272
t/support.t
Normal file
272
t/support.t
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan skip_all => 'temporarily disabled';
|
||||
plan tests => 27;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r;
|
||||
use Slic3r::Flow ':roles';
|
||||
use Slic3r::Geometry qw(epsilon scale);
|
||||
use Slic3r::Geometry::Clipper qw(diff);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('support_material', 1);
|
||||
my @contact_z = my @top_z = ();
|
||||
|
||||
my $test = sub {
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $object_config = $print->print->objects->[0]->config;
|
||||
my $flow = Slic3r::Flow->new_from_width(
|
||||
width => $object_config->support_material_extrusion_width || $object_config->extrusion_width,
|
||||
role => FLOW_ROLE_SUPPORT_MATERIAL,
|
||||
nozzle_diameter => $print->config->nozzle_diameter->[$object_config->support_material_extruder-1] // $print->config->nozzle_diameter->[0],
|
||||
layer_height => $object_config->layer_height,
|
||||
);
|
||||
my $support = Slic3r::Print::SupportMaterial->new(
|
||||
object_config => $print->print->objects->[0]->config,
|
||||
print_config => $print->print->config,
|
||||
flow => $flow,
|
||||
interface_flow => $flow,
|
||||
first_layer_flow => $flow,
|
||||
);
|
||||
my $support_z = $support->support_layers_z($print->print->objects->[0], \@contact_z, \@top_z, $config->layer_height);
|
||||
my $expected_top_spacing = $support->contact_distance($config->layer_height, $config->nozzle_diameter->[0]);
|
||||
|
||||
is $support_z->[0], $config->first_layer_height,
|
||||
'first layer height is honored';
|
||||
is scalar(grep { $support_z->[$_]-$support_z->[$_-1] <= 0 } 1..$#$support_z), 0,
|
||||
'no null or negative support layers';
|
||||
is scalar(grep { $support_z->[$_]-$support_z->[$_-1] > $config->nozzle_diameter->[0] + epsilon } 1..$#$support_z), 0,
|
||||
'no layers thicker than nozzle diameter';
|
||||
|
||||
my $wrong_top_spacing = 0;
|
||||
foreach my $top_z (@top_z) {
|
||||
# find layer index of this top surface
|
||||
my $layer_id = first { abs($support_z->[$_] - $top_z) < epsilon } 0..$#$support_z;
|
||||
|
||||
# check that first support layer above this top surface (or the next one) is spaced with nozzle diameter
|
||||
$wrong_top_spacing = 1
|
||||
if ($support_z->[$layer_id+1] - $support_z->[$layer_id]) != $expected_top_spacing
|
||||
&& ($support_z->[$layer_id+2] - $support_z->[$layer_id]) != $expected_top_spacing;
|
||||
}
|
||||
ok !$wrong_top_spacing, 'layers above top surfaces are spaced correctly';
|
||||
};
|
||||
|
||||
$config->set('layer_height', 0.2);
|
||||
$config->set('first_layer_height', 0.3);
|
||||
@contact_z = (1.9);
|
||||
@top_z = (1.1);
|
||||
$test->();
|
||||
|
||||
$config->set('first_layer_height', 0.4);
|
||||
$test->();
|
||||
|
||||
$config->set('layer_height', $config->nozzle_diameter->[0]);
|
||||
$test->();
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('raft_layers', 3);
|
||||
$config->set('brim_width', 0);
|
||||
$config->set('skirts', 0);
|
||||
$config->set('support_material_extruder', 2);
|
||||
$config->set('support_material_interface_extruder', 2);
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', 0.4);
|
||||
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
||||
ok my $gcode = Slic3r::Test::gcode($print), 'no conflict between raft/support and brim';
|
||||
|
||||
my $tool = 0;
|
||||
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd =~ /^T(\d+)/) {
|
||||
$tool = $1;
|
||||
} elsif ($info->{extruding}) {
|
||||
if ($self->Z <= ($config->raft_layers * $config->layer_height)) {
|
||||
fail 'not extruding raft with support material extruder'
|
||||
if $tool != ($config->support_material_extruder-1);
|
||||
} else {
|
||||
fail 'support material exceeds raft layers'
|
||||
if $tool == $config->support_material_extruder-1;
|
||||
# TODO: we should test that full support is generated when we use raft too
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('raft_layers', 3);
|
||||
$config->set('support_material_pattern', 'honeycomb');
|
||||
$config->set('support_material_extrusion_width', 0.6);
|
||||
$config->set('first_layer_extrusion_width', '100%');
|
||||
$config->set('bridge_speed', 99);
|
||||
$config->set('cooling', [ 0 ]); # prevent speed alteration
|
||||
$config->set('first_layer_speed', '100%'); # prevent speed alteration
|
||||
$config->set('start_gcode', ''); # prevent any unexpected Z move
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
|
||||
my $layer_id = -1; # so that first Z move sets this to 0
|
||||
my @raft = my @first_object_layer = ();
|
||||
my %first_object_layer_speeds = (); # F => 1
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
if ($layer_id <= $config->raft_layers) {
|
||||
# this is a raft layer or the first object layer
|
||||
my $line = Slic3r::Line->new_scale([ $self->X, $self->Y ], [ $info->{new_X}, $info->{new_Y} ]);
|
||||
my @path = @{$line->grow(scale($config->support_material_extrusion_width/2))};
|
||||
if ($layer_id < $config->raft_layers) {
|
||||
# this is a raft layer
|
||||
push @raft, @path;
|
||||
} else {
|
||||
push @first_object_layer, @path;
|
||||
$first_object_layer_speeds{ $args->{F} // $self->F } = 1;
|
||||
}
|
||||
}
|
||||
} elsif ($cmd eq 'G1' && $info->{dist_Z} > 0) {
|
||||
$layer_id++;
|
||||
}
|
||||
});
|
||||
|
||||
ok !@{diff(\@first_object_layer, \@raft)},
|
||||
'first object layer is completely supported by raft';
|
||||
is scalar(keys %first_object_layer_speeds), 1,
|
||||
'only one speed used in first object layer';
|
||||
ok +(keys %first_object_layer_speeds)[0] == $config->bridge_speed*60,
|
||||
'bridge speed used in first object layer';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('layer_height', 0.35);
|
||||
$config->set('first_layer_height', 0.3);
|
||||
$config->set('nozzle_diameter', [0.5]);
|
||||
$config->set('support_material_extruder', 2);
|
||||
$config->set('support_material_interface_extruder', 2);
|
||||
|
||||
my $test = sub {
|
||||
my ($raft_layers) = @_;
|
||||
$config->set('raft_layers', $raft_layers);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my %raft_z = (); # z => 1
|
||||
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 ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
if ($tool == $config->support_material_extruder-1) {
|
||||
$raft_z{$self->Z} = 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
is scalar(keys %raft_z), $config->raft_layers, 'correct number of raft layers is generated';
|
||||
};
|
||||
|
||||
$test->(2);
|
||||
$test->(70);
|
||||
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', 0.35);
|
||||
$test->(3);
|
||||
$test->(70);
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('brim_width', 0);
|
||||
$config->set('skirts', 0);
|
||||
$config->set('support_material', 1);
|
||||
$config->set('top_solid_layers', 0); # so that we don't have the internal bridge over infill
|
||||
$config->set('bridge_speed', 99);
|
||||
$config->set('cooling', [ 0 ]);
|
||||
$config->set('first_layer_speed', '100%');
|
||||
|
||||
my $test = sub {
|
||||
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
||||
|
||||
my $has_bridge_speed = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{extruding}) {
|
||||
if (($args->{F} // $self->F) == $config->bridge_speed*60) {
|
||||
$has_bridge_speed = 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
return $has_bridge_speed;
|
||||
};
|
||||
|
||||
$config->set('support_material_contact_distance', 0.2);
|
||||
ok $test->(), 'bridge speed is used when support_material_contact_distance > 0';
|
||||
|
||||
$config->set('support_material_contact_distance', 0);
|
||||
ok !$test->(), 'bridge speed is not used when support_material_contact_distance == 0';
|
||||
|
||||
$config->set('raft_layers', 5);
|
||||
$config->set('support_material_contact_distance', 0.2);
|
||||
ok $test->(), 'bridge speed is used when raft_layers > 0 and support_material_contact_distance > 0';
|
||||
|
||||
$config->set('support_material_contact_distance', 0);
|
||||
ok !$test->(), 'bridge speed is not used when raft_layers > 0 and support_material_contact_distance == 0';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('start_gcode', '');
|
||||
$config->set('raft_layers', 8);
|
||||
$config->set('nozzle_diameter', [0.4, 1]);
|
||||
$config->set('layer_height', 0.1);
|
||||
$config->set('first_layer_height', 0.8);
|
||||
$config->set('support_material_extruder', 2);
|
||||
$config->set('support_material_interface_extruder', 2);
|
||||
$config->set('support_material_contact_distance', 0);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok my $gcode = Slic3r::Test::gcode($print), 'first_layer_height is validated with support material extruder nozzle diameter when using raft layers';
|
||||
|
||||
my $tool = undef;
|
||||
my @z = (0);
|
||||
my %layer_heights_by_tool = (); # tool => [ lh, lh... ]
|
||||
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd =~ /^T(\d+)/) {
|
||||
$tool = $1;
|
||||
} elsif ($cmd eq 'G1' && exists $args->{Z} && $args->{Z} != $self->Z) {
|
||||
push @z, $args->{Z};
|
||||
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
$layer_heights_by_tool{$tool} ||= [];
|
||||
push @{ $layer_heights_by_tool{$tool} }, $z[-1] - $z[-2];
|
||||
}
|
||||
});
|
||||
|
||||
ok !defined(first { $_ > $config->nozzle_diameter->[0] + epsilon }
|
||||
@{ $layer_heights_by_tool{$config->perimeter_extruder-1} }),
|
||||
'no object layer is thicker than nozzle diameter';
|
||||
|
||||
ok !defined(first { abs($_ - $config->layer_height) < epsilon }
|
||||
@{ $layer_heights_by_tool{$config->support_material_extruder-1} }),
|
||||
'no support material layer is as thin as object layers';
|
||||
}
|
||||
|
||||
__END__
|
||||
185
t/thin.t
Normal file
185
t/thin.t
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
use Test::More tests => 23;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use List::Util qw(first sum none);
|
||||
use Slic3r::Geometry qw(epsilon scale unscale scaled_epsilon Y);
|
||||
use Slic3r::Test;
|
||||
|
||||
# Disable this until a more robust implementation is provided. It currently
|
||||
# fails on Linux 32bit because some spurious extrudates are generated.
|
||||
if (0) {
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('layer_height', 0.2);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('extrusion_width', 0.5);
|
||||
$config->set('first_layer_extrusion_width', '200%'); # check this one too
|
||||
$config->set('skirts', 0);
|
||||
$config->set('thin_walls', 1);
|
||||
|
||||
my $print = Slic3r::Test::init_print('gt2_teeth', config => $config);
|
||||
|
||||
my %extrusion_paths = (); # Z => count of continuous extrusions
|
||||
my $extruding = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1') {
|
||||
if ($info->{extruding} && $info->{dist_XY}) {
|
||||
if (!$extruding) {
|
||||
$extrusion_paths{$self->Z} //= 0;
|
||||
$extrusion_paths{$self->Z}++;
|
||||
}
|
||||
$extruding = 1;
|
||||
} else {
|
||||
$extruding = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ok !(first { $_ != 3 } values %extrusion_paths),
|
||||
'no superfluous thin walls are generated for toothed profile';
|
||||
}
|
||||
|
||||
{
|
||||
my $square = Slic3r::Polygon->new_scale( # ccw
|
||||
[100, 100],
|
||||
[200, 100],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
);
|
||||
my $hole_in_square = Slic3r::Polygon->new_scale( # cw
|
||||
[140, 140],
|
||||
[140, 160],
|
||||
[160, 160],
|
||||
[160, 140],
|
||||
);
|
||||
my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
|
||||
my $res = $expolygon->medial_axis(scale 40, scale 0.5);
|
||||
is scalar(@$res), 1, 'medial axis of a square shape is a single path';
|
||||
isa_ok $res->[0], 'Slic3r::Polyline', 'medial axis result is a polyline';
|
||||
ok $res->[0]->first_point->coincides_with($res->[0]->last_point), 'polyline forms a closed loop';
|
||||
ok $res->[0]->length > $hole_in_square->length && $res->[0]->length < $square->length,
|
||||
'medial axis loop has reasonable length';
|
||||
}
|
||||
|
||||
{
|
||||
my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
|
||||
[100, 100],
|
||||
[120, 100],
|
||||
[120, 200],
|
||||
[100, 200],
|
||||
));
|
||||
my $res = $expolygon->medial_axis(scale 20, scale 0.5);
|
||||
is scalar(@$res), 1, 'medial axis of a narrow rectangle is a single line';
|
||||
ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has reasonable length';
|
||||
|
||||
$expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
|
||||
[100, 100],
|
||||
[120, 100],
|
||||
[120, 200],
|
||||
[105, 200], # extra point in the short side
|
||||
[100, 200],
|
||||
));
|
||||
my $res2 = $expolygon->medial_axis(scale 1, scale 0.5);
|
||||
is scalar(@$res), 1, 'medial axis of a narrow rectangle with an extra vertex is still a single line';
|
||||
ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has still a reasonable length';
|
||||
ok !(grep { abs($_ - scale 150) < scaled_epsilon } map $_->[Y], map @$_, @$res2), "extra vertices don't influence medial axis";
|
||||
}
|
||||
|
||||
{
|
||||
my $expolygon = Slic3r::ExPolygon->new(
|
||||
Slic3r::Polygon->new([1185881,829367],[1421988,1578184],[1722442,2303558],[2084981,2999998],[2506843,3662186],[2984809,4285086],[3515250,4863959],[4094122,5394400],[4717018,5872368],[5379210,6294226],[6075653,6656769],[6801033,6957229],[7549842,7193328],[8316383,7363266],[9094809,7465751],[9879211,7500000],[10663611,7465750],[11442038,7363265],[12208580,7193327],[12957389,6957228],[13682769,6656768],[14379209,6294227],[15041405,5872366],[15664297,5394401],[16243171,4863960],[16758641,4301424],[17251579,3662185],[17673439,3000000],[18035980,2303556],[18336441,1578177],[18572539,829368],[18750748,0],[19758422,0],[19727293,236479],[19538467,1088188],[19276136,1920196],[18942292,2726179],[18539460,3499999],[18070731,4235755],[17539650,4927877],[16950279,5571067],[16307090,6160437],[15614974,6691519],[14879209,7160248],[14105392,7563079],[13299407,7896927],[12467399,8159255],[11615691,8348082],[10750769,8461952],[9879211,8500000],[9007652,8461952],[8142729,8348082],[7291022,8159255],[6459015,7896927],[5653029,7563079],[4879210,7160247],[4143447,6691519],[3451331,6160437],[2808141,5571066],[2218773,4927878],[1687689,4235755],[1218962,3499999],[827499,2748020],[482284,1920196],[219954,1088186],[31126,236479],[0,0],[1005754,0]),
|
||||
);
|
||||
my $res = $expolygon->medial_axis(scale 1.324888, scale 0.25);
|
||||
is scalar(@$res), 1, 'medial axis of a semicircumference is a single line';
|
||||
|
||||
# check whether turns are all CCW or all CW
|
||||
my @lines = @{$res->[0]->lines};
|
||||
my @angles = map { $lines[$_-1]->ccw($lines[$_]->b) } 1..$#lines;
|
||||
ok !!(none { $_ < 0 } @angles) || (none { $_ > 0 } @angles),
|
||||
'all medial axis segments of a semicircumference have the same orientation';
|
||||
}
|
||||
|
||||
{
|
||||
my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
|
||||
[100, 100],
|
||||
[120, 100],
|
||||
[112, 200],
|
||||
[108, 200],
|
||||
));
|
||||
my $res = $expolygon->medial_axis(scale 20, scale 0.5);
|
||||
is scalar(@$res), 1, 'medial axis of a narrow trapezoid is a single line';
|
||||
ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has reasonable length';
|
||||
}
|
||||
|
||||
{
|
||||
my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
|
||||
[100, 100],
|
||||
[120, 100],
|
||||
[120, 180],
|
||||
[200, 180],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
));
|
||||
my $res = $expolygon->medial_axis(scale 20, scale 0.5);
|
||||
is scalar(@$res), 1, 'medial axis of a L shape is a single polyline';
|
||||
my $len = unscale($res->[0]->length) + 20; # 20 is the thickness of the expolygon, which is subtracted from the ends
|
||||
ok $len > 80*2 && $len < 100*2, 'medial axis has reasonable length';
|
||||
}
|
||||
|
||||
{
|
||||
my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new(
|
||||
[-203064906,-51459966],[-219312231,-51459966],[-219335477,-51459962],[-219376095,-51459962],[-219412047,-51459966],
|
||||
[-219572094,-51459966],[-219624814,-51459962],[-219642183,-51459962],[-219656665,-51459966],[-220815482,-51459966],
|
||||
[-220815482,-37738966],[-221117540,-37738966],[-221117540,-51762024],[-203064906,-51762024],
|
||||
));
|
||||
my $polylines = $expolygon->medial_axis(819998, 102499.75);
|
||||
|
||||
my $perimeter = $expolygon->contour->split_at_first_point->length;
|
||||
ok sum(map $_->length, @$polylines) > $perimeter/2/4*3, 'medial axis has a reasonable length';
|
||||
}
|
||||
|
||||
{
|
||||
my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
|
||||
[50, 100],
|
||||
[1000, 102],
|
||||
[50, 104],
|
||||
));
|
||||
my $res = $expolygon->medial_axis(scale 4, scale 0.5);
|
||||
is scalar(@$res), 1, 'medial axis of a narrow triangle is a single line';
|
||||
ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has reasonable length';
|
||||
}
|
||||
|
||||
{
|
||||
# GH #2474
|
||||
my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new(
|
||||
[91294454,31032190],[11294481,31032190],[11294481,29967810],[44969182,29967810],[89909960,29967808],[91294454,29967808]
|
||||
));
|
||||
my $polylines = $expolygon->medial_axis(1871238, 500000);
|
||||
is scalar(@$polylines), 1, 'medial axis is a single polyline';
|
||||
my $polyline = $polylines->[0];
|
||||
|
||||
my $expected_y = $expolygon->bounding_box->center->y; #;;
|
||||
ok abs(sum(map $_->y, @$polyline) / @$polyline - $expected_y) < scaled_epsilon, #,,
|
||||
'medial axis is horizontal and is centered';
|
||||
|
||||
# order polyline from left to right
|
||||
$polyline->reverse if $polyline->first_point->x > $polyline->last_point->x;
|
||||
|
||||
my $polyline_bb = $polyline->bounding_box;
|
||||
is $polyline->first_point->x, $polyline_bb->x_min, 'expected x_min';
|
||||
is $polyline->last_point->x, $polyline_bb->x_max, 'expected x_max';
|
||||
|
||||
is_deeply [ map $_->x, @$polyline ], [ sort map $_->x, @$polyline ],
|
||||
'medial axis is not self-overlapping';
|
||||
}
|
||||
|
||||
__END__
|
||||
Loading…
Add table
Add a link
Reference in a new issue