From 7fa72aef52f87e56bac1d79d1f84d03fdc059b71 Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Thu, 10 Aug 2023 20:59:57 -0500 Subject: [PATCH] . --- HexGrid.pm | 13 +++++++++++++ HexGrid/Region.pm | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/HexGrid.pm b/HexGrid.pm index a86fff4..beda636 100644 --- a/HexGrid.pm +++ b/HexGrid.pm @@ -120,6 +120,19 @@ sub subgrid_for_tiles($this, @coords_list) return $subgrid; } +sub iter_region($this, $code) +{ + foreach my $region (values %{$this->{regions}}) + { + $code->($region); + } +} + +sub iter_tile($this, $code) +{ + $this->iter_region(sub($region) { $region->iter_tile($code) }); +} + sub render($this) { my ($min_x,$min_y,$max_x,$max_y) = qw(Inf Inf -Inf -Inf); diff --git a/HexGrid/Region.pm b/HexGrid/Region.pm index 64cce21..1ed8d3a 100644 --- a/HexGrid/Region.pm +++ b/HexGrid/Region.pm @@ -42,6 +42,17 @@ sub make_subregion($this, $name, %defaults) $this->add_subregion(HexGrid::Region->new(name => $name, defaults => $tile_defaults)); } +sub iter_tile($this, $code) +{ + foreach my $nw (keys %{$this->{tiles}}) + { + foreach my $sw (keys %{$this->{tiles}{$nw}}) + { + $code->($this->{tiles}{$nw}{$sw}); + } + } +} + sub render($this, $svg, $laters, $grid) { my ($min_x,$min_y,$max_x,$max_y) = qw(Inf Inf -Inf -Inf);