mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-18 19:12:17 +00:00
Ported Slic3r::Polyline::Collection
This commit is contained in:
@@ -96,9 +96,9 @@ sub fill_surface {
|
||||
|
||||
# connect paths
|
||||
{
|
||||
my $collection = Slic3r::Polyline::Collection->new(polylines => [@paths]);
|
||||
my $collection = Slic3r::Polyline::Collection->new(@paths);
|
||||
@paths = ();
|
||||
foreach my $path ($collection->chained_path) {
|
||||
foreach my $path (@{$collection->chained_path(0)}) {
|
||||
if (@paths) {
|
||||
# distance between first point of this path and last point of last path
|
||||
my $distance = $paths[-1]->last_point->distance_to($path->first_point);
|
||||
|
||||
@@ -66,9 +66,7 @@ sub fill_surface {
|
||||
# connect lines
|
||||
unless ($params{dont_connect}) {
|
||||
my ($expolygon_off) = @{$expolygon->offset_ex(scale $params{flow_spacing}/2)};
|
||||
my $collection = Slic3r::Polyline::Collection->new(
|
||||
polylines => [ @polylines ],
|
||||
);
|
||||
my $collection = Slic3r::Polyline::Collection->new(@polylines);
|
||||
@polylines = ();
|
||||
|
||||
my $tolerance = 10 * scaled_epsilon;
|
||||
@@ -80,7 +78,7 @@ sub fill_surface {
|
||||
}
|
||||
: sub { $_[X] <= $diagonal_distance && $_[Y] <= $diagonal_distance };
|
||||
|
||||
foreach my $polyline ($collection->chained_path) {
|
||||
foreach my $polyline (@{$collection->chained_path(0)}) {
|
||||
if (@polylines) {
|
||||
my $first_point = $polyline->first_point;
|
||||
my $last_point = $polylines[-1]->last_point;
|
||||
|
||||
@@ -163,38 +163,4 @@ sub regular_points {
|
||||
return @points;
|
||||
}
|
||||
|
||||
package Slic3r::Polyline::Collection;
|
||||
use Moo;
|
||||
|
||||
has 'polylines' => (is => 'ro', default => sub { [] });
|
||||
|
||||
# Note that our polylines will be reversed in place when necessary.
|
||||
sub chained_path {
|
||||
my $self = shift;
|
||||
my ($start_near, $no_reverse) = @_;
|
||||
|
||||
my @my_paths = @{$self->polylines};
|
||||
|
||||
my @paths = ();
|
||||
my $start_at;
|
||||
my $endpoints = $no_reverse
|
||||
? [ map { @$_[0,0] } @my_paths ]
|
||||
: [ map { @$_[0,-1] } @my_paths ];
|
||||
while (@my_paths) {
|
||||
# find nearest point
|
||||
my $start_index = defined $start_near
|
||||
? $start_near->nearest_point_index($endpoints)
|
||||
: 0;
|
||||
|
||||
my $path_index = int($start_index/2);
|
||||
if ($start_index % 2 && !$no_reverse) { # index is end so reverse to make it the start
|
||||
$my_paths[$path_index]->reverse;
|
||||
}
|
||||
push @paths, splice @my_paths, $path_index, 1;
|
||||
splice @$endpoints, $path_index*2, 2;
|
||||
$start_near = $paths[-1]->last_point;
|
||||
}
|
||||
return @paths;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user