mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-03 17:25:01 +08:00
Optimization: avoid calculating square roots if not needed
This commit is contained in:
parent
6cb891f2db
commit
ae201c8f41
@ -7,6 +7,7 @@ our @ISA = qw(Exporter);
|
|||||||
our @EXPORT_OK = qw(
|
our @EXPORT_OK = qw(
|
||||||
PI X Y Z A B X1 Y1 X2 Y2 MIN MAX epsilon slope line_atan lines_parallel
|
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
|
line_point_belongs_to_segment points_coincide distance_between_points
|
||||||
|
comparable_distance_between_points
|
||||||
line_length midpoint point_in_polygon point_in_segment segment_in_segment
|
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_is_on_left_of_segment polyline_lines polygon_lines nearest_point
|
||||||
point_along_segment polygon_segment_having_point polygon_has_subsegment
|
point_along_segment polygon_segment_having_point polygon_has_subsegment
|
||||||
@ -114,6 +115,11 @@ sub distance_between_points {
|
|||||||
return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2);
|
return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub comparable_distance_between_points {
|
||||||
|
my ($p1, $p2) = @_;
|
||||||
|
return (($p1->[X] - $p2->[X])**2) + (($p1->[Y] - $p2->[Y])**2);
|
||||||
|
}
|
||||||
|
|
||||||
sub point_line_distance {
|
sub point_line_distance {
|
||||||
my ($point, $line) = @_;
|
my ($point, $line) = @_;
|
||||||
return distance_between_points($point, $line->[A])
|
return distance_between_points($point, $line->[A])
|
||||||
@ -251,7 +257,7 @@ sub nearest_point_index {
|
|||||||
|
|
||||||
my ($nearest_point_index, $distance) = ();
|
my ($nearest_point_index, $distance) = ();
|
||||||
for my $i (0..$#$points) {
|
for my $i (0..$#$points) {
|
||||||
my $d = distance_between_points($point, $points->[$i]);
|
my $d = comparable_distance_between_points($point, $points->[$i]);
|
||||||
if (!defined $distance || $d < $distance) {
|
if (!defined $distance || $d < $distance) {
|
||||||
$nearest_point_index = $i;
|
$nearest_point_index = $i;
|
||||||
$distance = $d;
|
$distance = $d;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user