Ported union_pt() to XS

This commit is contained in:
Alessandro Ranellucci 2013-08-26 18:37:19 +02:00
parent 443d4e52cb
commit 9cf831b9c5
7 changed files with 78 additions and 42 deletions

View file

@ -37,7 +37,7 @@ sub fill_surface {
# generate paths from the outermost to the innermost, to avoid
# adhesion problems of the first central tiny loops
@loops = map Slic3r::Polygon->new(@$_),
reverse traverse_pt( union_pt(\@loops, PFT_EVENODD) );
reverse traverse_pt( union_pt(\@loops) );
# order paths using a nearest neighbor search
my @paths = ();

View file

@ -13,20 +13,6 @@ use Math::Clipper 1.22 qw(:cliptypes :polyfilltypes :jointypes is_counter_clockw
use Slic3r::Geometry qw(scale);
our $clipper = Math::Clipper->new;
sub _safety_offset {
my ($polygons, $factor) = @_;
return [ map Slic3r::Polygon->new(@$_),
@{Math::Clipper::int_offset(_convert($polygons), $factor // (scale 1e-05), 100000, JT_MITER, 2)} ];
}
sub union_pt {
my ($polygons, $jointype, $safety_offset) = @_;
$jointype = PFT_NONZERO unless defined $jointype;
$clipper->clear;
$clipper->add_subject_polygons($safety_offset ? _convert(_safety_offset($polygons)) : _convert($polygons));
return $clipper->pt_execute(CT_UNION, $jointype, $jointype);
}
sub traverse_pt {
my ($polynodes) = @_;
@ -45,10 +31,4 @@ sub traverse_pt {
return @polygons;
}
sub _convert {
my $p = shift;
$p = $p->pp if ref($p) ne 'ARRAY' && $p->can('pp');
return [ map { (ref($_) ne 'ARRAY' && $_->can('pp')) ? $_->pp : $_ } @$p ];
}
1;

View file

@ -239,8 +239,8 @@ sub make_perimeters {
$self->_fill_gaps(\@gaps);
# find nesting hierarchies separately for contours and holes
my $contours_pt = union_pt(\@contours, PFT_EVENODD);
my $holes_pt = union_pt(\@holes, PFT_EVENODD);
my $contours_pt = union_pt(\@contours);
my $holes_pt = union_pt(\@holes);
# prepare a coderef for traversing the PolyTree object
# external contours are root items of $contours_pt

View file

@ -681,7 +681,7 @@ sub make_brim {
polygon => Slic3r::Polygon->new(@$_),
role => EXTR_ROLE_SKIRT,
flow_spacing => $flow->spacing,
), reverse traverse_pt( union_pt(\@loops, PFT_EVENODD) );
), reverse traverse_pt( union_pt(\@loops) );
}
sub write_gcode {