2011-10-10 15:27:00 +00:00
|
|
|
package Slic3r::Geometry::Clipper;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
require Exporter;
|
|
|
|
our @ISA = qw(Exporter);
|
|
|
|
our @EXPORT_OK = qw(diff_ex diff union_ex);
|
|
|
|
|
2011-10-11 15:56:56 +00:00
|
|
|
use Math::Clipper 1.02 ':all';
|
2011-10-10 15:27:00 +00:00
|
|
|
our $clipper = Math::Clipper->new;
|
|
|
|
|
|
|
|
sub diff_ex {
|
|
|
|
my ($subject, $clip) = @_;
|
|
|
|
|
|
|
|
$clipper->clear;
|
|
|
|
$clipper->add_subject_polygons($subject);
|
|
|
|
$clipper->add_clip_polygons($clip);
|
|
|
|
return $clipper->ex_execute(CT_DIFFERENCE, PFT_NONZERO, PFT_NONZERO);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub diff {
|
|
|
|
return [ map { $_->{outer}, $_->{holes} } diff_ex(@_) ];
|
|
|
|
}
|
|
|
|
|
|
|
|
sub union_ex {
|
|
|
|
my ($polygons) = @_;
|
|
|
|
$clipper->clear;
|
|
|
|
$clipper->add_subject_polygons($polygons);
|
|
|
|
return $clipper->ex_execute(CT_UNION, PFT_NONZERO, PFT_NONZERO);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|