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

33 lines
1 KiB
Perl
Raw Normal View History

2011-10-10 17:27:00 +02:00
package Slic3r::Geometry::Clipper;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
2013-08-26 17:58:37 +02: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
2013-11-21 14:15:38 +01:00
intersection intersection_pl diff_pl union CLIPPER_OFFSET_SCALE);
2011-10-10 17:27:00 +02:00
use Slic3r::Geometry qw(scale);
2013-11-23 21:47:33 +01:00
use Slic3r::Geometry qw(chained_path);
2011-10-10 17:27:00 +02:00
2013-05-11 09:24:48 +02:00
sub traverse_pt {
2013-05-11 21:30:26 +02:00
my ($polynodes) = @_;
2013-05-11 09:24:48 +02:00
# use a nearest neighbor search to order these children
2013-11-23 21:47:33 +01:00
# TODO: supply second argument to chained_path() too?
my @ordering_points = map { ($_->{outer} // $_->{hole})->first_point } @$polynodes;
my @nodes = @$polynodes[ @{chained_path(\@ordering_points)} ];
2013-05-11 09:24:48 +02:00
my @polygons = ();
foreach my $polynode (@$polynodes) {
2013-05-11 21:05:29 +02:00
# traverse the next depth
2013-05-11 21:30:26 +02:00
push @polygons, traverse_pt($polynode->{children});
push @polygons, $polynode->{outer} // [ reverse @{$polynode->{hole}} ];
2013-05-11 09:24:48 +02:00
}
return @polygons;
}
2011-10-10 17:27:00 +02:00
1;