Rename shortest_path to chained_path, which reflects its algorithm more correctly

This commit is contained in:
Alessandro Ranellucci 2013-02-05 17:27:45 +01:00
parent 11637d527a
commit 090e3b1fe3
10 changed files with 19 additions and 19 deletions

View file

@ -8,19 +8,19 @@ sub endpoints {
return [ map $_->endpoints, @{$self->paths} ];
}
sub shortest_path {
sub chained_path {
my $self = shift;
my ($start_near) = @_;
# make sure we pass the same path objects to the Collection constructor
# and the ->shortest_path() method because the latter will reverse the
# and the ->chained_path() method because the latter will reverse the
# paths in-place when needed and we need to return them that way
my @paths = map $_->unpack, @{$self->paths};
my $collection = Slic3r::Polyline::Collection->new(
polylines => [ map $_->polyline, @paths ],
);
return $collection->shortest_path($start_near, \@paths);
return $collection->chained_path($start_near, \@paths);
}
sub cleanup {

View file

@ -12,7 +12,7 @@ use Slic3r::Fill::OctagramSpiral;
use Slic3r::Fill::PlanePath;
use Slic3r::Fill::Rectilinear;
use Slic3r::ExtrusionPath ':roles';
use Slic3r::Geometry qw(X Y PI scale shortest_path);
use Slic3r::Geometry qw(X Y PI scale chained_path);
use Slic3r::Geometry::Clipper qw(union_ex diff_ex);
use Slic3r::Surface ':types';
@ -183,7 +183,7 @@ sub make_fill {
push @fills_ordering_points, map $_->unpack->points->[0], @{$layer->thin_fills};
# organize infill paths using a shortest path search
@fills = @{shortest_path([
@fills = @{chained_path([
map [ $fills_ordering_points[$_], $fills[$_] ], 0..$#fills,
])};

View file

@ -93,7 +93,7 @@ sub fill_surface {
)};
return { flow_spacing => $params{flow_spacing} },
Slic3r::Polyline::Collection->new(polylines => \@paths)->shortest_path;
Slic3r::Polyline::Collection->new(polylines => \@paths)->chained_path;
}
1;

View file

@ -73,7 +73,7 @@ sub fill_surface {
}
: sub { abs($_[X] - $distance_between_lines) <= $tolerance && $_[Y] <= $diagonal_distance };
foreach my $path ($collection->shortest_path) {
foreach my $path ($collection->chained_path) {
if (@paths) {
my @distance = map abs($path->[0][$_] - $paths[-1][-1][$_]), (X,Y);

View file

@ -270,7 +270,7 @@ sub travel_to {
my $mp = shift;
return join '',
map $self->G0($_->[B], undef, 0, $comment || ""),
$mp->shortest_path($self->last_pos, $point)->lines;
$mp->chained_path($self->last_pos, $point)->lines;
};
if ($self->new_object) {

View file

@ -217,7 +217,7 @@ sub find_node {
}
}
sub shortest_path {
sub chained_path {
my $self = shift;
my ($from, $to) = @_;

View file

@ -18,7 +18,7 @@ our @EXPORT_OK = qw(
longest_segment angle3points three_points_aligned line_direction
polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices
polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges
shortest_path collinear scale unscale merge_collinear_lines
chained_path collinear scale unscale merge_collinear_lines
rad2deg_dir bounding_box_center line_intersects_any douglas_peucker
polyline_remove_short_segments normal triangle_normal polygon_is_convex
scaled_epsilon bounding_box_3D size_3D size_2D
@ -803,7 +803,7 @@ sub polyline_remove_short_segments {
# item is the point to be used for the shortest path, and the second
# one is the value to be returned in output (if the second item
# is not provided, the point will be returned)
sub shortest_path {
sub chained_path {
my ($items, $start_near) = @_;
my %values = map +($_->[0] => $_->[1] || $_->[0]), @$items;

View file

@ -2,7 +2,7 @@ package Slic3r::Layer::Region;
use Moo;
use Slic3r::ExtrusionPath ':roles';
use Slic3r::Geometry qw(scale shortest_path);
use Slic3r::Geometry qw(scale chained_path);
use Slic3r::Geometry::Clipper qw(safety_offset union_ex diff_ex intersection_ex);
use Slic3r::Surface ':types';
@ -167,7 +167,7 @@ sub make_perimeters {
my @perimeters = (); # one item per depth; each item
# organize islands using a shortest path search
my @surfaces = @{shortest_path([
my @surfaces = @{chained_path([
map [ $_->contour->[0], $_ ], @{$self->slices},
])};
@ -326,7 +326,7 @@ sub make_perimeters {
my @hole_depths = map [ map $_->holes, @$_ ], @$island;
# organize the outermost hole loops using a shortest path search
@{$hole_depths[0]} = @{shortest_path([
@{$hole_depths[0]} = @{chained_path([
map [ $_->[0], $_ ], @{$hole_depths[0]},
])};
@ -391,7 +391,7 @@ sub make_perimeters {
flow_spacing => $self->perimeter_flow->spacing,
);
} @{ $self->thin_walls }
])->shortest_path;
])->chained_path;
}
sub _add_perimeter {

View file

@ -193,7 +193,7 @@ has 'polylines' => (is => 'ro', default => sub { [] });
# If the second argument is provided, this method will return its items sorted
# instead of returning the actual sorted polylines.
# Note that our polylines will be reversed in place when necessary.
sub shortest_path {
sub chained_path {
my $self = shift;
my ($start_near, $items) = @_;

View file

@ -821,13 +821,13 @@ sub write_gcode {
$gcode .= $gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]);
if ($layer->support_contact_fills) {
$gcode .= $gcodegen->extrude_path($_, 'support material contact area')
for $layer->support_contact_fills->shortest_path($gcodegen->last_pos);
for $layer->support_contact_fills->chained_path($gcodegen->last_pos);
}
$gcode .= $gcodegen->move_z($layer->print_z);
if ($layer->support_fills) {
$gcode .= $gcodegen->extrude_path($_, 'support material')
for $layer->support_fills->shortest_path($gcodegen->last_pos);
for $layer->support_fills->chained_path($gcodegen->last_pos);
}
}
@ -854,7 +854,7 @@ sub write_gcode {
for my $fill (@{ $layerm->fills }) {
if ($fill->isa('Slic3r::ExtrusionPath::Collection')) {
$gcode .= $gcodegen->extrude($_, 'fill')
for $fill->shortest_path($gcodegen->last_pos);
for $fill->chained_path($gcodegen->last_pos);
} else {
$gcode .= $gcodegen->extrude($fill, 'fill') ;
}