# $region{NAME}{Centre}
foreach my $rr (values %region) {
next if $rr->{Special};
- my $poly = $rr->{Polygon};
my $sum = Math::GSL::Vector->new(2);
- $sum += $_->{Pos} foreach @$poly;
- $rr->{Centre} = $sum * (1.0 / @$poly);
- # xxx use mean edge location (ie weight by edge length)
+ my $wsum = 0;
+ foreach my $adj (@{ $rr->{Adj} }) {
+ my @ends = map { $_->{Pos} } @{ $adj->{Ends} };
+ my $w = ($ends[1] - $ends[0])->norm();
+ $sum += $w * $_ foreach @ends;
+ $wsum += $w;
+ }
+ $rr->{Centre} = $sum * (0.5 / $wsum);
}
}