PrusaSlicer-NonPlainar/lib/Slic3r/Geometry/Clipper.pm

34 lines
992 B
Perl
Raw Normal View History

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
diff_ex diff union_ex intersection_ex xor_ex JT_ROUND JT_MITER
JT_SQUARE is_counter_clockwise union_pt offset2 offset2_ex traverse_pt
intersection union CLIPPER_OFFSET_SCALE);
2011-10-10 15:27:00 +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-11-24 12:08:13 +00:00
no warnings 'recursion';
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;