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
|
2013-09-06 17:43:40 +02:00
|
|
|
diff_ex diff union_ex intersection_ex xor_ex JT_ROUND JT_MITER
|
2013-05-31 14:30:07 +02:00
|
|
|
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
|
|
|
|
2011-12-02 23:35:39 +01: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;
|