You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
use v5.36;
|
|
use rlib '.';
|
|
|
|
use Carp;
|
|
use Data::Dumper;
|
|
|
|
use feature "signatures";
|
|
no warnings "experimental::signatures";
|
|
|
|
my $coords_regex = qr/^\s*(-?\d+)\s*,\s*(-?\d+)\s*$/;
|
|
|
|
my %regions_to_tiles;
|
|
my %tiles_to_regions;
|
|
|
|
my $input_file = shift;
|
|
open (my $input_fh, $input_file);
|
|
|
|
my $output_file = shift // "$input_file.out";
|
|
open (my $output_fh, ">$output_file");
|
|
|
|
while (my $line = <$input_fh>)
|
|
{
|
|
my @fields = split '; ', $line;
|
|
print $output_fh (shift @fields) . "; "; #region name
|
|
print $output_fh (shift @fields) . "; "; #background colour
|
|
my @expanded_tile_specs = ();
|
|
foreach my $coords (@fields)
|
|
{
|
|
do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex;
|
|
my $nw_base = $1 * 3;
|
|
my $sw_base = $2 * 3;
|
|
|
|
my @new = ("$nw_base,$sw_base");
|
|
push @new, ($nw_base+1) . "," . ($sw_base);
|
|
push @new, ($nw_base-1) . "," . ($sw_base);
|
|
push @new, ($nw_base) . "," . ($sw_base+1);
|
|
push @new, ($nw_base) . "," . ($sw_base-1);
|
|
push @new, ($nw_base+1) . "," . ($sw_base-1);
|
|
push @new, ($nw_base-1) . "," . ($sw_base+1);
|
|
|
|
push @expanded_tile_specs, (join "; ", @new);
|
|
}
|
|
say $output_fh (join "; ", @expanded_tile_specs);
|
|
}
|
|
|
|
close $input_fh;
|
|
close $output_fh;
|
|
|