2011-10-10 15:27:00 +00:00
|
|
|
package Slic3r::Geometry::Clipper;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
require Exporter;
|
|
|
|
our @ISA = qw(Exporter);
|
2013-08-26 15:58:37 +00:00
|
|
|
our @EXPORT_OK = qw(offset offset_ex
|
2013-09-06 15:43:40 +00:00
|
|
|
diff_ex diff union_ex intersection_ex xor_ex JT_ROUND JT_MITER
|
2013-05-31 12:30:07 +00:00
|
|
|
JT_SQUARE is_counter_clockwise union_pt offset2 offset2_ex traverse_pt
|
2013-11-21 13:15:38 +00:00
|
|
|
intersection intersection_pl diff_pl union CLIPPER_OFFSET_SCALE);
|
2011-10-10 15:27:00 +00:00
|
|
|
|
2011-12-02 22:35:39 +00:00
|
|
|
use Slic3r::Geometry qw(scale);
|
2011-10-10 15:27:00 +00:00
|
|
|
|
2013-05-11 07:24:48 +00:00
|
|
|
sub traverse_pt {
|
2013-05-11 19:30:26 +00:00
|
|
|
my ($polynodes) = @_;
|
2013-05-11 07:24:48 +00:00
|
|
|
|
|
|
|
# use a nearest neighbor search to order these children
|
|
|
|
# TODO: supply second argument to chained_path_items() too?
|
|
|
|
my @nodes = @{Slic3r::Geometry::chained_path_items(
|
|
|
|
[ map [ ($_->{outer} ? $_->{outer}[0] : $_->{hole}[0]), $_ ], @$polynodes ],
|
|
|
|
)};
|
|
|
|
|
|
|
|
my @polygons = ();
|
|
|
|
foreach my $polynode (@$polynodes) {
|
2013-05-11 19:05:29 +00:00
|
|
|
# traverse the next depth
|
2013-05-11 19:30:26 +00:00
|
|
|
push @polygons, traverse_pt($polynode->{children});
|
|
|
|
push @polygons, $polynode->{outer} // [ reverse @{$polynode->{hole}} ];
|
2013-05-11 07:24:48 +00:00
|
|
|
}
|
|
|
|
return @polygons;
|
|
|
|
}
|
|
|
|
|
2011-10-10 15:27:00 +00:00
|
|
|
1;
|