Inline comparable_distance_between_points

It was called on an incredibly hot codepath from a single place. At 12313276 calls
on my test .stl, the sub call overhead alone was a significant perf hit.
This commit is contained in:
Jesse Vincent 2013-04-07 18:13:40 -04:00
parent 060d2da7fe
commit 3e8c5804fe

View File

@ -7,7 +7,7 @@ our @ISA = qw(Exporter);
our @EXPORT_OK = qw(
PI X Y Z A B X1 Y1 X2 Y2 MIN MAX epsilon slope line_atan lines_parallel
line_point_belongs_to_segment points_coincide distance_between_points
comparable_distance_between_points chained_path_items chained_path_points
chained_path_items chained_path_points
line_length midpoint point_in_polygon point_in_segment segment_in_segment
point_is_on_left_of_segment polyline_lines polygon_lines nearest_point
point_along_segment polygon_segment_having_point polygon_has_subsegment
@ -115,10 +115,6 @@ sub distance_between_points {
return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2);
}
sub comparable_distance_between_points {
return (($_[0]->[X] - $_[1]->[X])**2) + (($_[0]->[Y] - $_[1]->[Y])**2);
}
sub point_line_distance {
my ($point, $line) = @_;
return distance_between_points($point, $line->[A])
@ -248,7 +244,7 @@ sub nearest_point_index {
my ($nearest_point_index, $distance) = ();
for my $i (0..$#$points) {
my $d = comparable_distance_between_points($point, $points->[$i]);
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;