From da0e67a891c76b1eccd090e01089c52394fdbbab Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 7 Apr 2013 18:28:08 -0400 Subject: [PATCH] Only look up $point's X and Y once, rather than once on every pass through the loop. (Those lookups are expensive) --- lib/Slic3r/Geometry.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index c6744a200..d21cff330 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -243,8 +243,12 @@ sub nearest_point_index { my ($point, $points) = @_; my ($nearest_point_index, $distance) = (); + + my $point_x = $point->[X]; + my $point_y = $point->[Y]; + for my $i (0..$#$points) { - my $d = (($point->[X] - $points->[$i]->[X])**2) + (($point->[Y] - $points->[$i]->[Y])**2); + my $d = (($point_x - $points->[$i]->[X])**2) + (($point_y - $points->[$i]->[Y])**2); if (!defined $distance || $d < $distance) { $nearest_point_index = $i; $distance = $d;