Manage flattened endpoint list rather than creating it at every iteration.

Gives an 8% speedup on simcop2387's coaster for me.
This commit is contained in:
Mark Hindess 2012-06-19 17:59:22 +01:00
parent a578af9d28
commit 62eb41b967

View file

@ -28,9 +28,9 @@ sub shortest_path {
$_->deserialize for @my_paths; $_->deserialize for @my_paths;
my @paths = (); my @paths = ();
my $start_at; my $start_at;
CYCLE: while (@my_paths) { my $endpoints = [ map $_->endpoints, @my_paths ];
CYCLE: while (@my_paths) {
# find nearest point # find nearest point
my $endpoints = [ map $_->endpoints, @my_paths ];
$start_at = $start_near $start_at = $start_near
? Slic3r::Point->new(Slic3r::Geometry::nearest_point($start_near, $endpoints)) ? Slic3r::Point->new(Slic3r::Geometry::nearest_point($start_near, $endpoints))
: $self->endpoints->[0]; : $self->endpoints->[0];
@ -45,6 +45,7 @@ sub shortest_path {
} else { } else {
next PATH; next PATH;
} }
splice @$endpoints, $i*2, 2;
$start_near = $paths[-1]->points->[-1]; $start_near = $paths[-1]->points->[-1];
next CYCLE; next CYCLE;
} }