my @data = (
[
bless({'X' => '2289290.30567314', 'Y' => '507448.506452598'}, 'Point'),
bless({'X' => '2289282.72943502', 'Y' => '507410.155776398'}, 'Point'),
bless({'X' => '2289149', 'Y' => '507002.0625'}, 'Point'),
bless({'X' => '2289055.31527948', 'Y' => '506731.474946477'}, 'Point'),
],
[
bless({'X' => '2289563.40820205', 'Y' => '512818.142015762'}, 'Point'),
bless({'X' => '2289542.5', 'Y' => '512756.0625'}, 'Point'),
bless({'X' => '2289188.03442014', 'Y' => '510403.174475172'}, 'Point'),
],
[
bless({'X' => '2287498.5', 'Y' => '502968.75'}, 'Point'),
bless({'X' => '2287529.54227622', 'Y' => '502752.130034798'}, 'Point'),
bless({'X' => '2287571.41650288', 'Y' => '502527.884072168'}, 'Point'),
],
[
bless({'X' => '2288410.26157533', 'Y' => '505497.135963316'}, 'Point'),
bless({'X' => '2288373.62815415', 'Y' => '505449.841277223'}, 'Point'),
bless({'X' => '2287631.5', 'Y' => '503533.9375'}, 'Point'),
bless({'X' => '2287593', 'Y' => '503471'}, 'Point'),
],
[
bless({'X' => '2289188.03442014', 'Y' => '510403.174475172'}, 'Point'),
bless({'X' => '2289106.00673453', 'Y' => '509893.307668147'}, 'Point')
],
[
bless({'X' => '2288451.69937281', 'Y' => '505554.395479093'}, 'Point'),
bless({'X' => '2288410.26157533', 'Y' => '505497.135963316'}, 'Point')
],
[
bless({'X' => '2289106.00673453', 'Y' => '509893.307668147'}, 'Point'),
bless({'X' => '2289299.27685392', 'Y' => '507531.897507685'}, 'Point'),
bless({'X' => '2289290.30567314', 'Y' => '507448.506452598'}, 'Point'),
],
[
bless({'X' => '2287593', 'Y' => '503471'}, 'Point'),
bless({'X' => '2287498.5', 'Y' => '502968.75'}, 'Point'),
],
[
bless({'X' => '2288891.13335288', 'Y' => '506310.118972175'}, 'Point'),
bless({'X' => '2288451.69937281', 'Y' => '505554.395479093'}, 'Point'),
],
[
bless({'X' => '2289055.31527948', 'Y' => '506731.474946477'}, 'Point'),
bless({'X' => '2289012.5', 'Y' => '506607.8125'}, 'Point'),
bless({'X' => '2288907', 'Y' => '506360.3125'}, 'Point'),
bless({'X' => '2288891.13335288', 'Y' => '506310.118972175'}, 'Point'),
]
);
####
sub merge {
my @allparts = @_;
my @complete = @{shift(@allparts)};
ALLPARTS: while(@allparts) {
for(0 .. $#allparts) {
my @thispart = @{$allparts[$_]};
if($thispart[0] == $complete[$#complete]) {
shift(@thispart); # remove part, so we don't double points
@complete = (@complete,@thispart);
splice(@allparts,$_,1);
next ALLPARTS;
}
if($complete[0] == $thispart[$#thispart]) {
shift(@complete); # remove part
@complete = (@thispart,@complete);
splice(@allparts,$_,1);
next ALLPARTS;
}
}
die "Found pieces that don't fit!\n".Dumper(@allparts);
}
return @complete;
}
####
package Point;
use overload '==' => sub {
return ($_[0]->{X} == $_[1]->{X} && $_[0]->{Y} == $_[1]->{Y});
};