Algorithm-ClusterPoints

 view release on metacpan or  search on metacpan

example/cluster.pl  view on Meta::CPAN


use strict;
use warnings;

use Algorithm::ClusterPoints;

use Data::Dumper;

my $clp = Algorithm::ClusterPoints->new(radius => 0.1, min_size => 2, ordered => 1);

while (<DATA>) {
    next if /^\s*(?:#.*)?$/;
    chomp;
    my ($x, $y) = split;
    $clp->add_point($x, $y);
}

my @clusters_ix = $clp->clusters_ix;

print Data::Dumper->Dump([\@clusters_ix], ['clusters_ix']);

example/cluster.pl  view on Meta::CPAN

                     my ($x, $y) = $clp->point_coords($_);
                     "($_: $x, $y)"
                 } @{$clusters_ix[$i]}
               ), "\n"
         );
}

my @clusters = $clp->clusters;
print Data::Dumper->Dump([\@clusters], ['clusters']);

__DATA__
0.43 0.62
0.50 0.65
0.49 0.32
0.95 0.20
0.09 0.09
0.61 0.55
0.72 0.42
0.83 0.11
0.62 0.71
0.52 0.97



( run in 0.485 second using v1.01-cache-2.11-cpan-140bd7fdf52 )