Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Collection.pm « ExtrusionPath « Slic3r « lib - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a4358617e52680b246b09bc9df705f6b6267b4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package Slic3r::ExtrusionPath::Collection;
use Moo;

use XXX;

has 'paths' => (
    is      => 'rw',
    #isa     => 'ArrayRef[Slic3r::ExtrusionPath]',
    default => sub { [] },
);

sub add {
    my $self = shift;
    my ($path) = @_;
    
    push @{$self->paths}, $path;
}

sub endpoints {
    my $self = shift;
    return map $_->endpoints, @{$self->paths};
}

sub shortest_path {
    my $self = shift;
    my ($start_near) = @_;
    
    my @paths = ();
    my $start_at;
    CYCLE: while (@{$self->paths}) {
        # find nearest point
        $start_at = Slic3r::Point->new(Slic3r::Geometry::nearest_point($start_near, [ $self->endpoints ]));
        
        # loop through paths to find the one that starts or ends at the point found
        PATH: for (my $i = 0; $i <= $#{$self->paths}; $i++) {
            if ($start_at->id eq $self->paths->[$i]->points->[0]->id) {
                push @paths, splice @{$self->paths}, $i, 1;
            } elsif ($start_at->id eq $self->paths->[$i]->points->[-1]->id) {
                $self->paths->[$i]->reverse;
                push @paths, splice @{$self->paths}, $i, 1;
            } else {
                next PATH;
            }
            $start_near = $paths[-1]->points->[-1];
            next CYCLE;
        }
    }
    return @paths;
}

sub cleanup {
    my $self = shift;
    
    # split paths at angles that are too acute to be printed as they will cause blobs
    @{$self->paths} = map $_->split_at_acute_angles, @{$self->paths};
}

sub detect_arcs {
    my $self = shift;
    @{$self->paths} = map $_->detect_arcs, @{$self->paths};
}

1;