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,6 +105,8 @@ sub medial_axis {
my $self = shift; my $self = shift;
my ($width) = @_; my ($width) = @_;
my $voronoi;
{
my @points = (); my @points = ();
foreach my $polygon (@$self) { foreach my $polygon (@$self) {
{ {
@ -117,17 +119,16 @@ sub medial_axis {
# being longer than $width / 2 # being longer than $width / 2
$polygon = $polygon->subdivide($width/2); $polygon = $polygon->subdivide($width/2);
push @points, map $_->clone, @$polygon; push @points, map $_->pp, @$polygon;
}
$voronoi = Math::Geometry::Voronoi->new(points => \@points);
} }
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;