mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-18 20:28:08 -06:00
Implement nearest point index and split at index to avoid search for point.
This commit is contained in:
parent
35fda7de23
commit
35ecd65e77
4 changed files with 31 additions and 16 deletions
|
@ -5,7 +5,7 @@ use Moo;
|
|||
has 'polygon' => (
|
||||
is => 'rw',
|
||||
required => 1,
|
||||
handles => [qw(is_printable nearest_point_to reverse)],
|
||||
handles => [qw(is_printable nearest_point_index_to reverse)],
|
||||
);
|
||||
|
||||
has 'flow_spacing' => (is => 'rw');
|
||||
|
@ -29,6 +29,23 @@ sub shortest_path {
|
|||
return $self;
|
||||
}
|
||||
|
||||
sub split_at_index {
|
||||
my $self = shift;
|
||||
my ($index) = @_;
|
||||
|
||||
$self->deserialize;
|
||||
|
||||
my @new_points = ();
|
||||
push @new_points, @{$self->polygon}[$index .. $#{$self->polygon}];
|
||||
push @new_points, @{$self->polygon}[0 .. $index];
|
||||
|
||||
return Slic3r::ExtrusionPath->new(
|
||||
polyline => Slic3r::Polyline->new(\@new_points),
|
||||
role => $self->role,
|
||||
flow_spacing => $self->flow_spacing,
|
||||
);
|
||||
}
|
||||
|
||||
sub split_at {
|
||||
my $self = shift;
|
||||
my ($point) = @_;
|
||||
|
@ -47,21 +64,12 @@ sub split_at {
|
|||
}
|
||||
die "Point not found" if $i == -1;
|
||||
|
||||
my @new_points = ();
|
||||
push @new_points, @{$self->polygon}[$i .. $#{$self->polygon}];
|
||||
push @new_points, @{$self->polygon}[0 .. $i];
|
||||
|
||||
return Slic3r::ExtrusionPath->new(
|
||||
polyline => Slic3r::Polyline->new(\@new_points),
|
||||
role => $self->role,
|
||||
flow_spacing => $self->flow_spacing,
|
||||
);
|
||||
return $self->split_at_index($i);
|
||||
}
|
||||
|
||||
sub split_at_first_point {
|
||||
my $self = shift;
|
||||
$self->deserialize;
|
||||
return $self->split_at($self->polygon->[0]);
|
||||
return $self->split_at_index(0);
|
||||
}
|
||||
|
||||
# although a loop doesn't have endpoints, this method is provided to allow
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue