Finished porting group() to XS
This commit is contained in:
parent
67a7e4f769
commit
a331f4d27a
11 changed files with 68 additions and 41 deletions
|
@ -13,7 +13,7 @@ use Slic3r::Fill::PlanePath;
|
|||
use Slic3r::Fill::Rectilinear;
|
||||
use Slic3r::ExtrusionPath ':roles';
|
||||
use Slic3r::Geometry qw(X Y PI scale chained_path);
|
||||
use Slic3r::Geometry::Clipper qw(union_ex diff diff_ex intersection_ex offset offset2);
|
||||
use Slic3r::Geometry::Clipper qw(union union_ex diff diff_ex intersection_ex offset offset2);
|
||||
use Slic3r::Surface ':types';
|
||||
|
||||
|
||||
|
@ -58,28 +58,26 @@ sub make_fill {
|
|||
# in case of bridge surfaces, the ones with defined angle will be attached to the ones
|
||||
# without any angle (shouldn't this logic be moved to process_external_surfaces()?)
|
||||
{
|
||||
my @fill_surfaces = @{$layerm->fill_surfaces};
|
||||
my @surfaces_with_bridge_angle = grep defined $_->bridge_angle, @fill_surfaces;
|
||||
my @surfaces_with_bridge_angle = grep defined $_->bridge_angle, @{$layerm->fill_surfaces};
|
||||
|
||||
# give priority to bridges
|
||||
my @groups = Slic3r::Surface->group({merge_solid => 1}, @fill_surfaces);
|
||||
@groups = sort { defined $a->[0]->bridge_angle ? -1 : 0 } @groups;
|
||||
my @groups = sort { defined $a->[0]->bridge_angle ? -1 : 0 } @{$layerm->fill_surfaces->group(1)};
|
||||
|
||||
foreach my $group (@groups) {
|
||||
my $union = union_ex([ map $_->p, @$group ], 1);
|
||||
my $union_p = union([ map $_->p, @$group ], 1);
|
||||
|
||||
# subtract surfaces having a defined bridge_angle from any other
|
||||
if (@surfaces_with_bridge_angle && !defined $group->[0]->bridge_angle) {
|
||||
$union = diff_ex(
|
||||
[ map @$_, @$union ],
|
||||
$union_p = diff(
|
||||
$union_p,
|
||||
[ map $_->p, @surfaces_with_bridge_angle ],
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
||||
# subtract any other surface already processed
|
||||
$union = diff_ex(
|
||||
[ map @$_, @$union ],
|
||||
my $union = diff_ex(
|
||||
$union_p,
|
||||
[ map $_->p, @surfaces ],
|
||||
1,
|
||||
);
|
||||
|
|
|
@ -458,7 +458,7 @@ sub process_external_surfaces {
|
|||
|
||||
# intersect the grown surfaces with the actual fill boundaries
|
||||
my @new_surfaces = ();
|
||||
foreach my $group (Slic3r::Surface->group(@top, @bottom)) {
|
||||
foreach my $group (@{Slic3r::Surface::Collection->new(@top, @bottom)->group}) {
|
||||
push @new_surfaces,
|
||||
map $group->[0]->clone(expolygon => $_),
|
||||
@{intersection_ex(
|
||||
|
@ -470,7 +470,7 @@ sub process_external_surfaces {
|
|||
|
||||
# subtract the new top surfaces from the other non-top surfaces and re-add them
|
||||
my @other = grep $_->surface_type != S_TYPE_TOP && $_->surface_type != S_TYPE_BOTTOM, @surfaces;
|
||||
foreach my $group (Slic3r::Surface->group(@other)) {
|
||||
foreach my $group (@{Slic3r::Surface::Collection->new(@other)->group}) {
|
||||
push @new_surfaces, map $group->[0]->clone(expolygon => $_), @{diff_ex(
|
||||
[ map $_->p, @$group ],
|
||||
[ map $_->p, @new_surfaces ],
|
||||
|
|
|
@ -487,7 +487,7 @@ sub bridge_over_infill {
|
|||
foreach my $lower_layerm (@{$self->layers->[$i]->regions}) {
|
||||
my @new_surfaces = ();
|
||||
# subtract the area from all types of surfaces
|
||||
foreach my $group (Slic3r::Surface->group(@{$lower_layerm->fill_surfaces})) {
|
||||
foreach my $group (@{$lower_layerm->fill_surfaces->group}) {
|
||||
push @new_surfaces, map $group->[0]->clone(expolygon => $_),
|
||||
@{diff_ex(
|
||||
[ map $_->p, @$group ],
|
||||
|
@ -647,7 +647,7 @@ sub discover_horizontal_shells {
|
|||
(expolygon => $_, surface_type => S_TYPE_INTERNALSOLID), @$internal_solid);
|
||||
|
||||
# assign top and bottom surfaces to layer
|
||||
foreach my $s (Slic3r::Surface->group(grep { ($_->surface_type == S_TYPE_TOP) || ($_->surface_type == S_TYPE_BOTTOM) } @neighbor_fill_surfaces)) {
|
||||
foreach my $s (@{Slic3r::Surface::Collection->new(grep { ($_->surface_type == S_TYPE_TOP) || ($_->surface_type == S_TYPE_BOTTOM) } @neighbor_fill_surfaces)->group}) {
|
||||
my $solid_surfaces = diff_ex(
|
||||
[ map $_->p, @$s ],
|
||||
[ map @$_, @$internal_solid, @$internal ],
|
||||
|
|
|
@ -7,26 +7,6 @@ our @ISA = qw(Exporter);
|
|||
our @EXPORT_OK = qw(S_TYPE_TOP S_TYPE_BOTTOM S_TYPE_INTERNAL S_TYPE_INTERNALSOLID S_TYPE_INTERNALBRIDGE S_TYPE_INTERNALVOID);
|
||||
our %EXPORT_TAGS = (types => \@EXPORT_OK);
|
||||
|
||||
# static method to group surfaces having same surface_type, bridge_angle and thickness*
|
||||
sub group {
|
||||
my $class = shift;
|
||||
my $params = ref $_[0] eq 'HASH' ? shift(@_) : {};
|
||||
my (@surfaces) = @_;
|
||||
|
||||
my %unique_types = ();
|
||||
foreach my $surface (@surfaces) {
|
||||
my $type = join '_',
|
||||
($params->{merge_solid} && $surface->is_solid) ? 'solid' : $surface->surface_type,
|
||||
$surface->bridge_angle // '',
|
||||
$surface->thickness // '',
|
||||
$surface->thickness_layers;
|
||||
$unique_types{$type} ||= [];
|
||||
push @{ $unique_types{$type} }, $surface;
|
||||
}
|
||||
|
||||
return values %unique_types;
|
||||
}
|
||||
|
||||
sub offset {
|
||||
my $self = shift;
|
||||
return [ map $self->clone(expolygon => $_), @{$self->expolygon->offset_ex(@_)} ];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue