Compare commits

..

No commits in common. '2469ca32cc21613f5fa9ada89adb3e48912f8d56' and 'a68f9c7785a92f94a35e5c85413e7301671c7f87' have entirely different histories.

  1. 79
      HexGrid.pm
  2. 99
      HexGrid/Path.pm
  3. 5
      HexGrid/Tile.pm
  4. 22
      svg/hex-lines_equilateral.svg
  5. 48
      tests/paths.pl
  6. 329
      tests/paths.svg
  7. 10
      wiki-map.pl

@ -8,7 +8,6 @@ use SVG;
use Hash::Merge qw(merge); use Hash::Merge qw(merge);
use HexGrid::Tile; use HexGrid::Tile;
use HexGrid::Region; use HexGrid::Region;
use HexGrid::Path;
use HexGrid::PopUp; use HexGrid::PopUp;
use HexGrid::Image; use HexGrid::Image;
use Carp; use Carp;
@ -20,7 +19,6 @@ no warnings "experimental::signatures";
my $DEBUG = 0; my $DEBUG = 0;
has regions => (is => 'rw', default => sub { {} }); has regions => (is => 'rw', default => sub { {} });
has paths => (is => 'rw', default => sub { {} });
has images => (is => 'rw', default => sub{ {} }); has images => (is => 'rw', default => sub{ {} });
has sideLength => (is => 'rw', default => 100); has sideLength => (is => 'rw', default => 100);
@ -35,18 +33,6 @@ has embed_images => (is => 'rw', default => 1);
sub tile_width($this) { 2 * $this->{sideLength} } sub tile_width($this) { 2 * $this->{sideLength} }
sub tile_height($this) { sqrt(3) * $this->{sideLength} } sub tile_height($this) { sqrt(3) * $this->{sideLength} }
# Enumeration of each direction; opposite directions are negated
%HexGrid::DIR =
(
nw => 1,
sw => 2,
s => 3,
se => -1,
ne => -2,
n => -3
);
#Hash::Merge::merge defaults to Left Precedence, i.e. merge first arg onto second arg #Hash::Merge::merge defaults to Left Precedence, i.e. merge first arg onto second arg
sub add_region($this, $region) { $this->{regions}{$region->{name}} = $region; } sub add_region($this, $region) { $this->{regions}{$region->{name}} = $region; }
@ -56,20 +42,6 @@ sub make_region($this, $name, %defaults)
$this->add_region(HexGrid::Region->new(name => $name, defaults => $tile_defaults)); $this->add_region(HexGrid::Region->new(name => $name, defaults => $tile_defaults));
} }
sub add_path($this, $path) { $this->{paths}{$path->id} = $path; }
sub make_path_from($this, $id, $tile_coords, %rest)
{
my $path = HexGrid::Path->new
(
id => $id, %rest
);
foreach my $pair (@$tile_coords)
{
push @{$path->tiles}, $this->get_tile_at($pair->[0], $pair->[1]);
}
$this->add_path($path);
}
sub add_image($this, $name, $source) sub add_image($this, $name, $source)
{ {
# Height/width of the image within the symbol doesn't matter # Height/width of the image within the symbol doesn't matter
@ -178,8 +150,7 @@ sub render($this)
id => "${key}_symbol", id => "${key}_symbol",
viewBox => "0 0 $image->{width} $image->{height}", viewBox => "0 0 $image->{width} $image->{height}",
width => $image->{width}, width => $image->{width},
height => $image->{height} height => $image->{height});
);
$image->render($symbol); $image->render($symbol);
} }
@ -193,10 +164,6 @@ sub render($this)
$max_x = $m->{max_x} if $m->{max_x} > $max_x; $max_x = $m->{max_x} if $m->{max_x} > $max_x;
$max_y = $m->{max_y} if $m->{max_y} > $max_y; $max_y = $m->{max_y} if $m->{max_y} > $max_y;
} }
foreach my $path (keys %{$this->paths})
{
$this->{paths}{$path}->render($this, $svg);
}
foreach my $later (@$laters) foreach my $later (@$laters)
{ {
$later->($svg); $later->($svg);
@ -219,50 +186,6 @@ sub translate_coords($this, $nw, $sw)
1/2 * $this->tile_height * ($sw - $nw)); 1/2 * $this->tile_height * ($sw - $nw));
} }
sub coords_of_centre($this, $nw, $sw)
{
my ($x_root, $y_root) = $this->translate_coords($nw, $sw);
return ($x_root + $this->tile_width / 2, $y_root + $this->tile_height / 2);
}
sub coords_of_edge($this, $nw, $sw, $dir)
{
my ($x_translate, $y_translate);
if($dir == $HexGrid::DIR{nw})
{
$x_translate = $this->tile_width / 8;
$y_translate = $this->tile_height / 4;
}
elsif($dir == $HexGrid::DIR{sw})
{
$x_translate = $this->tile_width / 8;
$y_translate = $this->tile_height * 3 / 4;
}
elsif($dir == $HexGrid::DIR{s})
{
$x_translate = $this->tile_width / 2;
$y_translate = $this->tile_height;
}
elsif($dir == $HexGrid::DIR{se})
{
$x_translate = $this->tile_width * 7 / 8;
$y_translate = $this->tile_height * 3 / 4;
}
elsif($dir == $HexGrid::DIR{ne})
{
$x_translate = $this->tile_width * 7 / 8;
$y_translate = $this->tile_height / 4;
}
elsif($dir == $HexGrid::DIR{n})
{
$x_translate = $this->tile_width / 2;
$y_translate = 0;
}
my ($x_root, $y_root) = $this->translate_coords($nw, $sw);
return ($x_root + $x_translate, $y_root + $y_translate);
}
sub to_id($string) { $string =~ s/\W/-/g && return $string; } sub to_id($string) { $string =~ s/\W/-/g && return $string; }
sub DEBUG { $DEBUG = 1; } sub DEBUG { $DEBUG = 1; }

@ -1,99 +0,0 @@
package HexGrid::Path;
use v5.30;
use Moo;
use MooX::Aliases;
use Data::Dumper;
use feature "signatures";
no warnings "experimental::signatures";
has tiles => (is => 'rw', default => sub { [] });
has id => (is => 'ro', required => 1);
has style => (is => 'rw', default => sub { {} });
has colour => (is => 'rw', alias => 'color', default => 'blue');
has css_class => (is => 'rw');
# Class
my $DEFAULT_WIDTH = 5;
sub get_edge_direction($tile1, $tile2)
{
my $nw_diff = $tile2->nw - $tile1->nw;
my $sw_diff = $tile2->sw - $tile1->sw;
return $HexGrid::DIR{nw} if $nw_diff == 1 && $sw_diff == 0;
return $HexGrid::DIR{sw} if $nw_diff == 0 && $sw_diff == 1;
return $HexGrid::DIR{s} if $nw_diff == -1 && $sw_diff == 1;
return $HexGrid::DIR{se} if $nw_diff == -1 && $sw_diff == 0;
return $HexGrid::DIR{ne} if $nw_diff == 0 && $sw_diff == -1;
return $HexGrid::DIR{n} if $nw_diff == 1 && $sw_diff == -1;
#TODO: should die here, to be caught/bubbled in render...
}
sub curve_path($x1, $y1, $qx, $qy, $x2, $y2)
{
return "M $x1,$y1 Q $qx,$qy $x2,$y2";
}
# Instance
sub render($this, $grid, $svg)
{
return unless @{$this->tiles};
my $g = $svg->g(id => $this->id, class => $this->css_class);
my ($x1, $x2, $y1, $y2);
my $current_tile = shift @{$this->tiles};
unless (@{$this->tiles})
{
my ($cx, $cy) = $grid->coords_of_centre($current_tile->nw, $current_tile->sw);
$g->circle(cx => $cx, cy => $cy,
r => $this->{style}{'stroke-width'} // $DEFAULT_WIDTH,
fill => $this->colour, style => $this->style, class => $this->css_class);
return;
}
my $previous_tile = $current_tile;
$current_tile = shift @{$this->tiles};
my $next_edge = get_edge_direction($previous_tile, $current_tile);
($x1, $y1) = $grid->coords_of_centre($previous_tile->nw, $previous_tile->sw);
($x2, $y2) = $grid->coords_of_edge($previous_tile->nw, $previous_tile->sw, $next_edge);
$g->line(x1 => $x1, y1 => $y1, x2 => $x2, y2 => $y2,
stroke => $this->colour, style => $this->style, class => $this->css_class);
my $previous_edge; # not defined yet
my $next_tile; # not defined yet
while(@{$this->tiles})
{
$next_tile = shift @{$this->tiles};
$previous_edge = -$next_edge;
$next_edge = get_edge_direction($current_tile, $next_tile);
($x1,$y1) = $grid->coords_of_edge($current_tile->nw, $current_tile->sw, $previous_edge);
my ($qx,$qy) = $grid->coords_of_centre($current_tile->nw, $current_tile->sw);
($x2,$y2) = $grid->coords_of_edge($current_tile->nw, $current_tile->sw, $next_edge);
# TODO: Draw curve from $current_tile:$previous_edge to $current_tile:$next_edge
# with $current_tile centre as the control point
$g->path(d => curve_path($x1,$y1, $qx,$qy, $x2,$y2),
stroke => $this->colour, style => $this->style, class => $this->css_class
);
$previous_tile = $current_tile;
$current_tile = $next_tile;
}
# When loop is done (or if it was empty) $current_tile is the last tile
# $next_edge will be the last used edge, so use it's opposite for the source of last line
($x1, $y1) = $grid->coords_of_edge($current_tile->nw, $current_tile->sw, -$next_edge);
($x2, $y2) = $grid->coords_of_centre($current_tile->nw, $current_tile->sw);
$g->line(x1 => $x1, y1 => $y1, x2 => $x2, y2 => $y2,
stroke => $this->colour, style => $this->style, class => $this->css_class);
}
1;

@ -15,7 +15,7 @@ no warnings "experimental::signatures";
has nw => (is => 'ro', required => 1); has nw => (is => 'ro', required => 1);
has sw => (is => 'ro', required => 1); has sw => (is => 'ro', required => 1);
has style => (is => 'rw', default => sub { {} }); has style => (is => 'rw');
has colour => (is => 'rw', alias => 'color'); has colour => (is => 'rw', alias => 'color');
has opacity => (is => 'rw'); has opacity => (is => 'rw');
has images => (is => 'rw', alias => [qw(image background backgrounds)]); has images => (is => 'rw', alias => [qw(image background backgrounds)]);
@ -42,7 +42,6 @@ sub hex_path($w, $h)
{ {
# More readable for me at least as a sequence of points than as two sequences # More readable for me at least as a sequence of points than as two sequences
my @points = ([0, $h/2], [$w*1/4, 0], [$w*3/4, 0], [$w, $h/2], [$w*3/4, $h], [$w*1/4, $h]); my @points = ([0, $h/2], [$w*1/4, 0], [$w*3/4, 0], [$w, $h/2], [$w*3/4, $h], [$w*1/4, $h]);
# Join pairs with a comma, and sequence with spaces
return join " ", (map {join ",", @$_} @points); return join " ", (map {join ",", @$_} @points);
} }
@ -104,7 +103,7 @@ sub render($this, $container, $width, $height, $laters = undef)
); );
# $g->{onclick} = "say('($this->{nw},$this->{sw})')"; # $g->{onclick} = "say('($this->{nw},$this->{sw})')";
my $hex = $g->polygon(points => hex_path($width, $height), my $hex = $g->polygon(points => hex_path($width, $height),
id => "$this->{nw}_$this->{sw}_inner_hex", style => $this->style); id => "$this->{nw}_$this->{sw}_inner_hex", style => $this->{style} || {});
my $clipPath = $g->clipPath(id => "$this->{nw}_$this->{sw}_clip"); my $clipPath = $g->clipPath(id => "$this->{nw}_$this->{sw}_clip");
$clipPath->use(href => "#$hex->{id}"); $clipPath->use(href => "#$hex->{id}");

@ -1,22 +0,0 @@
<svg version="1.1" width="173.2" height="200" xmlns="http://www.w3.org/2000/svg">
<style>
.link { stroke-width: 4px; fill: transparent; }
</style>
<!-- 0,s √3*1/4,0 √3*3/4,0 √3,s √3*3/4,2s √3*1/4,2s-->
<polygon points="0,100 43.3,0 129.9,0 173.2,100 129.9,200 43.3,200"/>
<circle cx="86.6" cy="100" r="4" fill="white" stroke="white" />
<!-- 1/8*√3*s s/2-->
<circle cx="21.7" cy="50" r="4" fill="white " />
<circle cx="86.6" cy="0" r="4" fill="lime " />
<circle cx="151.6" cy="50" r="4" fill="yellow " />
<circle cx="151.6" cy="150" r="4" fill="red " />
<circle cx="86.6" cy="200" r="4" fill="magenta" />
<circle cx="21.7" cy="150" r="4" fill="cyan " />
<path d="M 21.75,50 Q 86.6,100 86.6,0 " stroke="lime " class="link" />
<path d="M 21.75,50 Q 86.6,100 151.6,50 " stroke="yellow " class="link" />
<path d="M 21.75,50 Q 86.6,100 151.6,150" stroke="red " class="link" />
<path d="M 21.75,50 Q 86.6,100 86.6,200 " stroke="magenta" class="link" />
<path d="M 21.75,50 Q 86.6,100 21.7,150 " stroke="cyan " class="link" />
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

@ -1,48 +0,0 @@
use v5.36;
use rlib '..';
use HexGrid;
use HexGrid::Path;
use Carp;
use Data::Dumper;
my $MAP_SIZE = 3;
my $grid = HexGrid->new(defaults => {
style => { 'stroke-width' => 1, stroke => 'white' },
show_coords => 0});
my $region = $grid->make_region("TEST");
for (my $nw=-$MAP_SIZE; $nw <= $MAP_SIZE; $nw++)
{
for (my $sw=-$MAP_SIZE; $sw <= $MAP_SIZE; $sw++)
{
$region->make_tile_at($nw, $sw);
}
}
$grid->make_path_from('test-id',
[[0,0], [1,0], [1,1], [2,0], [2,-1], [2,-2], [1,-2], [1,-1], [2,-1], [3,-1]],
colour => 'lime', css_class => 'path', style => { 'stroke-width' => 5 }
);
$grid->make_path_from('point-id', [[-1,1]],
colour => 'cyan', css_class => 'path', style => { 'stroke-width' => 5 }
);
$grid->make_path_from('loop-id',
[[-2,0], [-1,0], [-1,-1], [-2,-1], [-2,0]],
colour => 'red', css_class => 'path', style => { 'stroke-width' => 5 }
);
# say "@{[$grid->coords_of_centre(-2,0)]}";
# say "@{[$grid->coords_of_edge(-2,0,$HexGrid::DIR{nw})]}";
# say "@{[$grid->coords_of_edge(-2,0,$HexGrid::DIR{sw})]}";
# say "@{[$grid->coords_of_edge(-2,0,$HexGrid::DIR{s})]}" ;
# say "@{[$grid->coords_of_edge(-2,0,$HexGrid::DIR{se})]}";
# say "@{[$grid->coords_of_edge(-2,0,$HexGrid::DIR{ne})]}";
# say "@{[$grid->coords_of_edge(-2,0,$HexGrid::DIR{n})]}" ;
# say Dumper($grid);
say $grid->render;

@ -1,329 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg height="1000" id="grid-root" preserveAspectRatio="xMidYMid" version="1.2" viewBox="-900 -519.615242270663 2000 1212.43556529821" width="1000" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<style>.pin-popup { visibility: hidden; }</style>
<defs />
<g id="">
<g class="" id="1_-2_tile" transform="translate(150, -259.807621135332)">
<polygon id="1_-2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="1_-2_clip">
<use href="#1_-2_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-450, 86.6025403784439)">
<polygon id="1_2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="1_2_clip">
<use href="#1_2_inner_hex" />
</clipPath>
</g>
<g class="" id="1_-3_tile" transform="translate(300, -346.410161513775)">
<polygon id="1_-3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="1_-3_clip">
<use href="#1_-3_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-300, 0)">
<polygon id="1_1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="1_1_clip">
<use href="#1_1_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-150, -86.6025403784439)">
<polygon id="1_0_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="1_0_clip">
<use href="#1_0_inner_hex" />
</clipPath>
</g>
<g class="" id="1_-1_tile" transform="translate(0, -173.205080756888)">
<polygon id="1_-1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="1_-1_clip">
<use href="#1_-1_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-600, 173.205080756888)">
<polygon id="1_3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="1_3_clip">
<use href="#1_3_inner_hex" />
</clipPath>
</g>
<g class="" id="0_-1_tile" transform="translate(150, -86.6025403784439)">
<polygon id="0_-1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="0_-1_clip">
<use href="#0_-1_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-450, 259.807621135332)">
<polygon id="0_3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="0_3_clip">
<use href="#0_3_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-150, 86.6025403784439)">
<polygon id="0_1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="0_1_clip">
<use href="#0_1_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(0, 0)">
<polygon id="0_0_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="0_0_clip">
<use href="#0_0_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-300, 173.205080756888)">
<polygon id="0_2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="0_2_clip">
<use href="#0_2_inner_hex" />
</clipPath>
</g>
<g class="" id="0_-3_tile" transform="translate(450, -259.807621135332)">
<polygon id="0_-3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="0_-3_clip">
<use href="#0_-3_inner_hex" />
</clipPath>
</g>
<g class="" id="0_-2_tile" transform="translate(300, -173.205080756888)">
<polygon id="0_-2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="0_-2_clip">
<use href="#0_-2_inner_hex" />
</clipPath>
</g>
<g class="" id="-1_0_tile" transform="translate(150, 86.6025403784439)">
<polygon id="-1_0_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-1_0_clip">
<use href="#-1_0_inner_hex" />
</clipPath>
</g>
<g class="" id="-1_1_tile" transform="translate(0, 173.205080756888)">
<polygon id="-1_1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-1_1_clip">
<use href="#-1_1_inner_hex" />
</clipPath>
</g>
<g class="" id="-1_-1_tile" transform="translate(300, 0)">
<polygon id="-1_-1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-1_-1_clip">
<use href="#-1_-1_inner_hex" />
</clipPath>
</g>
<g class="" id="-1_3_tile" transform="translate(-300, 346.410161513775)">
<polygon id="-1_3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-1_3_clip">
<use href="#-1_3_inner_hex" />
</clipPath>
</g>
<g class="" id="-1_-2_tile" transform="translate(450, -86.6025403784439)">
<polygon id="-1_-2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-1_-2_clip">
<use href="#-1_-2_inner_hex" />
</clipPath>
</g>
<g class="" id="-1_2_tile" transform="translate(-150, 259.807621135332)">
<polygon id="-1_2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-1_2_clip">
<use href="#-1_2_inner_hex" />
</clipPath>
</g>
<g class="" id="-1_-3_tile" transform="translate(600, -173.205080756888)">
<polygon id="-1_-3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-1_-3_clip">
<use href="#-1_-3_inner_hex" />
</clipPath>
</g>
<g class="" id="3_-2_tile" transform="translate(-150, -433.012701892219)">
<polygon id="3_-2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="3_-2_clip">
<use href="#3_-2_inner_hex" />
</clipPath>
</g>
<g class="" id="3_-3_tile" transform="translate(0, -519.615242270663)">
<polygon id="3_-3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="3_-3_clip">
<use href="#3_-3_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-750, -86.6025403784439)">
<polygon id="3_2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="3_2_clip">
<use href="#3_2_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-450, -259.807621135332)">
<polygon id="3_0_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="3_0_clip">
<use href="#3_0_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-600, -173.205080756888)">
<polygon id="3_1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="3_1_clip">
<use href="#3_1_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-900, 0)">
<polygon id="3_3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="3_3_clip">
<use href="#3_3_inner_hex" />
</clipPath>
</g>
<g class="" id="3_-1_tile" transform="translate(-300, -346.410161513775)">
<polygon id="3_-1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="3_-1_clip">
<use href="#3_-1_inner_hex" />
</clipPath>
</g>
<g class="" id="-2_-2_tile" transform="translate(600, 0)">
<polygon id="-2_-2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-2_-2_clip">
<use href="#-2_-2_inner_hex" />
</clipPath>
</g>
<g class="" id="-2_2_tile" transform="translate(0, 346.410161513775)">
<polygon id="-2_2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-2_2_clip">
<use href="#-2_2_inner_hex" />
</clipPath>
</g>
<g class="" id="-2_-3_tile" transform="translate(750, -86.6025403784439)">
<polygon id="-2_-3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-2_-3_clip">
<use href="#-2_-3_inner_hex" />
</clipPath>
</g>
<g class="" id="-2_1_tile" transform="translate(150, 259.807621135332)">
<polygon id="-2_1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-2_1_clip">
<use href="#-2_1_inner_hex" />
</clipPath>
</g>
<g class="" id="-2_0_tile" transform="translate(300, 173.205080756888)">
<polygon id="-2_0_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-2_0_clip">
<use href="#-2_0_inner_hex" />
</clipPath>
</g>
<g class="" id="-2_-1_tile" transform="translate(450, 86.6025403784439)">
<polygon id="-2_-1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-2_-1_clip">
<use href="#-2_-1_inner_hex" />
</clipPath>
</g>
<g class="" id="-2_3_tile" transform="translate(-150, 433.012701892219)">
<polygon id="-2_3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-2_3_clip">
<use href="#-2_3_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-300, -173.205080756888)">
<polygon id="2_0_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="2_0_clip">
<use href="#2_0_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-450, -86.6025403784439)">
<polygon id="2_1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="2_1_clip">
<use href="#2_1_inner_hex" />
</clipPath>
</g>
<g class="" id="2_-1_tile" transform="translate(-150, -259.807621135332)">
<polygon id="2_-1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="2_-1_clip">
<use href="#2_-1_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-750, 86.6025403784439)">
<polygon id="2_3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="2_3_clip">
<use href="#2_3_inner_hex" />
</clipPath>
</g>
<g class="" id="2_-2_tile" transform="translate(0, -346.410161513775)">
<polygon id="2_-2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="2_-2_clip">
<use href="#2_-2_inner_hex" />
</clipPath>
</g>
<g class="" id="" transform="translate(-600, 0)">
<polygon id="2_2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="2_2_clip">
<use href="#2_2_inner_hex" />
</clipPath>
</g>
<g class="" id="2_-3_tile" transform="translate(150, -433.012701892219)">
<polygon id="2_-3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="2_-3_clip">
<use href="#2_-3_inner_hex" />
</clipPath>
</g>
<g class="" id="-3_0_tile" transform="translate(450, 259.807621135332)">
<polygon id="-3_0_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-3_0_clip">
<use href="#-3_0_inner_hex" />
</clipPath>
</g>
<g class="" id="-3_1_tile" transform="translate(300, 346.410161513775)">
<polygon id="-3_1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-3_1_clip">
<use href="#-3_1_inner_hex" />
</clipPath>
</g>
<g class="" id="-3_3_tile" transform="translate(0, 519.615242270663)">
<polygon id="-3_3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-3_3_clip">
<use href="#-3_3_inner_hex" />
</clipPath>
</g>
<g class="" id="-3_-1_tile" transform="translate(600, 173.205080756888)">
<polygon id="-3_-1_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-3_-1_clip">
<use href="#-3_-1_inner_hex" />
</clipPath>
</g>
<g class="" id="-3_-2_tile" transform="translate(750, 86.6025403784439)">
<polygon id="-3_-2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-3_-2_clip">
<use href="#-3_-2_inner_hex" />
</clipPath>
</g>
<g class="" id="-3_-3_tile" transform="translate(900, 0)">
<polygon id="-3_-3_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-3_-3_clip">
<use href="#-3_-3_inner_hex" />
</clipPath>
</g>
<g class="" id="-3_2_tile" transform="translate(150, 433.012701892219)">
<polygon id="-3_2_inner_hex" points="0,86.6025403784439 50,0 150,0 200,86.6025403784439 150,173.205080756888 50,173.205080756888" style="stroke: white; stroke-width: 1" />
<clipPath id="-3_2_clip">
<use href="#-3_2_inner_hex" />
</clipPath>
</g>
</g>
<g class="path" id="test-id">
<line class="path" stroke="lime" style="stroke-width: 5" x1="100" x2="25" y1="86.6025403784439" y2="43.3012701892219" />
<path class="path" d="M 25,43.3012701892219 Q -50,0 -125,43.3012701892219" stroke="lime" style="stroke-width: 5" />
<path class="path" d="M -125,43.3012701892219 Q -200,86.6025403784439 -200,0" stroke="lime" style="stroke-width: 5" />
<path class="path" d="M -200,0 Q -200,-86.6025403784439 -125,-129.903810567666" stroke="lime" style="stroke-width: 5" />
<path class="path" d="M -125,-129.903810567666 Q -50,-173.205080756888 25,-216.50635094611" stroke="lime" style="stroke-width: 5" />
<path class="path" d="M 25,-216.50635094611 Q 100,-259.807621135332 175,-216.50635094611" stroke="lime" style="stroke-width: 5" />
<path class="path" d="M 175,-216.50635094611 Q 250,-173.205080756888 175,-129.903810567666" stroke="lime" style="stroke-width: 5" />
<path class="path" d="M 175,-129.903810567666 Q 100,-86.6025403784439 25,-129.903810567666" stroke="lime" style="stroke-width: 5" />
<path class="path" d="M 25,-129.903810567666 Q -50,-173.205080756888 -125,-216.50635094611" stroke="lime" style="stroke-width: 5" />
<line class="path" stroke="lime" style="stroke-width: 5" x1="-125" x2="-200" y1="-216.50635094611" y2="-259.807621135332" />
</g>
<g class="path" id="point-id">
<circle class="path" cx="100" cy="259.807621135332" fill="cyan" r="5" style="stroke-width: 5" />
</g>
<g class="path" id="loop-id">
<line class="path" stroke="red" style="stroke-width: 5" x1="400" x2="325" y1="259.807621135332" y2="216.50635094611" />
<path class="path" d="M 325,216.50635094611 Q 250,173.205080756888 325,129.903810567666" stroke="red" style="stroke-width: 5" />
<path class="path" d="M 325,129.903810567666 Q 400,86.6025403784439 475,129.903810567666" stroke="red" style="stroke-width: 5" />
<path class="path" d="M 475,129.903810567666 Q 550,173.205080756888 475,216.50635094611" stroke="red" style="stroke-width: 5" />
<line class="path" stroke="red" style="stroke-width: 5" x1="475" x2="400" y1="216.50635094611" y2="259.807621135332" />
</g>
<!--
Generated using the Perl SVG Module V2.87
by Ronan Oger
-->
</svg>

Before

Width:  |  Height:  |  Size: 18 KiB

@ -1,5 +1,4 @@
use v5.36; use v5.36;
use rlib '.';
use HexGrid; use HexGrid;
use HexGrid::Pin; use HexGrid::Pin;
@ -16,7 +15,7 @@ use feature "signatures";
no warnings "experimental::signatures"; no warnings "experimental::signatures";
# This regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair # This regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
my $coords_regex = qr/^\s*(\s*-?\d+\s*)\s*,\s*(\s*-?\d+\s*)\s*$/; my $coords_regex = qr/^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/;
my $api_url; my $api_url;
@ -58,6 +57,7 @@ my $grid = HexGrid->new(embed_images => $embed_images, defaults => {
style => { 'stroke-width' => $border_width, stroke => $border_colour }, style => { 'stroke-width' => $border_width, stroke => $border_colour },
show_coords => $show_coords}); show_coords => $show_coords});
# my %region_grids;
my %regions_by_subregion; my %regions_by_subregion;
my %images_for_region_grids; my %images_for_region_grids;
my %location_grids; my %location_grids;
@ -223,6 +223,9 @@ foreach my $page (values %{$background_query_results->{query}{pages}})
} }
} }
# say STDERR Dumper($grid->{images});
# say STDERR Dumper(\%images_for_region_grids);
say STDERR "Getting Tile pages"; say STDERR "Getting Tile pages";
@ -266,13 +269,12 @@ my $site_query_results = $mw->api
inprop => 'url', inprop => 'url',
} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; } ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details};
# say STDERR "Sites found: " . join(" ,", map { $_->{title} } @$site_pages);
foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
{ {
next if $site_page_ref->{title} =~ /^Category:/; next if $site_page_ref->{title} =~ /^Category:/;
my $site_name = $site_page_ref->{title}; my $site_name = $site_page_ref->{title};
say STDERR "Processing Site $site_name"; say STDERR "Processing Site $site_name";
my $site_url = $site_page_ref->{canonicalurl}; my $site_url = $site_page_ref->{canonicalurl};
my $site_content = $site_page_ref->{revisions}[0]{'*'}; my $site_content = $site_page_ref->{revisions}[0]{'*'};
my $parsed_template = MWTemplate::Parse($site_content, $site_template_name); my $parsed_template = MWTemplate::Parse($site_content, $site_template_name);

Loading…
Cancel
Save