mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-01 21:21:10 -06:00
New semantics for ExtrusionLoop objects. Early processing of perimeter overhangs for paralellizing such work and making G-code export lighter. Lots of refactoring. This should fix a number of minor bugs, including reversals of perimeter overhangs.
This commit is contained in:
parent
d2d885fc53
commit
c37ef2f18b
27 changed files with 618 additions and 423 deletions
|
|
@ -3,37 +3,86 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use List::Util qw(sum);
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 8;
|
||||
|
||||
my $square = [
|
||||
[100, 100],
|
||||
[200, 100],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
];
|
||||
|
||||
my $loop = Slic3r::ExtrusionLoop->new(
|
||||
polygon => Slic3r::Polygon->new(@$square),
|
||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
||||
mm3_per_mm => 1,
|
||||
);
|
||||
isa_ok $loop, 'Slic3r::ExtrusionLoop';
|
||||
isa_ok $loop->polygon, 'Slic3r::Polygon', 'loop polygon';
|
||||
is_deeply $loop->polygon->pp, $square, 'polygon points roundtrip';
|
||||
|
||||
$loop = $loop->clone;
|
||||
|
||||
is $loop->role, Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, 'role';
|
||||
$loop->role(Slic3r::ExtrusionPath::EXTR_ROLE_FILL);
|
||||
is $loop->role, Slic3r::ExtrusionPath::EXTR_ROLE_FILL, 'modify role';
|
||||
use Test::More tests => 30;
|
||||
|
||||
{
|
||||
my $path = $loop->split_at_first_point;
|
||||
is_deeply $path->polyline->pp, [ @$square[0,1,2,3,0] ], 'split_at_first_point';
|
||||
is $path->role, $loop->role, 'role preserved after split';
|
||||
my $square = [
|
||||
[100, 100],
|
||||
[200, 100],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
];
|
||||
my $square_p = Slic3r::Polygon->new(@$square);
|
||||
|
||||
my $loop = Slic3r::ExtrusionLoop->new;
|
||||
$loop->append(Slic3r::ExtrusionPath->new(
|
||||
polyline => $square_p->split_at_first_point,
|
||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
||||
mm3_per_mm => 1,
|
||||
));
|
||||
|
||||
isa_ok $loop, 'Slic3r::ExtrusionLoop';
|
||||
isa_ok $loop->polygon, 'Slic3r::Polygon', 'loop polygon';
|
||||
is $loop->polygon->area, $square_p->area, 'polygon area';
|
||||
is $loop->length, $square_p->length(), 'loop length';
|
||||
|
||||
$loop = $loop->clone;
|
||||
|
||||
is scalar(@$loop), 1, 'loop contains one path';
|
||||
{
|
||||
my $path = $loop->[0];
|
||||
isa_ok $path, 'Slic3r::ExtrusionPath::Ref';
|
||||
is $path->role, Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, 'role';
|
||||
$path->role(Slic3r::ExtrusionPath::EXTR_ROLE_FILL);
|
||||
is $path->role, Slic3r::ExtrusionPath::EXTR_ROLE_FILL, 'modify role';
|
||||
}
|
||||
|
||||
$loop->split_at($square_p->[2]);
|
||||
is scalar(@$loop), 1, 'splitting a single-path loop results in a single path';
|
||||
is scalar(@{$loop->[0]->polyline}), 5, 'path has correct number of points';
|
||||
ok $loop->[0]->polyline->[0]->coincides_with($square_p->[2]), 'expected point order';
|
||||
ok $loop->[0]->polyline->[1]->coincides_with($square_p->[3]), 'expected point order';
|
||||
ok $loop->[0]->polyline->[2]->coincides_with($square_p->[0]), 'expected point order';
|
||||
ok $loop->[0]->polyline->[3]->coincides_with($square_p->[1]), 'expected point order';
|
||||
ok $loop->[0]->polyline->[4]->coincides_with($square_p->[2]), 'expected point order';
|
||||
}
|
||||
|
||||
{
|
||||
my $polyline1 = Slic3r::Polyline->new([100,100], [200,100], [200,200]);
|
||||
my $polyline2 = Slic3r::Polyline->new([200,200], [100,200], [100,100]);
|
||||
|
||||
is_deeply $loop->split_at_index(2)->polyline->pp, [ @$square[2,3,0,1,2] ], 'split_at_index';
|
||||
my $loop = Slic3r::ExtrusionLoop->new_from_paths(
|
||||
Slic3r::ExtrusionPath->new(
|
||||
polyline => $polyline1,
|
||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
||||
mm3_per_mm => 1,
|
||||
),
|
||||
Slic3r::ExtrusionPath->new(
|
||||
polyline => $polyline2,
|
||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_OVERHANG_PERIMETER,
|
||||
mm3_per_mm => 1,
|
||||
),
|
||||
);
|
||||
is $loop->length, sum($polyline1->length, $polyline2->length), 'length';
|
||||
is scalar(@$loop), 2, 'loop contains two paths';
|
||||
$loop->split_at($polyline1->[1]);
|
||||
is $loop->length, sum($polyline1->length, $polyline2->length), 'length after splitting';
|
||||
is scalar(@$loop), 3, 'loop contains three paths after splitting';
|
||||
ok $loop->[0]->polyline->[0]->coincides_with($polyline1->[1]), 'expected starting point';
|
||||
ok $loop->[-1]->polyline->[-1]->coincides_with($polyline1->[1]), 'expected ending point';
|
||||
ok $loop->[0]->polyline->[-1]->coincides_with($loop->[1]->polyline->[0]), 'paths have common point';
|
||||
ok $loop->[1]->polyline->[-1]->coincides_with($loop->[2]->polyline->[0]), 'paths have common point';
|
||||
is $loop->[0]->role, Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, 'expected order after splitting';
|
||||
is $loop->[1]->role, Slic3r::ExtrusionPath::EXTR_ROLE_OVERHANG_PERIMETER, 'expected order after splitting';
|
||||
is $loop->[2]->role, Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, 'expected order after splitting';
|
||||
is scalar(@{$loop->[0]->polyline}), 2, 'path has correct number of points';
|
||||
is scalar(@{$loop->[1]->polyline}), 3, 'path has correct number of points';
|
||||
is scalar(@{$loop->[2]->polyline}), 2, 'path has correct number of points';
|
||||
|
||||
my @paths = @{$loop->clip_end(3)};
|
||||
is sum(map $_->length, @paths), $loop->length - 3, 'returned paths have expected length';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
|||
|
|
@ -4,20 +4,20 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 11;
|
||||
use Test::More tests => 17;
|
||||
|
||||
my $square = [ # ccw
|
||||
my $square = Slic3r::Polygon->new( # ccw
|
||||
[200, 100],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
[100, 100],
|
||||
];
|
||||
my $hole_in_square = [ # cw
|
||||
);
|
||||
my $hole_in_square = Slic3r::Polygon->new( # cw
|
||||
[160, 140],
|
||||
[140, 140],
|
||||
[140, 160],
|
||||
[160, 160],
|
||||
];
|
||||
);
|
||||
my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
|
||||
|
||||
{
|
||||
|
|
@ -106,4 +106,53 @@ my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
|
|||
}
|
||||
}
|
||||
|
||||
if (0) { # Clipper does not preserve polyline orientation
|
||||
my $polyline = Slic3r::Polyline->new([50,150], [300,150]);
|
||||
my $result = Slic3r::Geometry::Clipper::intersection_pl([$polyline], [$square]);
|
||||
is scalar(@$result), 1, 'intersection_pl - correct number of result lines';
|
||||
is_deeply $result->[0]->pp, [[100,150], [200,150]], 'clipped line orientation is preserved';
|
||||
}
|
||||
|
||||
if (0) { # Clipper does not preserve polyline orientation
|
||||
my $polyline = Slic3r::Polyline->new([300,150], [50,150]);
|
||||
my $result = Slic3r::Geometry::Clipper::intersection_pl([$polyline], [$square]);
|
||||
is scalar(@$result), 1, 'intersection_pl - correct number of result lines';
|
||||
is_deeply $result->[0]->pp, [[200,150], [100,150]], 'clipped line orientation is preserved';
|
||||
}
|
||||
|
||||
if (0) { # Clipper does not preserve polyline orientation
|
||||
my $result = Slic3r::Geometry::Clipper::intersection_ppl([$hole_in_square], [$square]);
|
||||
is_deeply $result->[0]->pp, $hole_in_square->split_at_first_point->pp,
|
||||
'intersection_ppl - clipping cw polygon as polyline preserves winding order';
|
||||
}
|
||||
|
||||
{
|
||||
my $square2 = $square->clone;
|
||||
$square2->translate(50,50);
|
||||
{
|
||||
my $result = Slic3r::Geometry::Clipper::intersection_ppl([$square2], [$square]);
|
||||
is scalar(@$result), 1, 'intersection_ppl - result contains a single line';
|
||||
is scalar(@{$result->[0]}), 3, 'intersection_ppl - result contains expected number of points';
|
||||
# Clipper does not preserve polyline orientation so we only check the middle point
|
||||
###ok $result->[0][0]->coincides_with(Slic3r::Point->new(150,200)), 'intersection_ppl - expected point order';
|
||||
ok $result->[0][1]->coincides_with(Slic3r::Point->new(150,150)), 'intersection_ppl - expected point order';
|
||||
###ok $result->[0][2]->coincides_with(Slic3r::Point->new(200,150)), 'intersection_ppl - expected point order';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $square2 = $square->clone;
|
||||
$square2->reverse;
|
||||
$square2->translate(50,50);
|
||||
{
|
||||
my $result = Slic3r::Geometry::Clipper::intersection_ppl([$square2], [$square]);
|
||||
is scalar(@$result), 1, 'intersection_ppl - result contains a single line';
|
||||
is scalar(@{$result->[0]}), 3, 'intersection_ppl - result contains expected number of points';
|
||||
# Clipper does not preserve polyline orientation so we only check the middle point
|
||||
###ok $result->[0][0]->coincides_with(Slic3r::Point->new(200,150)), 'intersection_ppl - expected point order';
|
||||
ok $result->[0][1]->coincides_with(Slic3r::Point->new(150,150)), 'intersection_ppl - expected point order';
|
||||
###ok $result->[0][2]->coincides_with(Slic3r::Point->new(150,200)), 'intersection_ppl - expected point order';
|
||||
}
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@ my $path = Slic3r::ExtrusionPath->new(
|
|||
mm3_per_mm => 1,
|
||||
);
|
||||
|
||||
my $loop = Slic3r::ExtrusionLoop->new(
|
||||
polygon => Slic3r::Polygon->new(@$points),
|
||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_FILL,
|
||||
mm3_per_mm => 1,
|
||||
my $loop = Slic3r::ExtrusionLoop->new_from_paths(
|
||||
Slic3r::ExtrusionPath->new(
|
||||
polyline => Slic3r::Polygon->new(@$points)->split_at_first_point,
|
||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_FILL,
|
||||
mm3_per_mm => 1,
|
||||
),
|
||||
);
|
||||
|
||||
my $collection = Slic3r::ExtrusionPath::Collection->new($path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue