mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-29 11:41:20 -06:00
Initial import
This commit is contained in:
commit
55a523e1fa
12 changed files with 891 additions and 0 deletions
64
lib/Slic3r/Polyline.pm
Normal file
64
lib/Slic3r/Polyline.pm
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package Slic3r::Polyline;
|
||||
use Moose;
|
||||
|
||||
has 'lines' => (
|
||||
traits => ['Array'],
|
||||
is => 'rw',
|
||||
isa => 'ArrayRef[Slic3r::Line]',
|
||||
default => sub { [] },
|
||||
handles => {
|
||||
add_line => 'push',
|
||||
},
|
||||
);
|
||||
|
||||
after 'add_line' => sub {
|
||||
my $self = shift;
|
||||
|
||||
# add a weak reference to this polyline in line objects
|
||||
# (avoid circular refs)
|
||||
$self->lines->[-1]->polyline($self);
|
||||
};
|
||||
|
||||
sub BUILD {
|
||||
my $self = shift;
|
||||
$_->polyline($self) for @{ $self->lines };
|
||||
}
|
||||
|
||||
sub id {
|
||||
my $self = shift;
|
||||
return join '-', map($_->id, $self->points);
|
||||
}
|
||||
|
||||
sub new_from_points {
|
||||
my $class = shift;
|
||||
my (@points) = @_;
|
||||
|
||||
# we accept Point objects or arrayrefs with point coordinates
|
||||
@points = map {
|
||||
ref $_ eq 'ARRAY'
|
||||
? Slic3r::Point->new('x' => $_->[0], 'y' => $_->[1])
|
||||
: $_
|
||||
} @points;
|
||||
|
||||
my $polyline = __PACKAGE__->new;
|
||||
my $previous_point;
|
||||
$previous_point = $points[-1] if $class eq 'Slic3r::Polyline::Closed';
|
||||
foreach my $point (@points) {
|
||||
if ($previous_point) {
|
||||
my $line = Slic3r::Line->new(a => $previous_point, b => $point);
|
||||
$polyline->add_line($line);
|
||||
}
|
||||
$previous_point = $point;
|
||||
}
|
||||
|
||||
return $polyline;
|
||||
}
|
||||
|
||||
sub points {
|
||||
my $self = shift;
|
||||
my %points = ();
|
||||
$points{$_} = $_ for map $_->points, @{ $self->lines };
|
||||
return values %points;
|
||||
}
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue