Ported point_line_distance() and removed same_point()
This commit is contained in:
parent
09be25a156
commit
c133a33ed2
6 changed files with 29 additions and 26 deletions
|
@ -187,7 +187,7 @@ sub _medial_axis_voronoi {
|
|||
# being longer than $width / 2
|
||||
$polygon = $polygon->subdivide($width/2);
|
||||
|
||||
push @points, map $_->pp, @$polygon;
|
||||
push @points, @{$polygon->pp};
|
||||
}
|
||||
$voronoi = Math::Geometry::Voronoi->new(points => \@points);
|
||||
}
|
||||
|
@ -200,10 +200,8 @@ sub _medial_axis_voronoi {
|
|||
# ignore lines going to infinite
|
||||
next if $edge->[1] == -1 || $edge->[2] == -1;
|
||||
|
||||
my ($a, $b);
|
||||
$a = Slic3r::Point->new(@{$vertices->[$edge->[1]]});
|
||||
$b = Slic3r::Point->new(@{$vertices->[$edge->[2]]});
|
||||
next if !$self->encloses_point_quick($a) || !$self->encloses_point_quick($b);
|
||||
next if !$self->encloses_point_quick(Slic3r::Point->new(@{$vertices->[$edge->[1]]}))
|
||||
|| !$self->encloses_point_quick(Slic3r::Point->new(@{$vertices->[$edge->[2]]}));
|
||||
|
||||
push @skeleton_lines, [$edge->[1], $edge->[2]];
|
||||
}
|
||||
|
@ -244,7 +242,7 @@ sub _medial_axis_voronoi {
|
|||
# cleanup
|
||||
$polyline = Slic3r::Geometry::douglas_peucker($polyline, $width / 7);
|
||||
|
||||
if (Slic3r::Geometry::same_point($polyline->[0], $polyline->[-1])) {
|
||||
if ($polyline->[0][X] == $polyline->[-1][X] && $polyline->[0][Y] == $polyline->[-1][Y]) {
|
||||
next if @$polyline == 2;
|
||||
push @result, Slic3r::Polygon->new(@$polyline[0..$#$polyline-1]);
|
||||
} else {
|
||||
|
|
|
@ -14,7 +14,7 @@ our @EXPORT_OK = qw(
|
|||
polygon_has_vertex can_connect_points deg2rad rad2deg
|
||||
rotate_points move_points clip_segment_polygon
|
||||
sum_vectors multiply_vector subtract_vectors dot perp polygon_points_visibility
|
||||
line_intersection bounding_box bounding_box_intersect same_point
|
||||
line_intersection bounding_box bounding_box_intersect
|
||||
angle3points three_points_aligned line_direction
|
||||
polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices
|
||||
polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges
|
||||
|
@ -107,29 +107,11 @@ sub points_coincide {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub same_point {
|
||||
my ($p1, $p2) = @_;
|
||||
return $p1->[X] == $p2->[X] && $p1->[Y] == $p2->[Y];
|
||||
}
|
||||
|
||||
sub distance_between_points {
|
||||
my ($p1, $p2) = @_;
|
||||
return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2);
|
||||
}
|
||||
|
||||
sub point_line_distance {
|
||||
my ($point, $line) = @_;
|
||||
return distance_between_points($point, $line->[A])
|
||||
if same_point($line->[A], $line->[B]);
|
||||
|
||||
my $n = ($line->[B][X] - $line->[A][X]) * ($line->[A][Y] - $point->[Y])
|
||||
- ($line->[A][X] - $point->[X]) * ($line->[B][Y] - $line->[A][Y]);
|
||||
|
||||
my $d = sqrt((($line->[B][X] - $line->[A][X]) ** 2) + (($line->[B][Y] - $line->[A][Y]) ** 2));
|
||||
|
||||
return abs($n) / $d;
|
||||
}
|
||||
|
||||
# this will check whether a point is in a polygon regardless of polygon orientation
|
||||
sub point_in_polygon {
|
||||
my ($point, $polygon) = @_;
|
||||
|
@ -795,7 +777,7 @@ sub douglas_peucker {
|
|||
my $dmax = 0;
|
||||
my $index = 0;
|
||||
for my $i (1..$#$points) {
|
||||
my $d = point_line_distance($points->[$i], [ $points->[0], $points->[-1] ]);
|
||||
my $d = $points->[$i]->distance_to(Slic3r::Line->new($points->[0], $points->[-1]));
|
||||
if ($d > $dmax) {
|
||||
$index = $i;
|
||||
$dmax = $d;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue