mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-12-05 16:51:07 -07:00
Ported Slic3r::Polyline::Collection
This commit is contained in:
parent
fb82de9aaf
commit
1cfdf7e955
12 changed files with 194 additions and 46 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue