our %vxname2pos; # $vxname2pos{VXNAME} = Math::GSL::Vector
our %bb; # $r{Bounding...}[0..3] = points
our $maxpaper = 'a3';
+my $a1sfactor = 1/sqrt(8);
sub TAU { M_PI * 2.0; }
sub MM2PT { 72.0 / 25.4; }
sub prs2r ($) {
# bodgery for the sea and land
- return 'NZ' if m/ \| / && !grep { !m{^(?:NZ|L2?)$} } split / \| /, $_[0];
+ return $c{Sea} if m/ \| / && !grep { !m{^$c{OuterfaceRe}$} } split / \| /, $_[0];
$prs2region{$_[0]} // confess "@_ ?"
}
sub prs2rr ($) { $region{prs2r($_[0])} }
my @edges;
my $process_rr = sub {
my $last_ai;
- if ($rr->{Name} eq 'NZ') {
- # We combined L and NZ; now we must split them again
- # in fact, we just throw away L and L2 entirely.
- # Here, when processing NZ, we keep only vertices that
- # are part of NZ.
+ if ($rr->{Name} eq $c{Sea}) {
+ # We combined land and sea; now we must split them again
+ # in fact, we just throw away all L entirely.
+ # Here, when processing sea, we keep only vertices that
+ # are part of the sea.
@edges = grep {
my $evxname = $_->{VxName};
my @eregions = split / \| ?/, $evxname;
- grep { $_ eq 'NZ' } @eregions
+ grep { $_ eq $c{Sea} } @eregions
} @edges;
}
$rr->{Polygon} = [ @edges ];
- if ($rr->{Name} ne 'NZ') {
+ if ($rr->{Name} ne $c{Sea}) {
for my $ei (0..$#edges) {
if (!defined $last_ai) {
my $ai;
}
$process_rr->();
- $region{$_}{Special} = 1 foreach qw(NZ L L2);
+ $region{$_}{Special} = 1 foreach @{ $c{SpecialRegions} };
}
#----- geometry mangling -----
$mid = ($lims[1] - $lims[0]) * 0.5;
}
-sub adjust_nz() {
- my $poly = $region{NZ}{Polygon};
+sub adjust_sea() {
+ # Adjusts the top and bottom edges of the sea
+ my $poly = $region{$c{Sea}}{Polygon};
my %occurs;
foreach my $v (@$poly) {
$occurs{$v->{VxName}}++
}
foreach my $v (@$poly) {
- $v->{NZ_Occurs} = $occurs{$v->{VxName}};
+ $v->{SeaOccurs} = $occurs{$v->{VxName}};
}
- #print STDERR " nz ".(scalar @$poly)."\n";
+ #print STDERR " sea ".(scalar @$poly)."\n";
my $occurs_m = sub {
my ($ei) = @_;
- $poly->[($ei+@$poly) % @$poly]{NZ_Occurs} > 1
+ $poly->[($ei+@$poly) % @$poly]{SeaOccurs} > 1
};
for my $ei (0..$#$poly) {
next if $occurs_m->($ei);
next unless $occurs_m->($ei-1);
next unless $occurs_m->($ei+1);
- #print STDERR " nz would adjust $poly->[$ei]{VxName}\n";
+ #print STDERR " sea would adjust $poly->[$ei]{VxName}\n";
# adjust coord outwards
}
for my $ei (0..$#$poly) {
next unless $occurs_m->($ei);
- #print STDERR " nz occurs_m $ei $poly->[$ei]{VxName}\n";
+ #print STDERR " sea occurs_m $ei $poly->[$ei]{VxName}\n";
next unless $occurs_m->($ei-1);
- my $dleft = mkvec(-1000,0);
+ my $dleft = &mkvec(@{ $c{PA}{OuterCoastDelta} });
foreach my $which (0,-1) {
my $ej = ($ei + $which + @$poly) % @$poly;
my $ek = ($ei + +1 + 3*$which + @$poly) % @$poly;
my $posj = \ $poly->[$ej]{Pos};
my $posk = \ $poly->[$ek]{Pos};
my $dout = $$posk - $$posj;
- #print STDERR " nz adj j=$ej ",prvec($$posj)," $poly->[$ej]{VxName}\n";
- #print STDERR " nz adj k=$ek ",prvec($$posk)," $poly->[$ek]{VxName}\n";
- if ($poly->[$ej]{VxName} =~ /Noorderzijlvest/) {
- #print STDERR " nz adj extra\n";
- $$posk = $$posj + 10 * mkvec(100,-50);
+ #print STDERR " sea adj j=$ej ",prvec($$posj)," $poly->[$ej]{VxName}\n";
+ #print STDERR " sea adj k=$ek ",prvec($$posk)," $poly->[$ek]{VxName}\n";
+ foreach my $paocv (@{ $c{PA_Outercoast_Vertices} }) {
+ if ($poly->[$ej]{VxName} =~ m{$paocv->{Re}}) {
+ #print STDERR " sea adj extra\n";
+ $$posk = $$posj + 10 * &mkvec(@{ $paocv->{PA} });
+ }
}
$$posj = $$posj + $dleft + $dout*10;
$$posk = $$posk + $dout*10;
@{ $bb{PrintableT} }[2..3],
];
} elsif ($maxpaper =~ m/^a1/) {
+ my $offx = ($a1_w - $bb{Entire}[2] * (1 + $a1sfactor)) / 3;
+ my $offy = 0.5*($a1_h - $bb{Entire}[3]);
+ $somepage->('P', -$offx,-$offy, $a1_w-$offx, $a1_h-$offy);
my $hairs = 30 * MM2PT;
my $hairsw = $bb{Entire}[2];
my $hairsh = $bb{Entire}[3];
my $surround = 5 * MM2PT;
my $surroundw = $bb{Entire}[2] + $surround*2;
my $surroundh = $bb{Entire}[3] + $surround*2;
- $somepage->('P', 0,0, $a1_w, $a1_h);
- my $offx = 0.5*($bb{PageP}[2] - $bb{Entire}[2]);
- my $offy = 0.5*($bb{PageP}[3] - $bb{Entire}[3]);
my @hrect = @{ $bb{Entire} };
- $bb{Entire}[0] += $offx; $bb{Entire}[1] += $offy;
- $bb{Entire}[2] += $offx; $bb{Entire}[3] += $offy;
if ($maxpaper eq 'a1m') {
@hrect = @{ $submargins->($a1m_pasteedge, \@hrect) };
- $bb{Cutout} = $submargins->($a1m_pasteedge, $bb{Entire});
+ $bb{Cutout} = \@hrect;
}
my $w_stroke = $xopts =~ m/W/ ?
' gsave 3 setlinewidth stroke grestore '
: '';
$preamble_from_boundings = <<END;
- $offx $offy translate
1 setlinewidth
0 setgray
/a1hairs {
$hrect[0] $hrect[3] a1hairs
$hrect[2] $hrect[3] a1hairs
$hrect[2] $hrect[1] a1hairs
+ newpath
-$surround -$surround moveto
$surroundw 0 rlineto
0 $surroundh rlineto
sub showboundings () {
return unless $xopts =~ m/B/;
- o(" grestore gsave\n");
+ o(" gsave\n");
+ my $bb = $bb{$bounding};
+ o(" $bb->[0] neg $bb->[1] neg translate\n");
my $i = 0;
my $on = 2;
my $off = 9;
o(" closepath stroke\n");
$i++;
}
+ o(" grestore");
}
sub o_amble (@) {
$t =~ s/^\&+/ '%' x length $& /mge;
o($t);
}
-
+
sub preamble() {
my $bb = $bb{$bounding}; confess $bounding unless $bb;
my $sz = [ $bb->[2] - $bb->[0], $bb->[3] - $bb->[1] ];
o_amble(<<END);
&!PS-Adobe-3.0
-&&BoundingBox @$bb
+&&BoundingBox 0 0 @$sz
&&Pages: 1
&&EndComments
&&BeginProlog
&&EndProlog
&&BeginSetup
<< /PageSize [ @$sz ] >> setpagedevice
+/all {
+ gsave
+ $bb->[0] neg $bb->[1] neg translate
+ $preamble_from_boundings
+ board
+ grestore
+ showboundings
+} def
+/showboundings {
+END
+ showboundings();
+ o_amble(<<END);
+} def
/board {
gsave
-$preamble_from_boundings
+ % adjustment to actual image placement within prinable areas etc.:
34 -15 translate
END
if ($maxpaper eq 'a4') {
o("0 -17 translate\n");
}
- # xxx split into pages
}
sub postamble () {
o_amble(<<END);
grestore
-} bind def
+} def % board
&&EndSetup
&&Page: 1
&&BeginPageSetup
/pgsave save def
&&EndPageSetup
-board
+all
+END
+ if ($maxpaper =~ m/^a1/) {
+ o(<<END);
+ $a1_w 0 translate
+ $a1sfactor dup scale
+ $a1_w neg 0 translate
+ 1 1 3 { pop all 0 $a1_h 0.8 mul translate } for
+END
+ }
+ o_amble(<<END);
pgsave restore
showpage
&&EOF
sub facepscolour ($) {
my ($colourname) = @_;
- $xopts =~ m/W/ ? '1 setgray' : lighterpscolour($colourname, 0.75);
+ $xopts =~ m/W/ ? '1 setgray' :
+ $colourname =~ m/land/ ? miscpscolour($colourname)
+ : lighterpscolour($colourname, 0.75);
}
sub miscpscolour ($) {
}
}
-sub afsluitdijk() {
- my ($adj) = grep { $_->{Name} eq 'NZ' } @{ $region{'ZZ'}{Adj} };
+sub dashedwithhs ($$$) {
+ my ($inner, $comment, $colour) = @_;
+ my ($adj) = grep { $_->{Name} eq $c{Sea} } @{ $region{$inner}{Adj} };
my $dash = 20;
my (@pos) = adj_ends($adj);
my $mid = 0.5 * ($pos[0] + $pos[1]);
my $r = 0.5 * ($pos[1] - $pos[0])->norm();
- o(sprintf <<'END', facepscolour('sea'), psvec($mid), $r);
- %% Afsluitdijk
+ o(sprintf <<'END', $comment, facepscolour('sea'), psvec($mid), $r);
+ %% %s
%s %s %s 0 360 arc closepath fill
END
some_edge_faces(()); # just sets the colour
stroke
[] 0 setdash
END
- one_hs('purple', $mid);
+ one_hs($colour, $mid);
+}
+
+sub dashedwithhses() {
+ dashedwithhs(
+ $_->{Inner},
+ $_->{Comment},
+ $_->{Colour}
+ ) foreach @{ $c{DashedHs} };
}
sub edge_faces() {
- some_edge_faces($region{'NZ'});
- afsluitdijk();
+ some_edge_faces($region{$c{Sea}});
+ dashedwithhses();
some_edge_faces(grep {
- $_->{Name} !~ m{^(?:L2?|NZ|ZZ)$}
+ my $n = $_->{Name};
+ $n !~ m{^$c{OuterfaceRe}$} &&
+ !grep { $n eq $_->{Inner} } @{ $c{DashedHs} }
} values %region);
}
next if $rr->{Name} =~ m/^L\d?$/;
my $words = $rr->{DisplayName};
my $pos;
- if ($rr->{Name} eq 'NZ') {
+ if ($rr->{Name} eq $c{Sea}) {
$pos = mkvec(90, 1280);
} else {
$pos = $rr->{Centre} + mkvec( 0, 0.5 * $sz * @$words );
$pos += $sz * &mkvec(@$adjust);
}
my $w = $rr->{Water};
- $w = 2 if $rr->{Special} || $rr->{Name} eq 'ZZ';
+ $w = 2 if $rr->{Name} eq $c{Sea};
if ($w) {
#print STDERR " water $w in $rr->{Name}\n";
my $down = water_cubes_sz(2) - water_cubes_sz(1) + $cube_gap;
$pos -= mkvec(0, -0.5 * $down);
my $cube_y = -($sz * @$words);
- if ($rr->{Name} eq 'Wieringermeer') {
+ if (grep { $_ eq $rr->{Name} } @{ $c{CubeAbove} }) {
$pos -= mkvec(0,+$sz);
$cube_y = 0;
$down = 0;
o(" } bind def\n");
foreach my $rr (values %region) {
next if $rr->{Special};
- next if $rr->{Name} eq 'ZZ';
+ next if grep { $_->{Inner} eq $rr->{Name} } @{ $c{DashedHs} };
next if $rr->{Colour} eq 'high';
foreach my $adj (@{ $rr->{Adj} }) {
my $neigh = $adj->{Name};
read_faces();
calculate_centres();
transform_coordinates();
-adjust_nz();
+adjust_sea();
computeboundings();
preamble();
sea_track();
hs_initial();
play_hint();
-showboundings();
postamble();
print STDERR Dumper(\%region) if $ENV{'GENERATE_BOARD_DUP'};