Ported diff_ex, intersection_ex, union_ex, xor_ex

This commit is contained in:
Alessandro Ranellucci 2013-07-17 00:29:09 +02:00
parent f7ada2b5db
commit bf8c799685
9 changed files with 72 additions and 48 deletions

View file

@ -70,7 +70,7 @@ sub make_fill {
@groups = sort { defined $a->[0]->bridge_angle ? -1 : 0 } @groups;
foreach my $group (@groups) {
my $union = union_ex([ map $_->p, @$group ], undef, 1);
my $union = union_ex([ map $_->p, @$group ], 1);
# subtract surfaces having a defined bridge_angle from any other
if (@surfaces_with_bridge_angle && !defined $group->[0]->bridge_angle) {
@ -120,7 +120,6 @@ sub make_fill {
(map @{$_->expolygon}, grep $_->surface_type == S_TYPE_INTERNALVOID, @surfaces),
(@$collapsed),
],
undef,
1,
)};
}

View file

@ -105,7 +105,7 @@ sub change_layer {
);
if ($self->config->avoid_crossing_perimeters) {
$self->layer_mp(Slic3r::GCode::MotionPlanner->new(
islands => union_ex([ map @$_, @{$layer->slices} ], undef, 1),
islands => union_ex([ map @$_, @{$layer->slices} ], 1),
));
}

View file

@ -57,18 +57,6 @@ sub diff {
];
}
sub union_ex {
my ($polygons, $jointype, $safety_offset) = @_;
$jointype = PFT_NONZERO unless defined $jointype;
$clipper->clear;
$polygons = $polygons->arrayref if ref $polygons eq 'Slic3r::ExPolygon';
$clipper->add_subject_polygons($safety_offset ? _convert(safety_offset($polygons)) : _convert($polygons));
return [
map Slic3r::ExPolygon->new($_->{outer}, @{$_->{holes}}),
@{ $clipper->ex_execute(CT_UNION, $jointype, $jointype) },
];
}
sub union_pt {
my ($polygons, $jointype, $safety_offset) = @_;
$jointype = PFT_NONZERO unless defined $jointype;
@ -77,18 +65,6 @@ sub union_pt {
return $clipper->pt_execute(CT_UNION, $jointype, $jointype);
}
sub intersection_ex {
my ($subject, $clip, $jointype, $safety_offset) = @_;
$jointype = PFT_NONZERO unless defined $jointype;
$clipper->clear;
$clipper->add_subject_polygons(_convert($subject));
$clipper->add_clip_polygons($safety_offset ? _convert(safety_offset($clip)) : _convert($clip));
return [
map Slic3r::ExPolygon->new($_->{outer}, @{$_->{holes}}),
@{ $clipper->ex_execute(CT_INTERSECTION, $jointype, $jointype) },
];
}
sub intersection {
my ($subject, $clip, $jointype, $safety_offset) = @_;
$jointype = PFT_NONZERO unless defined $jointype;
@ -101,18 +77,6 @@ sub intersection {
];
}
sub xor_ex {
my ($subject, $clip, $jointype) = @_;
$jointype = PFT_NONZERO unless defined $jointype;
$clipper->clear;
$clipper->add_subject_polygons(_convert($subject));
$clipper->add_clip_polygons(_convert($clip));
return [
map Slic3r::ExPolygon->new($_->{outer}, @{$_->{holes}}),
@{ $clipper->ex_execute(CT_XOR, $jointype, $jointype) },
];
}
sub collapse_ex {
my ($polygons, $width) = @_;
return offset2_ex($polygons, -$width/2, +$width/2);

View file

@ -418,13 +418,11 @@ sub process_external_surfaces {
@top = @{intersection_ex(
[ Slic3r::Geometry::Clipper::offset([ map $_->p, @top ], +$margin) ],
[ map $_->p, @fill_boundaries ],
undef,
1, # to ensure adjacent expolygons are unified
)};
@bottom = @{intersection_ex(
[ Slic3r::Geometry::Clipper::offset([ map $_->p, @bottom ], +$margin) ],
[ map $_->p, @fill_boundaries ],
undef,
1, # to ensure adjacent expolygons are unified
)};
@ -526,7 +524,6 @@ sub _detect_bridges {
my $anchors = intersection_ex(
[ $surface->p ],
[ map @$_, @lower ],
undef,
1, # safety offset required to avoid Clipper from detecting empty intersection while Boost actually found some @edges
);

View file

@ -610,7 +610,7 @@ sub discover_horizontal_shells {
my $new_internal_solid = intersection_ex(
[ map @$_, @$solid ],
[ map $_->p, grep { ($_->surface_type == S_TYPE_INTERNAL) || ($_->surface_type == S_TYPE_INTERNALSOLID) } @neighbor_fill_surfaces ],
undef, 1,
1,
);
next if !@$new_internal_solid;