Some cleanup for the Voronoi code

This commit is contained in:
Alessandro Ranellucci 2013-09-16 19:15:30 +02:00
parent a88ce0cb5e
commit 78167f56ee

View File

@ -105,29 +105,30 @@ sub medial_axis {
my $self = shift; my $self = shift;
my ($width) = @_; my ($width) = @_;
my @points = (); my $voronoi;
foreach my $polygon (@$self) { {
{ my @points = ();
my $p = $polygon->pp; foreach my $polygon (@$self) {
Slic3r::Geometry::polyline_remove_short_segments($p, $width / 2); {
$polygon = Slic3r::Polygon->new(@$p); my $p = $polygon->pp;
Slic3r::Geometry::polyline_remove_short_segments($p, $width / 2);
$polygon = Slic3r::Polygon->new(@$p);
}
# subdivide polygon segments so that we don't have anyone of them
# being longer than $width / 2
$polygon = $polygon->subdivide($width/2);
push @points, map $_->pp, @$polygon;
} }
$voronoi = Math::Geometry::Voronoi->new(points => \@points);
# subdivide polygon segments so that we don't have anyone of them
# being longer than $width / 2
$polygon = $polygon->subdivide($width/2);
push @points, map $_->clone, @$polygon;
} }
my $voronoi = Math::Geometry::Voronoi->new(points => [ map $_->pp, @points ]);
$voronoi->compute; $voronoi->compute;
my $vertices = $voronoi->vertices;
my @skeleton_lines = (); my @skeleton_lines = ();
foreach my $edge (@{ $voronoi->edges }) {
my $vertices = $voronoi->vertices;
my $edges = $voronoi->edges;
foreach my $edge (@$edges) {
# ignore lines going to infinite # ignore lines going to infinite
next if $edge->[1] == -1 || $edge->[2] == -1; next if $edge->[1] == -1 || $edge->[2] == -1;