mirror of
https://github.com/FULU-Foundation/OrcaSlicer-bambulab.git
synced 2026-05-14 13:02:39 -07:00
Only look up $point's X and Y once, rather than once on every pass through the loop.
(Those lookups are expensive)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user